Skip to content

Commit

Permalink
Inline comments seem to sort of work?
Browse files Browse the repository at this point in the history
  • Loading branch information
notjosh authored and bigkraig committed Apr 9, 2019
1 parent abecf38 commit 8ceb1ec
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
11 changes: 11 additions & 0 deletions source/dsl/GitLabDSL.ts
Expand Up @@ -179,6 +179,17 @@ export interface GitLabNote {
noteable_iid: number
}

export interface GitLabDiscussionTextPosition {
position_type: "text"
base_sha: string
start_sha: string
head_sha: string
new_path: string
new_line: string
old_path: string
old_line: string | null
}

export interface GitLabInlineNote extends GitLabNote {
position: {
base_sha: string
Expand Down
22 changes: 12 additions & 10 deletions source/platforms/GitLab.ts
Expand Up @@ -95,8 +95,6 @@ class GitLab implements Platform {
}
})

// console.log({ comments })

return comments
}

Expand All @@ -122,28 +120,21 @@ class GitLab implements Platform {

if (dangered.length) {
// update the first
console.log(`[+] update ${dangered[0].id}`)
console.log(dangered)
note = await this.api.updateMergeRequestNote(dangered[0].id, newComment)

// delete the rest
for (let deleteme of dangered) {
if (deleteme === dangered[0]) {
console.log(`[-] skip ${deleteme.id}`)
continue
}

console.log(`[+] delete ${deleteme.id}`)
await this.api.deleteMergeRequestNote(deleteme.id)
}
} else {
// create a new note
console.log("[+] create")
note = await this.api.createMergeRequestNote(newComment)
}

console.log("[+] note -> " + note.id)

// create URL from note
// "https://gitlab.com/group/project/merge_requests/154#note_132143425"
return `${this.api.mergeRequestURL}#note_${note.id}`
Expand All @@ -157,7 +148,18 @@ class GitLab implements Platform {
createInlineComment = async (git: GitDSL, comment: string, path: string, line: number): Promise<string> => {
d("createInlineComment", { git, comment, path, line })

return this.api.createMergeRequestDiscussion(comment)
const mr = await this.api.getMergeRequestInfo()

return this.api.createMergeRequestDiscussion(comment, {
position_type: "text",
base_sha: mr.diff_refs.base_sha,
start_sha: mr.diff_refs.start_sha,
head_sha: mr.diff_refs.head_sha,
old_path: path,
old_line: null,
new_path: path,
new_line: `${line}`,
})
}

updateInlineComment = async (comment: string, id: string): Promise<GitLabNote> => {
Expand Down

0 comments on commit 8ceb1ec

Please sign in to comment.