From 53872c7f97d56ec2b317223f25cd626b85b70b9c Mon Sep 17 00:00:00 2001 From: ciucky Date: Wed, 13 Nov 2024 17:19:11 +0200 Subject: [PATCH] feat: add filter for azure repos /pull-request endpoint --- .../azure-repos/accept.json.sample | 16 ++ defaultFilters/azure-repos.json | 16 ++ .../runtime-rules-hotloading.test.ts.snap | 228 ++++++++++++++++++ test/unit/filters.test.ts | 27 +++ 4 files changed, 287 insertions(+) diff --git a/client-templates/azure-repos/accept.json.sample b/client-templates/azure-repos/accept.json.sample index 501ffd516..a80885490 100644 --- a/client-templates/azure-repos/accept.json.sample +++ b/client-templates/azure-repos/accept.json.sample @@ -388,6 +388,22 @@ "scheme": "basic", "token": "${BROKER_CLIENT_VALIDATION_BASIC_AUTH}" } + }, + { + "//": "get pull-request info", + "method": "GET", + "path": "/:owner/_apis/git/repositories/:repo/pullrequests/:pullRef", + "origin": "https://${AZURE_REPOS_HOST}/${AZURE_REPOS_ORG}", + "valid": [ + { + "queryParam": "api-version", + "values": ["7.1", ""] + } + ], + "auth": { + "scheme": "basic", + "token": "${BROKER_CLIENT_VALIDATION_BASIC_AUTH}" + } } ] } diff --git a/defaultFilters/azure-repos.json b/defaultFilters/azure-repos.json index faf223982..654c2eb2a 100644 --- a/defaultFilters/azure-repos.json +++ b/defaultFilters/azure-repos.json @@ -388,6 +388,22 @@ "scheme": "basic", "token": "${BROKER_CLIENT_VALIDATION_BASIC_AUTH}" } + }, + { + "//": "get pull-request info", + "method": "GET", + "path": "/:owner/_apis/git/repositories/:repo/pullrequests/:pullRef", + "origin": "https://${AZURE_REPOS_HOST}/${AZURE_REPOS_ORG}", + "valid": [ + { + "queryParam": "api-version", + "values": ["7.1", ""] + } + ], + "auth": { + "scheme": "basic", + "token": "${BROKER_CLIENT_VALIDATION_BASIC_AUTH}" + } } ] } \ 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 23b520828..bbb51b7d2 100644 --- a/test/unit/__snapshots__/runtime-rules-hotloading.test.ts.snap +++ b/test/unit/__snapshots__/runtime-rules-hotloading.test.ts.snap @@ -179,6 +179,25 @@ Object { "origin": "https://\${AZURE_REPOS_HOST}/\${AZURE_REPOS_ORG}", "path": "/:owner/_apis/git/repositories/:repo/pullRequests/:pullRef/iterations", }, + Object { + "//": "get pull-request info", + "auth": Object { + "scheme": "basic", + "token": "\${BROKER_CLIENT_VALIDATION_BASIC_AUTH}", + }, + "method": "GET", + "origin": "https://\${AZURE_REPOS_HOST}/\${AZURE_REPOS_ORG}", + "path": "/:owner/_apis/git/repositories/:repo/pullrequests/:pullRef", + "valid": Array [ + Object { + "queryParam": "api-version", + "values": Array [ + "7.1", + "", + ], + }, + ], + }, Object { "//": "get file content. restrict by file types", "method": "GET", @@ -8026,6 +8045,25 @@ Object { "origin": "https://\${AZURE_REPOS_HOST}/\${AZURE_REPOS_ORG}", "path": "/:owner/_apis/git/repositories/:repo/pullRequests/:pullRef/iterations", }, + Object { + "//": "get pull-request info", + "auth": Object { + "scheme": "basic", + "token": "\${BROKER_CLIENT_VALIDATION_BASIC_AUTH}", + }, + "method": "GET", + "origin": "https://\${AZURE_REPOS_HOST}/\${AZURE_REPOS_ORG}", + "path": "/:owner/_apis/git/repositories/:repo/pullrequests/:pullRef", + "valid": Array [ + Object { + "queryParam": "api-version", + "values": Array [ + "7.1", + "", + ], + }, + ], + }, Object { "//": "get core api's location for sanity check", "auth": Object { @@ -16591,6 +16629,25 @@ Object { "origin": "https://\${AZURE_REPOS_HOST}/\${AZURE_REPOS_ORG}", "path": "/:owner/_apis/git/repositories/:repo/pullRequests/:pullRef/iterations", }, + Object { + "//": "get pull-request info", + "auth": Object { + "scheme": "basic", + "token": "\${BROKER_CLIENT_VALIDATION_BASIC_AUTH}", + }, + "method": "GET", + "origin": "https://\${AZURE_REPOS_HOST}/\${AZURE_REPOS_ORG}", + "path": "/:owner/_apis/git/repositories/:repo/pullrequests/:pullRef", + "valid": Array [ + Object { + "queryParam": "api-version", + "values": Array [ + "7.1", + "", + ], + }, + ], + }, ], "public": Array [ Object { @@ -24413,6 +24470,25 @@ Object { "origin": "https://\${AZURE_REPOS_HOST}/\${AZURE_REPOS_ORG}", "path": "/:owner/_apis/git/repositories/:repo/pullRequests/:pullRef/iterations", }, + Object { + "//": "get pull-request info", + "auth": Object { + "scheme": "basic", + "token": "\${BROKER_CLIENT_VALIDATION_BASIC_AUTH}", + }, + "method": "GET", + "origin": "https://\${AZURE_REPOS_HOST}/\${AZURE_REPOS_ORG}", + "path": "/:owner/_apis/git/repositories/:repo/pullrequests/:pullRef", + "valid": Array [ + Object { + "queryParam": "api-version", + "values": Array [ + "7.1", + "", + ], + }, + ], + }, Object { "//": "allow info refs (for git clone)", "auth": Object { @@ -32374,6 +32450,25 @@ Object { "origin": "https://\${AZURE_REPOS_HOST}/\${AZURE_REPOS_ORG}", "path": "/:owner/_apis/git/repositories/:repo/pullRequests/:pullRef/iterations", }, + Object { + "//": "get pull-request info", + "auth": Object { + "scheme": "basic", + "token": "\${BROKER_CLIENT_VALIDATION_BASIC_AUTH}", + }, + "method": "GET", + "origin": "https://\${AZURE_REPOS_HOST}/\${AZURE_REPOS_ORG}", + "path": "/:owner/_apis/git/repositories/:repo/pullrequests/:pullRef", + "valid": Array [ + Object { + "queryParam": "api-version", + "values": Array [ + "7.1", + "", + ], + }, + ], + }, Object { "//": "allow info refs (for git clone)", "auth": Object { @@ -40409,6 +40504,25 @@ Object { "origin": "https://\${AZURE_REPOS_HOST}/\${AZURE_REPOS_ORG}", "path": "/:owner/_apis/git/repositories/:repo/pullRequests/:pullRef/iterations", }, + Object { + "//": "get pull-request info", + "auth": Object { + "scheme": "basic", + "token": "\${BROKER_CLIENT_VALIDATION_BASIC_AUTH}", + }, + "method": "GET", + "origin": "https://\${AZURE_REPOS_HOST}/\${AZURE_REPOS_ORG}", + "path": "/:owner/_apis/git/repositories/:repo/pullrequests/:pullRef", + "valid": Array [ + Object { + "queryParam": "api-version", + "values": Array [ + "7.1", + "", + ], + }, + ], + }, Object { "//": "allow info refs (for git clone)", "auth": Object { @@ -48402,6 +48516,25 @@ Object { "origin": "https://\${AZURE_REPOS_HOST}/\${AZURE_REPOS_ORG}", "path": "/:owner/_apis/git/repositories/:repo/pullRequests/:pullRef/iterations", }, + Object { + "//": "get pull-request info", + "auth": Object { + "scheme": "basic", + "token": "\${BROKER_CLIENT_VALIDATION_BASIC_AUTH}", + }, + "method": "GET", + "origin": "https://\${AZURE_REPOS_HOST}/\${AZURE_REPOS_ORG}", + "path": "/:owner/_apis/git/repositories/:repo/pullrequests/:pullRef", + "valid": Array [ + Object { + "queryParam": "api-version", + "values": Array [ + "7.1", + "", + ], + }, + ], + }, ], "public": Array [ Object { @@ -48822,6 +48955,25 @@ Object { "origin": "https://\${AZURE_REPOS_HOST}/\${AZURE_REPOS_ORG}", "path": "/:owner/_apis/git/repositories/:repo/pullRequests/:pullRef/iterations", }, + Object { + "//": "get pull-request info", + "auth": Object { + "scheme": "basic", + "token": "\${BROKER_CLIENT_VALIDATION_BASIC_AUTH}", + }, + "method": "GET", + "origin": "https://\${AZURE_REPOS_HOST}/\${AZURE_REPOS_ORG}", + "path": "/:owner/_apis/git/repositories/:repo/pullrequests/:pullRef", + "valid": Array [ + Object { + "queryParam": "api-version", + "values": Array [ + "7.1", + "", + ], + }, + ], + }, ], "public": Array [ Object { @@ -64576,6 +64728,25 @@ Object { "origin": "https://\${AZURE_REPOS_HOST}/\${AZURE_REPOS_ORG}", "path": "/:owner/_apis/git/repositories/:repo/pullRequests/:pullRef/iterations", }, + Object { + "//": "get pull-request info", + "auth": Object { + "scheme": "basic", + "token": "\${BROKER_CLIENT_VALIDATION_BASIC_AUTH}", + }, + "method": "GET", + "origin": "https://\${AZURE_REPOS_HOST}/\${AZURE_REPOS_ORG}", + "path": "/:owner/_apis/git/repositories/:repo/pullrequests/:pullRef", + "valid": Array [ + Object { + "queryParam": "api-version", + "values": Array [ + "7.1", + "", + ], + }, + ], + }, ], "public": Array [ Object { @@ -72386,6 +72557,25 @@ Object { "origin": "https://\${AZURE_REPOS_HOST}/\${AZURE_REPOS_ORG}", "path": "/:owner/_apis/git/repositories/:repo/pullRequests/:pullRef/iterations", }, + Object { + "//": "get pull-request info", + "auth": Object { + "scheme": "basic", + "token": "\${BROKER_CLIENT_VALIDATION_BASIC_AUTH}", + }, + "method": "GET", + "origin": "https://\${AZURE_REPOS_HOST}/\${AZURE_REPOS_ORG}", + "path": "/:owner/_apis/git/repositories/:repo/pullrequests/:pullRef", + "valid": Array [ + Object { + "queryParam": "api-version", + "values": Array [ + "7.1", + "", + ], + }, + ], + }, ], "public": Array [ Object { @@ -80196,6 +80386,25 @@ Object { "origin": "https://\${AZURE_REPOS_HOST}/\${AZURE_REPOS_ORG}", "path": "/:owner/_apis/git/repositories/:repo/pullRequests/:pullRef/iterations", }, + Object { + "//": "get pull-request info", + "auth": Object { + "scheme": "basic", + "token": "\${BROKER_CLIENT_VALIDATION_BASIC_AUTH}", + }, + "method": "GET", + "origin": "https://\${AZURE_REPOS_HOST}/\${AZURE_REPOS_ORG}", + "path": "/:owner/_apis/git/repositories/:repo/pullrequests/:pullRef", + "valid": Array [ + Object { + "queryParam": "api-version", + "values": Array [ + "7.1", + "", + ], + }, + ], + }, ], "public": Array [ Object { @@ -88006,6 +88215,25 @@ Object { "origin": "https://\${AZURE_REPOS_HOST}/\${AZURE_REPOS_ORG}", "path": "/:owner/_apis/git/repositories/:repo/pullRequests/:pullRef/iterations", }, + Object { + "//": "get pull-request info", + "auth": Object { + "scheme": "basic", + "token": "\${BROKER_CLIENT_VALIDATION_BASIC_AUTH}", + }, + "method": "GET", + "origin": "https://\${AZURE_REPOS_HOST}/\${AZURE_REPOS_ORG}", + "path": "/:owner/_apis/git/repositories/:repo/pullrequests/:pullRef", + "valid": Array [ + Object { + "queryParam": "api-version", + "values": Array [ + "7.1", + "", + ], + }, + ], + }, ], "public": Array [ Object { diff --git a/test/unit/filters.test.ts b/test/unit/filters.test.ts index 514799538..980942152 100644 --- a/test/unit/filters.test.ts +++ b/test/unit/filters.test.ts @@ -235,6 +235,33 @@ describe('filters', () => { const filterResponseUrl = filterResponse ? filterResponse.url : ''; expect(filterResponseUrl).toMatch(url); }); + + it('should allow fetching pr info', () => { + const url = '/test-owner/_apis/git/repositories/test-repo/pullRequests/1'; + + const filterResponse = filter({ + url, + method: 'GET', + }); + + expect(filterResponse).not.toEqual(false); + const filterResponseUrl = filterResponse ? filterResponse.url : ''; + expect(filterResponseUrl).toMatch(url); + }); + + it('should allow fetching pr info with api-version', () => { + const url = + '/test-owner/_apis/git/repositories/test-repo/pullrequests/1?api-version=7.1'; + + const filterResponse = filter({ + url, + method: 'GET', + }); + + expect(filterResponse).not.toEqual(false); + const filterResponseUrl = filterResponse ? filterResponse.url : ''; + expect(filterResponseUrl).toMatch(url); + }); }); describe('for gitlab', () => {