From 36b6a7680b30400888b773e394340a177801d3d4 Mon Sep 17 00:00:00 2001 From: ciucky Date: Wed, 13 Nov 2024 18:32:53 +0200 Subject: [PATCH] feat: add filter for bitbucket server /pull-request endpoint --- .../accept.json.sample | 10 + .../bitbucket-server/accept.json.sample | 11 + .../bitbucket-server-bearer-auth.json | 10 + defaultFilters/bitbucket-server.json | 11 + .../runtime-rules-hotloading.test.ts.snap | 252 ++++++++++++++++++ test/unit/filters.test.ts | 31 ++- 6 files changed, 323 insertions(+), 2 deletions(-) diff --git a/client-templates/bitbucket-server-bearer-auth/accept.json.sample b/client-templates/bitbucket-server-bearer-auth/accept.json.sample index 18242cb9a..e50a5e25a 100644 --- a/client-templates/bitbucket-server-bearer-auth/accept.json.sample +++ b/client-templates/bitbucket-server-bearer-auth/accept.json.sample @@ -1062,6 +1062,16 @@ "scheme": "bearer", "token": "${BITBUCKET_PAT}" } + }, + { + "//": "get a single pull request info", + "method": "GET", + "path": "/rest/api/1.0/projects/:project/repos/:repo/pull-requests/:pullRequestId", + "origin": "https://${BITBUCKET}", + "auth": { + "scheme": "bearer", + "token": "${BITBUCKET_PAT}" + } } ] } diff --git a/client-templates/bitbucket-server/accept.json.sample b/client-templates/bitbucket-server/accept.json.sample index 1d3d27c29..6dccfce48 100644 --- a/client-templates/bitbucket-server/accept.json.sample +++ b/client-templates/bitbucket-server/accept.json.sample @@ -1167,6 +1167,17 @@ "username": "${BITBUCKET_USERNAME}", "password": "${BITBUCKET_PASSWORD}" } + }, + { + "//": "get a single pull request info", + "method": "GET", + "path": "/rest/api/1.0/projects/:project/repos/:repo/pull-requests/:pullRequestId", + "origin": "https://${BITBUCKET_API}", + "auth": { + "scheme": "basic", + "username": "${BITBUCKET_USERNAME}", + "password": "${BITBUCKET_PASSWORD}" + } } ] } diff --git a/defaultFilters/bitbucket-server-bearer-auth.json b/defaultFilters/bitbucket-server-bearer-auth.json index 18242cb9a..e50a5e25a 100644 --- a/defaultFilters/bitbucket-server-bearer-auth.json +++ b/defaultFilters/bitbucket-server-bearer-auth.json @@ -1062,6 +1062,16 @@ "scheme": "bearer", "token": "${BITBUCKET_PAT}" } + }, + { + "//": "get a single pull request info", + "method": "GET", + "path": "/rest/api/1.0/projects/:project/repos/:repo/pull-requests/:pullRequestId", + "origin": "https://${BITBUCKET}", + "auth": { + "scheme": "bearer", + "token": "${BITBUCKET_PAT}" + } } ] } diff --git a/defaultFilters/bitbucket-server.json b/defaultFilters/bitbucket-server.json index bf84245cc..8e9e1300c 100644 --- a/defaultFilters/bitbucket-server.json +++ b/defaultFilters/bitbucket-server.json @@ -1167,6 +1167,17 @@ "username": "${BITBUCKET_USERNAME}", "password": "${BITBUCKET_PASSWORD}" } + }, + { + "//": "get a single pull request info", + "method": "GET", + "path": "/rest/api/1.0/projects/:project/repos/:repo/pull-requests/:pullRequestId", + "origin": "https://${BITBUCKET_API}", + "auth": { + "scheme": "basic", + "username": "${BITBUCKET_USERNAME}", + "password": "${BITBUCKET_PASSWORD}" + } } ] } \ No newline at end of file diff --git a/test/unit/__snapshots__/runtime-rules-hotloading.test.ts.snap b/test/unit/__snapshots__/runtime-rules-hotloading.test.ts.snap index 732385a6b..f92c30a01 100644 --- a/test/unit/__snapshots__/runtime-rules-hotloading.test.ts.snap +++ b/test/unit/__snapshots__/runtime-rules-hotloading.test.ts.snap @@ -1388,6 +1388,17 @@ Object { "origin": "https://\${BITBUCKET}", "path": "/rest/api/1.0/projects/:project/repos/:repo/permissions/search", }, + Object { + "//": "get a single pull request info", + "auth": Object { + "password": "\${BITBUCKET_PASSWORD}", + "scheme": "basic", + "username": "\${BITBUCKET_USERNAME}", + }, + "method": "GET", + "origin": "https://\${BITBUCKET_API}", + "path": "/rest/api/1.0/projects/:project/repos/:repo/pull-requests/:pullRequestId", + }, Object { "//": "used to get custom pull request template", "auth": Object { @@ -2480,6 +2491,16 @@ Object { "origin": "https://\${BITBUCKET}", "path": "/rest/api/1.0/projects/:project/repos/:repo/permissions/search", }, + Object { + "//": "get a single pull request info", + "auth": Object { + "scheme": "bearer", + "token": "\${BITBUCKET_PAT}", + }, + "method": "GET", + "origin": "https://\${BITBUCKET}", + "path": "/rest/api/1.0/projects/:project/repos/:repo/pull-requests/:pullRequestId", + }, Object { "//": "used to get custom pull request template", "auth": Object { @@ -9572,6 +9593,17 @@ Object { "origin": "https://\${BITBUCKET}", "path": "/rest/api/1.0/projects/:project/repos/:repo/permissions/search", }, + Object { + "//": "get a single pull request info", + "auth": Object { + "password": "\${BITBUCKET_PASSWORD}", + "scheme": "basic", + "username": "\${BITBUCKET_USERNAME}", + }, + "method": "GET", + "origin": "https://\${BITBUCKET_API}", + "path": "/rest/api/1.0/projects/:project/repos/:repo/pull-requests/:pullRequestId", + }, Object { "//": "used to get repo's commits", "auth": Object { @@ -10786,6 +10818,16 @@ Object { "origin": "https://\${BITBUCKET}", "path": "/rest/api/1.0/projects/:project/repos/:repo/permissions/search", }, + Object { + "//": "get a single pull request info", + "auth": Object { + "scheme": "bearer", + "token": "\${BITBUCKET_PAT}", + }, + "method": "GET", + "origin": "https://\${BITBUCKET}", + "path": "/rest/api/1.0/projects/:project/repos/:repo/pull-requests/:pullRequestId", + }, Object { "//": "used to get repo's commits", "auth": Object { @@ -17835,6 +17877,17 @@ Object { "origin": "https://\${BITBUCKET}", "path": "/rest/api/1.0/projects/:project/repos/:repo/permissions/search", }, + Object { + "//": "get a single pull request info", + "auth": Object { + "password": "\${BITBUCKET_PASSWORD}", + "scheme": "basic", + "username": "\${BITBUCKET_USERNAME}", + }, + "method": "GET", + "origin": "https://\${BITBUCKET_API}", + "path": "/rest/api/1.0/projects/:project/repos/:repo/pull-requests/:pullRequestId", + }, ], "public": Array [ Object { @@ -18905,6 +18958,16 @@ Object { "origin": "https://\${BITBUCKET}", "path": "/rest/api/1.0/projects/:project/repos/:repo/permissions/search", }, + Object { + "//": "get a single pull request info", + "auth": Object { + "scheme": "bearer", + "token": "\${BITBUCKET_PAT}", + }, + "method": "GET", + "origin": "https://\${BITBUCKET}", + "path": "/rest/api/1.0/projects/:project/repos/:repo/pull-requests/:pullRequestId", + }, ], "public": Array [ Object { @@ -25712,6 +25775,17 @@ Object { "origin": "https://\${BITBUCKET}", "path": "/rest/api/1.0/projects/:project/repos/:repo/permissions/search", }, + Object { + "//": "get a single pull request info", + "auth": Object { + "password": "\${BITBUCKET_PASSWORD}", + "scheme": "basic", + "username": "\${BITBUCKET_USERNAME}", + }, + "method": "GET", + "origin": "https://\${BITBUCKET_API}", + "path": "/rest/api/1.0/projects/:project/repos/:repo/pull-requests/:pullRequestId", + }, Object { "//": "allow info refs (for git clone)", "auth": Object { @@ -26815,6 +26889,16 @@ Object { "origin": "https://\${BITBUCKET}", "path": "/rest/api/1.0/projects/:project/repos/:repo/permissions/search", }, + Object { + "//": "get a single pull request info", + "auth": Object { + "scheme": "bearer", + "token": "\${BITBUCKET_PAT}", + }, + "method": "GET", + "origin": "https://\${BITBUCKET}", + "path": "/rest/api/1.0/projects/:project/repos/:repo/pull-requests/:pullRequestId", + }, Object { "//": "allow info refs (for git clone)", "auth": Object { @@ -33698,6 +33782,17 @@ Object { "origin": "https://\${BITBUCKET}", "path": "/rest/api/1.0/projects/:project/repos/:repo/permissions/search", }, + Object { + "//": "get a single pull request info", + "auth": Object { + "password": "\${BITBUCKET_PASSWORD}", + "scheme": "basic", + "username": "\${BITBUCKET_USERNAME}", + }, + "method": "GET", + "origin": "https://\${BITBUCKET_API}", + "path": "/rest/api/1.0/projects/:project/repos/:repo/pull-requests/:pullRequestId", + }, Object { "//": "used to scan IAC files", "auth": Object { @@ -34823,6 +34918,16 @@ Object { "origin": "https://\${BITBUCKET}", "path": "/rest/api/1.0/projects/:project/repos/:repo/permissions/search", }, + Object { + "//": "get a single pull request info", + "auth": Object { + "scheme": "bearer", + "token": "\${BITBUCKET_PAT}", + }, + "method": "GET", + "origin": "https://\${BITBUCKET}", + "path": "/rest/api/1.0/projects/:project/repos/:repo/pull-requests/:pullRequestId", + }, Object { "//": "used to scan IAC files", "auth": Object { @@ -41758,6 +41863,17 @@ Object { "origin": "https://\${BITBUCKET}", "path": "/rest/api/1.0/projects/:project/repos/:repo/permissions/search", }, + Object { + "//": "get a single pull request info", + "auth": Object { + "password": "\${BITBUCKET_PASSWORD}", + "scheme": "basic", + "username": "\${BITBUCKET_USERNAME}", + }, + "method": "GET", + "origin": "https://\${BITBUCKET_API}", + "path": "/rest/api/1.0/projects/:project/repos/:repo/pull-requests/:pullRequestId", + }, Object { "//": "allow info refs (for git clone)", "auth": Object { @@ -42861,6 +42977,16 @@ Object { "origin": "https://\${BITBUCKET}", "path": "/rest/api/1.0/projects/:project/repos/:repo/permissions/search", }, + Object { + "//": "get a single pull request info", + "auth": Object { + "scheme": "bearer", + "token": "\${BITBUCKET_PAT}", + }, + "method": "GET", + "origin": "https://\${BITBUCKET}", + "path": "/rest/api/1.0/projects/:project/repos/:repo/pull-requests/:pullRequestId", + }, Object { "//": "allow info refs (for git clone)", "auth": Object { @@ -50185,6 +50311,17 @@ Object { "origin": "https://\${BITBUCKET}", "path": "/rest/api/1.0/projects/:project/repos/:repo/permissions/search", }, + Object { + "//": "get a single pull request info", + "auth": Object { + "password": "\${BITBUCKET_PASSWORD}", + "scheme": "basic", + "username": "\${BITBUCKET_USERNAME}", + }, + "method": "GET", + "origin": "https://\${BITBUCKET_API}", + "path": "/rest/api/1.0/projects/:project/repos/:repo/pull-requests/:pullRequestId", + }, Object { "//": "used to scan IAC files", "auth": Object { @@ -51470,6 +51607,17 @@ Object { "origin": "https://\${BITBUCKET}", "path": "/rest/api/1.0/projects/:project/repos/:repo/permissions/search", }, + Object { + "//": "get a single pull request info", + "auth": Object { + "password": "\${BITBUCKET_PASSWORD}", + "scheme": "basic", + "username": "\${BITBUCKET_USERNAME}", + }, + "method": "GET", + "origin": "https://\${BITBUCKET_API}", + "path": "/rest/api/1.0/projects/:project/repos/:repo/pull-requests/:pullRequestId", + }, Object { "//": "used to scan IAC files", "auth": Object { @@ -52584,6 +52732,16 @@ Object { "origin": "https://\${BITBUCKET}", "path": "/rest/api/1.0/projects/:project/repos/:repo/permissions/search", }, + Object { + "//": "get a single pull request info", + "auth": Object { + "scheme": "bearer", + "token": "\${BITBUCKET_PAT}", + }, + "method": "GET", + "origin": "https://\${BITBUCKET}", + "path": "/rest/api/1.0/projects/:project/repos/:repo/pull-requests/:pullRequestId", + }, Object { "//": "used to scan IAC files", "auth": Object { @@ -53754,6 +53912,16 @@ Object { "origin": "https://\${BITBUCKET}", "path": "/rest/api/1.0/projects/:project/repos/:repo/permissions/search", }, + Object { + "//": "get a single pull request info", + "auth": Object { + "scheme": "bearer", + "token": "\${BITBUCKET_PAT}", + }, + "method": "GET", + "origin": "https://\${BITBUCKET}", + "path": "/rest/api/1.0/projects/:project/repos/:repo/pull-requests/:pullRequestId", + }, Object { "//": "used to scan IAC files", "auth": Object { @@ -65970,6 +66138,17 @@ Object { "origin": "https://\${BITBUCKET}", "path": "/rest/api/1.0/projects/:project/repos/:repo/permissions/search", }, + Object { + "//": "get a single pull request info", + "auth": Object { + "password": "\${BITBUCKET_PASSWORD}", + "scheme": "basic", + "username": "\${BITBUCKET_USERNAME}", + }, + "method": "GET", + "origin": "https://\${BITBUCKET_API}", + "path": "/rest/api/1.0/projects/:project/repos/:repo/pull-requests/:pullRequestId", + }, ], "public": Array [ Object { @@ -67040,6 +67219,16 @@ Object { "origin": "https://\${BITBUCKET}", "path": "/rest/api/1.0/projects/:project/repos/:repo/permissions/search", }, + Object { + "//": "get a single pull request info", + "auth": Object { + "scheme": "bearer", + "token": "\${BITBUCKET_PAT}", + }, + "method": "GET", + "origin": "https://\${BITBUCKET}", + "path": "/rest/api/1.0/projects/:project/repos/:repo/pull-requests/:pullRequestId", + }, ], "public": Array [ Object { @@ -73805,6 +73994,17 @@ Object { "origin": "https://\${BITBUCKET}", "path": "/rest/api/1.0/projects/:project/repos/:repo/permissions/search", }, + Object { + "//": "get a single pull request info", + "auth": Object { + "password": "\${BITBUCKET_PASSWORD}", + "scheme": "basic", + "username": "\${BITBUCKET_USERNAME}", + }, + "method": "GET", + "origin": "https://\${BITBUCKET_API}", + "path": "/rest/api/1.0/projects/:project/repos/:repo/pull-requests/:pullRequestId", + }, ], "public": Array [ Object { @@ -74875,6 +75075,16 @@ Object { "origin": "https://\${BITBUCKET}", "path": "/rest/api/1.0/projects/:project/repos/:repo/permissions/search", }, + Object { + "//": "get a single pull request info", + "auth": Object { + "scheme": "bearer", + "token": "\${BITBUCKET_PAT}", + }, + "method": "GET", + "origin": "https://\${BITBUCKET}", + "path": "/rest/api/1.0/projects/:project/repos/:repo/pull-requests/:pullRequestId", + }, ], "public": Array [ Object { @@ -81640,6 +81850,17 @@ Object { "origin": "https://\${BITBUCKET}", "path": "/rest/api/1.0/projects/:project/repos/:repo/permissions/search", }, + Object { + "//": "get a single pull request info", + "auth": Object { + "password": "\${BITBUCKET_PASSWORD}", + "scheme": "basic", + "username": "\${BITBUCKET_USERNAME}", + }, + "method": "GET", + "origin": "https://\${BITBUCKET_API}", + "path": "/rest/api/1.0/projects/:project/repos/:repo/pull-requests/:pullRequestId", + }, ], "public": Array [ Object { @@ -82710,6 +82931,16 @@ Object { "origin": "https://\${BITBUCKET}", "path": "/rest/api/1.0/projects/:project/repos/:repo/permissions/search", }, + Object { + "//": "get a single pull request info", + "auth": Object { + "scheme": "bearer", + "token": "\${BITBUCKET_PAT}", + }, + "method": "GET", + "origin": "https://\${BITBUCKET}", + "path": "/rest/api/1.0/projects/:project/repos/:repo/pull-requests/:pullRequestId", + }, ], "public": Array [ Object { @@ -89475,6 +89706,17 @@ Object { "origin": "https://\${BITBUCKET}", "path": "/rest/api/1.0/projects/:project/repos/:repo/permissions/search", }, + Object { + "//": "get a single pull request info", + "auth": Object { + "password": "\${BITBUCKET_PASSWORD}", + "scheme": "basic", + "username": "\${BITBUCKET_USERNAME}", + }, + "method": "GET", + "origin": "https://\${BITBUCKET_API}", + "path": "/rest/api/1.0/projects/:project/repos/:repo/pull-requests/:pullRequestId", + }, ], "public": Array [ Object { @@ -90545,6 +90787,16 @@ Object { "origin": "https://\${BITBUCKET}", "path": "/rest/api/1.0/projects/:project/repos/:repo/permissions/search", }, + Object { + "//": "get a single pull request info", + "auth": Object { + "scheme": "bearer", + "token": "\${BITBUCKET_PAT}", + }, + "method": "GET", + "origin": "https://\${BITBUCKET}", + "path": "/rest/api/1.0/projects/:project/repos/:repo/pull-requests/:pullRequestId", + }, ], "public": Array [ Object { diff --git a/test/unit/filters.test.ts b/test/unit/filters.test.ts index e038b5dd5..a249134a4 100644 --- a/test/unit/filters.test.ts +++ b/test/unit/filters.test.ts @@ -145,6 +145,19 @@ describe('filters', () => { const filterResponseUrl = filterResponse ? filterResponse.url : ''; expect(filterResponseUrl).toMatch(url); }); + + it('should allow fetching single PR info', () => { + const url = + '/rest/api/1.0/projects/test-org/repos/test-repo/pull-requests/1'; + + const filterResponse = filter({ + url, + method: 'GET', + }); + expect(filterResponse).not.toEqual(false); + const filterResponseUrl = filterResponse ? filterResponse.url : ''; + expect(filterResponseUrl).toMatch(url); + }); }); describe('for bitbucket server bearer auth private filters', () => { @@ -204,6 +217,19 @@ describe('filters', () => { const filterResponseUrl = filterResponse ? filterResponse.url : ''; expect(filterResponseUrl).toMatch(url); }); + + it('should allow fetching pr info', () => { + const url = + '/rest/api/1.0/projects/test-org/repos/test-repo/pull-requests/1'; + + const filterResponse = filter({ + url, + method: 'GET', + }); + expect(filterResponse).not.toEqual(false); + const filterResponseUrl = filterResponse ? filterResponse.url : ''; + expect(filterResponseUrl).toMatch(url); + }); }); describe('for azure repos', () => { @@ -236,8 +262,9 @@ describe('filters', () => { expect(filterResponseUrl).toMatch(url); }); - it('should allow fetching pr info', () => { - const url = '/test-owner/_apis/git/repositories/test-repo/pullRequests/1'; + it('should allow fetching single pr info', () => { + const url = + '/test-owner/_apis/git/repositories/test-repo/pullRequests/1'; const filterResponse = filter({ url,