From aab92edc32cad748e290bb09699e13acdb581b14 Mon Sep 17 00:00:00 2001 From: David Brunow <> Date: Fri, 22 Jul 2022 11:25:45 -0500 Subject: [PATCH] Make BitBucket Server username matching case insensitive --- .../bitbucket_server/BitBucketServerAPI.ts | 4 +- .../_tests/_bitbucket_server_api.test.ts | 72 +++++++++++++++++++ 2 files changed, 74 insertions(+), 2 deletions(-) diff --git a/source/platforms/bitbucket_server/BitBucketServerAPI.ts b/source/platforms/bitbucket_server/BitBucketServerAPI.ts index 6ae1e07e1..074bd732d 100644 --- a/source/platforms/bitbucket_server/BitBucketServerAPI.ts +++ b/source/platforms/bitbucket_server/BitBucketServerAPI.ts @@ -213,7 +213,7 @@ export class BitBucketServerAPI implements BitBucketServerAPIDSL { return comments .filter(comment => comment!.text.includes(dangerIDMessage)) - .filter(comment => username || comment!.author.name === username) + .filter(comment => comment!.author.name.toLowerCase() === username!.toLowerCase()) .filter(comment => comment!.text.includes("Generated by")) } @@ -232,7 +232,7 @@ export class BitBucketServerAPI implements BitBucketServerAPIDSL { .map((i: any) => { return { id: i.id, - ownedByDanger: i.author.name === username && i.text.includes(dangerIDMessage), + ownedByDanger: i.author.name.toLowerCase() === username!.toLowerCase() && i.text.includes(dangerIDMessage), body: i.text, } }) diff --git a/source/platforms/bitbucket_server/_tests/_bitbucket_server_api.test.ts b/source/platforms/bitbucket_server/_tests/_bitbucket_server_api.test.ts index a6d9f37b7..cf339c293 100644 --- a/source/platforms/bitbucket_server/_tests/_bitbucket_server_api.test.ts +++ b/source/platforms/bitbucket_server/_tests/_bitbucket_server_api.test.ts @@ -241,6 +241,49 @@ describe("API testing - BitBucket Server", () => { ]) }) + it("getDangerCommentsCaseInsensitive", async () => { + const commitID = "e70f3d6468f61a4bef68c9e6eaba9166b096e23c" + jsonResult = () => ({ + isLastPage: true, + values: [ + { + comment: { + text: `FAIL! danger-id-1; ${dangerSignaturePostfix({} as DangerResults, commitID)}`, + author: { + name: "userNAME", + }, + }, + }, + { + comment: null, + }, + { + comment: { + text: "not a danger comment", + author: { + name: "azz", + }, + }, + }, + ], + }) + const result = await api.getDangerComments("1") + + expect(api.fetch).toHaveBeenCalledWith( + `${host}/rest/api/1.0/projects/FOO/repos/BAR/pull-requests/1/activities?fromType=COMMENT&start=0`, + { method: "GET", body: null, headers: expectedJSONHeaders }, + undefined + ) + expect(result).toEqual([ + { + text: `FAIL! danger-id-1; ${dangerSignaturePostfix({} as DangerResults, commitID)}`, + author: { + name: "userNAME", + }, + }, + ]) + }) + it("getDangerInlineComments", async () => { jsonResult = () => ({ isLastPage: true, @@ -270,6 +313,35 @@ describe("API testing - BitBucket Server", () => { expect(comments[0].ownedByDanger).toBeTruthy() }) + it("getDangerInlineCommentsCaseInsensitive", async () => { + jsonResult = () => ({ + isLastPage: true, + values: [ + { + comment: { + text: + "\n[//]: # (danger-id-default;)\n[//]: # ( File: README.md;\n Line: 5;)\n\n- :warning: Hello updates\n\n\n ", + author: { + name: "userNAME", + }, + }, + commentAnchor: { + line: 5, + lineType: "ADDED", + }, + }, + ], + }) + const comments = await api.getDangerInlineComments("default") + expect(api.fetch).toHaveBeenCalledWith( + `${host}/rest/api/1.0/projects/FOO/repos/BAR/pull-requests/1/activities?fromType=COMMENT&start=0`, + { method: "GET", body: null, headers: expectedJSONHeaders }, + undefined + ) + expect(comments.length).toEqual(1) + expect(comments[0].ownedByDanger).toBeTruthy() + }) + it("getFileContents", async () => { textResult = "contents..." const result = await api.getFileContents("path/folder with space/foo.txt", "projects/FOO/repos/BAR", "master")