Comparing version 11.2.6 to 11.2.7
@@ -20,2 +20,6 @@ import GitLabAPI from "./gitlab/GitLabAPI"; | ||
deleteInlineComment: (id: string) => Promise<boolean>; | ||
/** | ||
* Attempts to delete the "main" Danger comment. If the "main" Danger | ||
* comment has any comments on it then that comment will not be deleted. | ||
*/ | ||
deleteMainComment: (dangerID: string) => Promise<boolean>; | ||
@@ -28,4 +32,17 @@ deleteNotes: (notes: GitLabNote[]) => Promise<boolean>; | ||
reduceNotesFromDiscussions: (discussions: GitLabDiscussion[]) => GitLabNote[]; | ||
getDangerNotes: (dangerID: string) => Promise<GitLabNote[]>; | ||
getDangerNoteFilter: (dangerID: string) => Promise<(note: GitLabNote) => boolean>; | ||
/** | ||
* Attempts to find the "main" Danger note and should return at most | ||
* one item. If the "main" Danger note has any comments on it then that | ||
* note will not be returned. | ||
*/ | ||
getMainDangerNotes: (dangerID: string) => Promise<GitLabNote[]>; | ||
/** | ||
* Filters a note to determine if it was created by Danger. | ||
*/ | ||
getDangerDiscussionNoteFilter: (dangerID: string) => Promise<(note: GitLabNote) => boolean>; | ||
/** | ||
* Filters a note to the "main" Danger note. If that note has any | ||
* comments on it then it will not be found. | ||
*/ | ||
getDangerMainNoteFilter: (dangerID: string) => Promise<(note: GitLabNote) => boolean>; | ||
updateStatus: () => Promise<boolean>; | ||
@@ -32,0 +49,0 @@ getFileContents: (path: string, slug?: string | undefined, ref?: string | undefined) => Promise<string>; |
@@ -63,2 +63,5 @@ "use strict"; | ||
var d = (0, debug_1.debug)("GitLab"); | ||
/** | ||
* Determines whether Danger should use threads for the "main" Danger comment. | ||
*/ | ||
var useThreads = function () { | ||
@@ -155,4 +158,2 @@ return process.env.DANGER_GITLAB_USE_THREADS === "1" || process.env.DANGER_GITLAB_USE_THREADS === "true"; | ||
body: note.body, | ||
// XXX: we should re-use the logic in getDangerNotes, need to check what inline comment template we're using if | ||
// any | ||
ownedByDanger: note.author.id === dangerUserID && note.body.includes(dangerID), | ||
@@ -165,3 +166,3 @@ }; | ||
this.updateOrCreateComment = function (dangerID, newComment) { return __awaiter(_this, void 0, void 0, function () { | ||
var discussions, firstDiscussion, existingNote, newOrUpdatedNote; | ||
var discussions, firstDiscussion, existingNote, newOrUpdatedNote, notes, note, _i, notes_1, deleteme; | ||
return __generator(this, function (_a) { | ||
@@ -171,2 +172,3 @@ switch (_a.label) { | ||
d("updateOrCreateComment", { dangerID: dangerID, newComment: newComment }); | ||
if (!useThreads()) return [3 /*break*/, 7]; | ||
return [4 /*yield*/, this.getDangerDiscussions(dangerID)]; | ||
@@ -182,2 +184,3 @@ case 1: | ||
_a.sent(); //delete the rest | ||
newOrUpdatedNote = void 0; | ||
if (!existingNote) return [3 /*break*/, 4]; | ||
@@ -198,2 +201,38 @@ return [4 /*yield*/, this.api.updateMergeRequestNote(existingNote.id, newComment)]; | ||
return [2 /*return*/, "".concat(this.api.mergeRequestURL, "#note_").concat(newOrUpdatedNote.id)]; | ||
case 7: return [4 /*yield*/, this.getMainDangerNotes(dangerID)]; | ||
case 8: | ||
notes = _a.sent(); | ||
note = void 0; | ||
if (!notes.length) return [3 /*break*/, 14]; | ||
return [4 /*yield*/, this.api.updateMergeRequestNote(notes[0].id, newComment) | ||
// delete the rest | ||
]; | ||
case 9: | ||
// update the first | ||
note = _a.sent(); | ||
_i = 0, notes_1 = notes; | ||
_a.label = 10; | ||
case 10: | ||
if (!(_i < notes_1.length)) return [3 /*break*/, 13]; | ||
deleteme = notes_1[_i]; | ||
if (deleteme === notes[0]) { | ||
return [3 /*break*/, 12]; | ||
} | ||
return [4 /*yield*/, this.api.deleteMergeRequestNote(deleteme.id)]; | ||
case 11: | ||
_a.sent(); | ||
_a.label = 12; | ||
case 12: | ||
_i++; | ||
return [3 /*break*/, 10]; | ||
case 13: return [3 /*break*/, 16]; | ||
case 14: return [4 /*yield*/, this.api.createMergeRequestNote(newComment)]; | ||
case 15: | ||
// create a new note | ||
note = _a.sent(); | ||
_a.label = 16; | ||
case 16: | ||
// create URL from note | ||
// "https://gitlab.com/group/project/merge_requests/154#note_132143425" | ||
return [2 /*return*/, "".concat(this.api.mergeRequestURL, "#note_").concat(note.id)]; | ||
} | ||
@@ -266,7 +305,13 @@ }); | ||
}); }; | ||
/** | ||
* Attempts to delete the "main" Danger comment. If the "main" Danger | ||
* comment has any comments on it then that comment will not be deleted. | ||
*/ | ||
this.deleteMainComment = function (dangerID) { return __awaiter(_this, void 0, void 0, function () { | ||
var discussions; | ||
var discussions, notes, _i, notes_2, note; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.getDangerDiscussions(dangerID)]; | ||
case 0: | ||
if (!useThreads()) return [3 /*break*/, 3]; | ||
return [4 /*yield*/, this.getDangerDiscussions(dangerID)]; | ||
case 1: | ||
@@ -276,2 +321,19 @@ discussions = _a.sent(); | ||
case 2: return [2 /*return*/, _a.sent()]; | ||
case 3: return [4 /*yield*/, this.getMainDangerNotes(dangerID)]; | ||
case 4: | ||
notes = _a.sent(); | ||
_i = 0, notes_2 = notes; | ||
_a.label = 5; | ||
case 5: | ||
if (!(_i < notes_2.length)) return [3 /*break*/, 8]; | ||
note = notes_2[_i]; | ||
d("deleteMainComment", { id: note.id }); | ||
return [4 /*yield*/, this.api.deleteMergeRequestNote(note.id)]; | ||
case 6: | ||
_a.sent(); | ||
_a.label = 7; | ||
case 7: | ||
_i++; | ||
return [3 /*break*/, 5]; | ||
case 8: return [2 /*return*/, notes.length > 0]; | ||
} | ||
@@ -281,11 +343,11 @@ }); | ||
this.deleteNotes = function (notes) { return __awaiter(_this, void 0, void 0, function () { | ||
var _i, notes_1, note; | ||
var _i, notes_3, note; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_i = 0, notes_1 = notes; | ||
_i = 0, notes_3 = notes; | ||
_a.label = 1; | ||
case 1: | ||
if (!(_i < notes_1.length)) return [3 /*break*/, 4]; | ||
note = notes_1[_i]; | ||
if (!(_i < notes_3.length)) return [3 /*break*/, 4]; | ||
note = notes_3[_i]; | ||
d("deleteNotes", { id: note.id }); | ||
@@ -310,3 +372,3 @@ return [4 /*yield*/, this.api.deleteMergeRequestNote(note.id)]; | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.getDangerNoteFilter(dangerID)]; | ||
case 0: return [4 /*yield*/, this.getDangerDiscussionNoteFilter(dangerID)]; | ||
case 1: | ||
@@ -330,7 +392,12 @@ noteFilter = _a.sent(); | ||
}; | ||
this.getDangerNotes = function (dangerID) { return __awaiter(_this, void 0, void 0, function () { | ||
/** | ||
* Attempts to find the "main" Danger note and should return at most | ||
* one item. If the "main" Danger note has any comments on it then that | ||
* note will not be returned. | ||
*/ | ||
this.getMainDangerNotes = function (dangerID) { return __awaiter(_this, void 0, void 0, function () { | ||
var noteFilter, notes; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.getDangerNoteFilter(dangerID)]; | ||
case 0: return [4 /*yield*/, this.getDangerMainNoteFilter(dangerID)]; | ||
case 1: | ||
@@ -345,3 +412,6 @@ noteFilter = _a.sent(); | ||
}); }; | ||
this.getDangerNoteFilter = function (dangerID) { return __awaiter(_this, void 0, void 0, function () { | ||
/** | ||
* Filters a note to determine if it was created by Danger. | ||
*/ | ||
this.getDangerDiscussionNoteFilter = function (dangerID) { return __awaiter(_this, void 0, void 0, function () { | ||
var dangerUserId; | ||
@@ -357,6 +427,2 @@ return __generator(this, function (_a) { | ||
id === dangerUserId && | ||
//we do not check the `type` - it's `null` most of the time, | ||
// only in discussions/threads this is `DiscussionNote` for all notes. But even if danger only creates a | ||
// normal `null`-comment, any user replying to that comment will turn it into a `DiscussionNote`-typed one. | ||
// So we cannot assume anything here about danger's note type. | ||
body.includes((0, githubIssueTemplate_1.dangerIDToString)(dangerID))); | ||
@@ -367,2 +433,30 @@ }]; | ||
}); }; | ||
/** | ||
* Filters a note to the "main" Danger note. If that note has any | ||
* comments on it then it will not be found. | ||
*/ | ||
this.getDangerMainNoteFilter = function (dangerID) { return __awaiter(_this, void 0, void 0, function () { | ||
var dangerUserId; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.api.getUser()]; | ||
case 1: | ||
dangerUserId = (_a.sent()).id; | ||
return [2 /*return*/, function (_a) { | ||
var id = _a.author.id, body = _a.body, system = _a.system, type = _a.type; | ||
return (!system && // system notes are generated when the user interacts with the UI e.g. changing a PR title | ||
id === dangerUserId && | ||
// This check for the type being `null` seems to be the best option | ||
// we have to determine whether this note is the "main" Danger note. | ||
// This assumption does not hold if there are any comments on the | ||
// "main" Danger note and in that case a new "main" Danger note will | ||
// be created instead of updating the existing note. This behavior is better | ||
// than the current alternative which is the bug described here: | ||
// https://github.com/danger/danger-js/issues/1351 | ||
type == null && | ||
body.includes((0, githubIssueTemplate_1.dangerIDToString)(dangerID))); | ||
}]; | ||
} | ||
}); | ||
}); }; | ||
this.updateStatus = function () { return __awaiter(_this, void 0, void 0, function () { | ||
@@ -369,0 +463,0 @@ return __generator(this, function (_a) { |
{ | ||
"name": "danger", | ||
"version": "11.2.6", | ||
"version": "11.2.7", | ||
"description": "Unit tests for Team Culture", | ||
@@ -5,0 +5,0 @@ "main": "distribution/danger.js", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1399066
21693