-
-
Notifications
You must be signed in to change notification settings - Fork 368
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
[BUG] Inline comments often don't show up, or show incorrectly with GitLab self-hosted #1351
Comments
Looking into this further, I think I understand what is happening. I can see the note originally getting created:
Then later on, this same note is updated with the global warnings, which replaces the body:
Looking at the API code for GitLab, it seems like when deciding whether to create or update a discussion, we just pick the first discussion available: updateOrCreateComment = async (dangerID: string, newComment: string): Promise<string> => {
d("updateOrCreateComment", { dangerID, newComment })
//Even when we don't set danger to create threads, we still need to delete them if someone answered to a single
// comment created by danger, resulting in a discussion/thread. Otherwise we are left with dangling comments
// that will most likely have no meaning out of context.
const discussions = await this.getDangerDiscussions(dangerID)
const firstDiscussion = discussions.shift()
const existingNote = firstDiscussion?.notes[0]
// Delete all notes from all other danger discussions (discussions cannot be deleted as a whole):
await this.deleteNotes(this.reduceNotesFromDiscussions(discussions)) //delete the rest
...
} Is it possible that this is a naive approach? I'm afraid I know very little about typescript or javascript, so I'm not sure how I'd go about investigating this further to create a PR. |
Interestingly, if I create a new MR, with only the inline warning, I see it briefly in GitLab before it disappears completely. Looking at the pipeline log it seems like it's created successfully, then gets deleted at the end of the pipeline. Full Log
|
OK after significant investigation, I've found the issue. In GitLab.ts, we have the following: updateOrCreateComment = async (dangerID: string, newComment: string): Promise<string> => {
d("updateOrCreateComment", { dangerID, newComment })
//Even when we don't set danger to create threads, we still need to delete them if someone answered to a single
// comment created by danger, resulting in a discussion/thread. Otherwise we are left with dangling comments
// that will most likely have no meaning out of context.
const discussions = await this.getDangerDiscussions(dangerID)
const firstDiscussion = discussions.shift()
const existingNote = firstDiscussion?.notes[0]
// Delete all notes from all other danger discussions (discussions cannot be deleted as a whole):
await this.deleteNotes(this.reduceNotesFromDiscussions(discussions)) //delete the rest
let newOrUpdatedNote: GitLabNote
if (existingNote) {
// update the existing comment
newOrUpdatedNote = await this.api.updateMergeRequestNote(existingNote.id, newComment)
} else {
// create a new comment
newOrUpdatedNote = await this.createComment(newComment)
}
// create URL from note
// "https://gitlab.com/group/project/merge_requests/154#note_132143425"
return `${this.api.mergeRequestURL}#note_${newOrUpdatedNote.id}`
} The problem here is we update the existing inline note, with the global warnings. If I comment out the existing note check: // if (existingNote) {
// update the existing comment
// newOrUpdatedNote = await this.api.updateMergeRequestNote(existingNote.id, newComment)
// } else {
// create a new comment
newOrUpdatedNote = await this.createComment(newComment)
// } then run from my test repo:
I can now see both the inline and global warnings However, I'm unsure what side effects this has, as I'm unfamiliar with the code base and flow. Does anyone have any advice? Reverting to danger js 11.1.4 fixes this issue for us. |
I just came across this same bug today. I'll see if I can implement the fix you mention. |
Another quick fix is to downgrade to 11.1.4 which is the last release before this bug was introduced. |
Describe the bug
I'm unable to get inline comments to show up correctly, and consistently, with danger-js and GitLab. While danger correctly adds a comment at the line I'd expect, the comment text is incorrect.
To Reproduce
.gitlab-ci.yml
file listed belowLinterTest.swift
listed belowLinterTest.swift
, removing the comments in lines 22-26.gitlab-ci.yml
LinterTest.swift
dangerfile.ts
Expected behavior
There should be one inline comment, underneath line 22 of
LinterTest.swift
, with the textinline warning, line 22
. There should be 3 warnings on the main page of the merge request:inline warning, line 16
- as this line isn't part of the changed file, it may not show up at allglobal warning
global warning 2, electric boogaloo
Screenshots
Overview
Changes tab
Your Environment
The text was updated successfully, but these errors were encountered: