Skip to content

Commit

Permalink
delete main comment when all issues are resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie Thompson committed May 21, 2019
1 parent e3a78d7 commit ab83665
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions source/platforms/GitLab.ts
Expand Up @@ -6,6 +6,7 @@ import { GitCommit } from "../dsl/Commit"
import { GitLabDSL, GitLabNote } from "../dsl/GitLabDSL"

import { debug } from "../debug"
import { dangerIDToString } from "../runner/templates/githubIssueTemplate"
const d = debug("GitLab")

class GitLab implements Platform {
Expand Down Expand Up @@ -174,9 +175,27 @@ class GitLab implements Platform {
return await this.api.deleteMergeRequestNote(nid)
}

deleteMainComment = async (): Promise<boolean> => {
d("deleteMainComment", {})
return true
deleteMainComment = async (dangerID: string): Promise<boolean> => {
const notes = await this.getDangerNotes(dangerID)
for (let note of notes) {
d("deleteMainComment", { id: note.id })
await this.api.deleteMergeRequestNote(note.id)
}

return notes.length > 0
}

getDangerNotes = async (dangerID: string): Promise<GitLabNote[]> => {
const { id: dangerUserId } = await this.api.getUser()
const notes: GitLabNote[] = await this.api.getMergeRequestNotes()

return (
notes
.filter(({ author: { id } }) => id === dangerUserId)
// danger-id-(dangerID) is included in a hidden comment in the githubIssueTemplate
// this allows users to run Danger as their user without risking deleting their comments
.filter(({ body }) => body!.includes(dangerIDToString(dangerID)))
)
}

updateStatus = async (): Promise<boolean> => {
Expand Down

0 comments on commit ab83665

Please sign in to comment.