diff --git a/CHANGELOG.md b/CHANGELOG.md index 98ae97f01..a4aad67eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,8 +16,8 @@ - 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://github.com/danger/danger-js/issues/1301) [@ivankatliarchuk] +- Gitlab: add support for skipping remove of messages when empty [#1330](https://github.com/danger/danger-js/issues/1330) [@ivankatliarchuk] +- Gitlab: package moved to a new home "@gitbreaker/*" [#1301](https://github.com/danger/danger-js/issues/1301) [@ivankatliarchuk] - GitLab: Improve support for MRs from forks [#1319](https://github.com/danger/danger-js/pull/1319) [@ivankatliarchuk] - GitLab: Added provider tests [#1319](https://github.com/danger/danger-js/pull/1319) [@ivankatliarchuk] diff --git a/source/commands/danger-process.ts b/source/commands/danger-process.ts index c9e00a041..433e9b1c9 100644 --- a/source/commands/danger-process.ts +++ b/source/commands/danger-process.ts @@ -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 @@ -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.` ) process.exitCode = 1 } diff --git a/source/platforms/gitlab/_tests/_gitlab_api.test.ts b/source/platforms/gitlab/_tests/_gitlab_api.test.ts index 467b8415a..b203e2064 100644 --- a/source/platforms/gitlab/_tests/_gitlab_api.test.ts +++ b/source/platforms/gitlab/_tests/_gitlab_api.test.ts @@ -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() }) diff --git a/source/runner/Executor.ts b/source/runner/Executor.ts index 9c8f81938..bcb922f6c 100644 --- a/source/runner/Executor.ts +++ b/source/runner/Executor.ts @@ -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) + } } } } diff --git a/source/runner/_tests/_executor.test.ts b/source/runner/_tests/_executor.test.ts index d765de6b7..af031bf6d 100644 --- a/source/runner/_tests/_executor.test.ts +++ b/source/runner/_tests/_executor.test.ts @@ -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(