Skip to content

Commit 0c8804f

Browse files
authoredNov 1, 2022
Merge pull request #1332 from ivankatliarchuk/issue_1330
Gitlab: added environment variable DANGER_SKIP_WHEN_EMPTY
2 parents 2bcccbd + 886616b commit 0c8804f

File tree

5 files changed

+44
-16
lines changed

5 files changed

+44
-16
lines changed
 

‎CHANGELOG.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
<!-- Your comment below this -->
1818
- Append random string to danger-results.json and danger-dsl.json files to better support concurrent processes #1311
19-
20-
- Gitlab package moved to a new home "@gitbreaker/*" [#1301](https://github.com/danger/danger-js/issues/1301) [@ivankatliarchuk]
19+
- Gitlab: add support for skipping remove of messages when empty [#1330](https://github.com/danger/danger-js/issues/1330) [@ivankatliarchuk]
20+
- Gitlab: package moved to a new home "@gitbreaker/*" [#1301](https://github.com/danger/danger-js/issues/1301) [@ivankatliarchuk]
2121
- GitLab: Improve support for MRs from forks [#1319](https://github.com/danger/danger-js/pull/1319) [@ivankatliarchuk]
2222
- GitLab: Added provider tests [#1319](https://github.com/danger/danger-js/pull/1319) [@ivankatliarchuk]
2323

‎source/commands/danger-process.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ program.action(process_name => (subprocessName = process_name)).parse(process.ar
4949

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

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

‎source/platforms/gitlab/_tests/_gitlab_api.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,9 @@ describe("GitLab API", () => {
181181
expected: "",
182182
},
183183
]
184-
for (let el in parameters) {
185-
let result = await api.getFileContents(parameters[el].filePath, api.repoMetadata.repoSlug, parameters[el].ref)
186-
expect(result).toContain(parameters[el].expected)
184+
for (let el of parameters) {
185+
let result = await api.getFileContents(el.filePath, api.repoMetadata.repoSlug, el.ref)
186+
expect(result).toContain(el.expected)
187187
}
188188
nockDone()
189189
})

‎source/runner/Executor.ts

+15-9
Original file line numberDiff line numberDiff line change
@@ -262,16 +262,22 @@ export class Executor {
262262
let issueURL = undefined
263263

264264
if (!hasMessages || this.options.removePreviousComments) {
265-
if (!hasMessages) {
266-
this.log(`Found no issues or messages from Danger. Removing any existing messages on ${this.platform.name}.`)
265+
if (process.env["DANGER_SKIP_WHEN_EMPTY"] === "true") {
266+
this.log(`Skip posting to platform ${this.platform.name}.`)
267267
} else {
268-
this.log(`'removePreviousComments' option specified. Removing any existing messages on ${this.platform.name}.`)
269-
}
270-
await this.platform.deleteMainComment(dangerID)
271-
const previousComments = await this.platform.getInlineComments(dangerID)
272-
for (const comment of previousComments) {
273-
if (comment && comment.ownedByDanger) {
274-
await this.deleteInlineComment(comment)
268+
if (!hasMessages) {
269+
this.log(`Found no issues or messages from Danger. Removing any existing messages on ${this.platform.name}.`)
270+
} else {
271+
this.log(
272+
`'removePreviousComments' option specified. Removing any existing messages on ${this.platform.name}.`
273+
)
274+
}
275+
await this.platform.deleteMainComment(dangerID)
276+
const previousComments = await this.platform.getInlineComments(dangerID)
277+
for (const comment of previousComments) {
278+
if (comment && comment.ownedByDanger) {
279+
await this.deleteInlineComment(comment)
280+
}
275281
}
276282
}
277283
}

‎source/runner/_tests/_executor.test.ts

+22
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,28 @@ describe("setup", () => {
112112
expect(platform.deleteMainComment).toBeCalled()
113113
})
114114

115+
it("Configure to Skip a post deletion when there are no messages", async () => {
116+
const platform = new FakePlatform()
117+
const exec = new Executor(new FakeCI({}), platform, inlineRunner, defaultConfig, new FakeProcces())
118+
let parameters: { skip: boolean; times: number }[] = [
119+
{ skip: true, times: 0 },
120+
{ skip: false, times: 1 },
121+
]
122+
for (let el of parameters) {
123+
if (el.skip) {
124+
process.env.DANGER_SKIP_WHEN_EMPTY = "true"
125+
} else {
126+
process.env.DANGER_SKIP_WHEN_EMPTY = "false"
127+
}
128+
const dsl = await defaultDsl(platform)
129+
platform.deleteMainComment = jest.fn()
130+
await exec.handleResults(emptyResults, dsl.git)
131+
132+
expect(process.env.DANGER_SKIP_WHEN_EMPTY).toBeDefined()
133+
expect(platform.deleteMainComment).toBeCalledTimes(el.times)
134+
}
135+
})
136+
115137
it("Deletes a post when 'removePreviousComments' option has been specified", async () => {
116138
const platform = new FakePlatform()
117139
const exec = new Executor(

0 commit comments

Comments
 (0)
Please sign in to comment.