Skip to content

Commit

Permalink
Merge pull request #1076 from HelloCore/fix/bitbucket-cloud-comment-c…
Browse files Browse the repository at this point in the history
…onflict

Bitbucket Cloud: Fix bug when Danger updating inline comment with summary comment
  • Loading branch information
orta committed Oct 12, 2020
2 parents 3cff430 + 16e2f8f commit 9b28d2d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -15,6 +15,8 @@

<!-- Your comment below this -->

- Bitbucket Cloud: Fix bug when Danger updating inline comment with summary comment. - [@hellocore]

<!-- Your comment above this -->

# 10.4.2
Expand Down
4 changes: 2 additions & 2 deletions source/platforms/BitBucketCloud.ts
Expand Up @@ -82,7 +82,7 @@ export class BitBucketCloud implements Platform {
* @returns {Promise<boolean>} did it work?
*/
deleteMainComment = async (dangerID: string): Promise<boolean> => {
const comments = await this.api.getDangerComments(dangerID)
const comments = await this.api.getDangerMainComments(dangerID)
for (let comment of comments) {
await this.api.deleteComment(comment.id.toString())
}
Expand All @@ -98,7 +98,7 @@ export class BitBucketCloud implements Platform {
* @returns {Promise<string>} the URL for the comment
*/
async updateOrCreateComment(dangerID: string, newComment: string): Promise<string | undefined> {
const comments = await this.api.getDangerComments(dangerID)
const comments = await this.api.getDangerMainComments(dangerID)
let issue = null

if (comments.length) {
Expand Down
3 changes: 2 additions & 1 deletion source/platforms/bitbucket_cloud/BitBucketCloudAPI.ts
Expand Up @@ -214,11 +214,12 @@ export class BitBucketCloudAPI {
return await res.text()
}

getDangerComments = async (dangerID: string): Promise<BitBucketCloudPRComment[]> => {
getDangerMainComments = async (dangerID: string): Promise<BitBucketCloudPRComment[]> => {
const comments = await this.getPullRequestComments()
const dangerIDMessage = dangerIDToString(dangerID)

return comments
.filter(comment => comment.inline == null)
.filter(comment => comment.content.raw.includes(dangerIDMessage))
.filter(comment => comment.user.uuid === this.uuid)
}
Expand Down
Expand Up @@ -149,6 +149,24 @@ describe("API testing - BitBucket Cloud", () => {
display_name: "name",
},
},
{
content: {
raw: `FAIL! danger-id-1; ${dangerSignaturePostfix({} as DangerResults, "1234")}`,
},
user: {
display_name: "name",
uuid: "{1234-1234-1234-1234}",
},
},
{
content: {
raw: "not a danger comment",
},
user: {
display_name: "someone",
uuid: "{1234-1234-1234-1235}",
},
},
],
})
const comments = await api.getDangerInlineComments("1")
Expand All @@ -173,7 +191,7 @@ describe("API testing - BitBucket Cloud", () => {
expect(result).toEqual(["activity"])
})

it("getDangerComments", async () => {
it("getDangerMainComments", async () => {
const commitID = "e70f3d6468f61a4bef68c9e6eaba9166b096e23c"
jsonResult = () => ({
isLastPage: true,
Expand All @@ -187,6 +205,21 @@ describe("API testing - BitBucket Cloud", () => {
uuid: "{1234-1234-1234-1234}",
},
},
{
content: {
raw:
"\n[//]: # (danger-id-1;)\n[//]: # ( File: dangerfile.ts;\n Line: 5;)\n\n- :warning: Hello updates\n\n\n ",
},
id: 1234,
inline: {
from: 5,
path: "dangerfile.ts",
},
user: {
uuid: "{1234-1234-1234-1234}",
display_name: "name",
},
},
{
content: {
raw: "not a danger comment",
Expand All @@ -198,7 +231,8 @@ describe("API testing - BitBucket Cloud", () => {
},
],
})
const result = await api.getDangerComments("1")

const result = await api.getDangerMainComments("1")

expect(api.fetch).toHaveBeenCalledWith(
"https://api.bitbucket.org/2.0/repositories/foo/bar/pullrequests/1/comments?q=deleted=false",
Expand Down

0 comments on commit 9b28d2d

Please sign in to comment.