Skip to content

Commit a5a33fe

Browse files
authored
Merge pull request #1291 from DavidBrunow/make_username_conditionals_case_insensitive
Make BitBucket Server username matching case insensitive
2 parents 52ed9c8 + aab92ed commit a5a33fe

File tree

2 files changed

+74
-2
lines changed

2 files changed

+74
-2
lines changed

source/platforms/bitbucket_server/BitBucketServerAPI.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ export class BitBucketServerAPI implements BitBucketServerAPIDSL {
213213

214214
return comments
215215
.filter(comment => comment!.text.includes(dangerIDMessage))
216-
.filter(comment => username || comment!.author.name === username)
216+
.filter(comment => comment!.author.name.toLowerCase() === username!.toLowerCase())
217217
.filter(comment => comment!.text.includes("Generated by"))
218218
}
219219

@@ -232,7 +232,7 @@ export class BitBucketServerAPI implements BitBucketServerAPIDSL {
232232
.map((i: any) => {
233233
return {
234234
id: i.id,
235-
ownedByDanger: i.author.name === username && i.text.includes(dangerIDMessage),
235+
ownedByDanger: i.author.name.toLowerCase() === username!.toLowerCase() && i.text.includes(dangerIDMessage),
236236
body: i.text,
237237
}
238238
})

source/platforms/bitbucket_server/_tests/_bitbucket_server_api.test.ts

+72
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,49 @@ describe("API testing - BitBucket Server", () => {
241241
])
242242
})
243243

244+
it("getDangerCommentsCaseInsensitive", async () => {
245+
const commitID = "e70f3d6468f61a4bef68c9e6eaba9166b096e23c"
246+
jsonResult = () => ({
247+
isLastPage: true,
248+
values: [
249+
{
250+
comment: {
251+
text: `FAIL! danger-id-1; ${dangerSignaturePostfix({} as DangerResults, commitID)}`,
252+
author: {
253+
name: "userNAME",
254+
},
255+
},
256+
},
257+
{
258+
comment: null,
259+
},
260+
{
261+
comment: {
262+
text: "not a danger comment",
263+
author: {
264+
name: "azz",
265+
},
266+
},
267+
},
268+
],
269+
})
270+
const result = await api.getDangerComments("1")
271+
272+
expect(api.fetch).toHaveBeenCalledWith(
273+
`${host}/rest/api/1.0/projects/FOO/repos/BAR/pull-requests/1/activities?fromType=COMMENT&start=0`,
274+
{ method: "GET", body: null, headers: expectedJSONHeaders },
275+
undefined
276+
)
277+
expect(result).toEqual([
278+
{
279+
text: `FAIL! danger-id-1; ${dangerSignaturePostfix({} as DangerResults, commitID)}`,
280+
author: {
281+
name: "userNAME",
282+
},
283+
},
284+
])
285+
})
286+
244287
it("getDangerInlineComments", async () => {
245288
jsonResult = () => ({
246289
isLastPage: true,
@@ -270,6 +313,35 @@ describe("API testing - BitBucket Server", () => {
270313
expect(comments[0].ownedByDanger).toBeTruthy()
271314
})
272315

316+
it("getDangerInlineCommentsCaseInsensitive", async () => {
317+
jsonResult = () => ({
318+
isLastPage: true,
319+
values: [
320+
{
321+
comment: {
322+
text:
323+
"\n[//]: # (danger-id-default;)\n[//]: # ( File: README.md;\n Line: 5;)\n\n- :warning: Hello updates\n\n\n ",
324+
author: {
325+
name: "userNAME",
326+
},
327+
},
328+
commentAnchor: {
329+
line: 5,
330+
lineType: "ADDED",
331+
},
332+
},
333+
],
334+
})
335+
const comments = await api.getDangerInlineComments("default")
336+
expect(api.fetch).toHaveBeenCalledWith(
337+
`${host}/rest/api/1.0/projects/FOO/repos/BAR/pull-requests/1/activities?fromType=COMMENT&start=0`,
338+
{ method: "GET", body: null, headers: expectedJSONHeaders },
339+
undefined
340+
)
341+
expect(comments.length).toEqual(1)
342+
expect(comments[0].ownedByDanger).toBeTruthy()
343+
})
344+
273345
it("getFileContents", async () => {
274346
textResult = "contents..."
275347
const result = await api.getFileContents("path/folder with space/foo.txt", "projects/FOO/repos/BAR", "master")

0 commit comments

Comments
 (0)