Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gitlab: added environment variable DANGER_SKIP_WHEN_EMPTY #1332

Merged
merged 5 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

<!-- Your comment below this -->
- Append random string to danger-results.json and danger-dsl.json files to better support concurrent processes #1311

- Gitlab package moved to a new home "@gitbreaker/*" [#1301](https:/danger/danger-js/issues/1301) [@ivankatliarchuk]
- Gitlab: add support for skipping remove of messages when empty [#1330](https:/danger/danger-js/issues/1330) [@ivankatliarchuk]
- Gitlab: package moved to a new home "@gitbreaker/*" [#1301](https:/danger/danger-js/issues/1301) [@ivankatliarchuk]
- GitLab: Improve support for MRs from forks [#1319](https:/danger/danger-js/pull/1319) [@ivankatliarchuk]
- GitLab: Added provider tests [#1319](https:/danger/danger-js/pull/1319) [@ivankatliarchuk]

Expand Down
4 changes: 2 additions & 2 deletions source/commands/danger-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ program.action(process_name => (subprocessName = process_name)).parse(process.ar

// The dynamic nature of the program means typecasting a lot
// use this to work with dynamic properties
const app = (program as any) as SharedCLI
const app = program as any as SharedCLI

if (process.env["DANGER_VERBOSE"] || app.verbose) {
global.verbose = true
Expand All @@ -67,7 +67,7 @@ getRuntimeCISource(app).then(source => {
if (!platform) {
console.log(chalk.red(`Could not find a source code hosting platform for ${source.name}.`))
console.log(
`Currently Danger JS only supports GitHub and BitBucket Server, if you want other platforms, consider the Ruby version or help out.`
`Platform '${source.name}' is not supported with Danger JS, if you want other platforms, consider the Ruby version or help out.`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice move

)
process.exitCode = 1
}
Expand Down
6 changes: 3 additions & 3 deletions source/platforms/gitlab/_tests/_gitlab_api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ describe("GitLab API", () => {
expected: "",
},
]
for (let el in parameters) {
let result = await api.getFileContents(parameters[el].filePath, api.repoMetadata.repoSlug, parameters[el].ref)
expect(result).toContain(parameters[el].expected)
for (let el of parameters) {
let result = await api.getFileContents(el.filePath, api.repoMetadata.repoSlug, el.ref)
expect(result).toContain(el.expected)
}
nockDone()
})
Expand Down
24 changes: 15 additions & 9 deletions source/runner/Executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,16 +262,22 @@ export class Executor {
let issueURL = undefined

if (!hasMessages || this.options.removePreviousComments) {
if (!hasMessages) {
this.log(`Found no issues or messages from Danger. Removing any existing messages on ${this.platform.name}.`)
if (process.env["DANGER_SKIP_WHEN_EMPTY"] === "true") {
this.log(`Skip posting to platform ${this.platform.name}.`)
} else {
this.log(`'removePreviousComments' option specified. Removing any existing messages on ${this.platform.name}.`)
}
await this.platform.deleteMainComment(dangerID)
const previousComments = await this.platform.getInlineComments(dangerID)
for (const comment of previousComments) {
if (comment && comment.ownedByDanger) {
await this.deleteInlineComment(comment)
if (!hasMessages) {
this.log(`Found no issues or messages from Danger. Removing any existing messages on ${this.platform.name}.`)
} else {
this.log(
`'removePreviousComments' option specified. Removing any existing messages on ${this.platform.name}.`
)
}
await this.platform.deleteMainComment(dangerID)
const previousComments = await this.platform.getInlineComments(dangerID)
for (const comment of previousComments) {
if (comment && comment.ownedByDanger) {
await this.deleteInlineComment(comment)
}
}
}
}
Expand Down
22 changes: 22 additions & 0 deletions source/runner/_tests/_executor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,28 @@ describe("setup", () => {
expect(platform.deleteMainComment).toBeCalled()
})

it("Configure to Skip a post deletion when there are no messages", async () => {
const platform = new FakePlatform()
const exec = new Executor(new FakeCI({}), platform, inlineRunner, defaultConfig, new FakeProcces())
let parameters: { skip: boolean; times: number }[] = [
{ skip: true, times: 0 },
{ skip: false, times: 1 },
]
for (let el of parameters) {
if (el.skip) {
process.env.DANGER_SKIP_WHEN_EMPTY = "true"
} else {
process.env.DANGER_SKIP_WHEN_EMPTY = "false"
}
const dsl = await defaultDsl(platform)
platform.deleteMainComment = jest.fn()
await exec.handleResults(emptyResults, dsl.git)

expect(process.env.DANGER_SKIP_WHEN_EMPTY).toBeDefined()
expect(platform.deleteMainComment).toBeCalledTimes(el.times)
}
})

it("Deletes a post when 'removePreviousComments' option has been specified", async () => {
const platform = new FakePlatform()
const exec = new Executor(
Expand Down