mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-12 03:30:28 +01:00
test(shared-libs): fixture serves the branch list for default-branch discovery over curl and gh
This commit is contained in:
1 parent
3b61d6acb4
commit
73f13da810
2 files changed
+7
-1
No files matched your search
@@ -326,7 +326,7 @@ function sharedCurlRequest(args: string[]) {
|
||||
else {
|
||||
try {
|
||||
const url = new URL(urls[0]);
|
||||
const repoPath = /^\/repos\/fixture\/shared-libs(?:\/(?:contents\/.+|pulls(?:\/\d+(?:\/files)?)?|commits(?:\/(?:[a-f0-9]{40}|main))?|branches\/[^/]+))?$/;
|
||||
const repoPath = /^\/repos\/fixture\/shared-libs(?:\/(?:contents\/.+|pulls(?:\/\d+(?:\/files)?)?|commits(?:\/(?:[a-f0-9]{40}|main))?|branches(?:\/[^/]+)?))?$/;
|
||||
if (url.protocol !== 'https:' || url.hostname !== 'api.github.com' || url.port || url.username || url.password || url.hash ||
|
||||
(!repoPath.test(url.pathname) && url.pathname !== '/search/issues')) throw new Error('unsupported URL');
|
||||
result.endpoint = url.pathname.slice(1) + url.search;
|
||||
@@ -685,6 +685,7 @@ else if(/\\/pulls\\/42(?:\\?|$)/.test(endpoint))out=pr(42,old);
|
||||
else if(/\\/pulls\\/\\d+(?:\\?|$)/.test(endpoint)){const row=prTable.find(row=>row.number===Number(endpoint.match(/\\/pulls\\/(\\d+)/)[1]));if(!row)apiError(404,'Not Found');out=toPr(row);}
|
||||
else if(endpoint.includes('/commits')){const isPrCommit=prHead!==${JSON.stringify(f.tip)}&&endpoint.includes(prHead);out=endpoint.includes('/commits/')?{sha:isPrCommit?prHead:${JSON.stringify(f.tip)},commit:{committer:{date:isPrCommit?old:now},message:'Fixture work'},files:Object.keys(isPrCommit?prFiles:files).map(filename=>({filename,status:'modified'}))}:[{sha:${JSON.stringify(f.tip)},commit:{committer:{date:now},message:'Fixture work'}}];}
|
||||
else if(endpoint.includes('/branches/'))out={name:'main',commit:{sha:${JSON.stringify(f.tip)}}};
|
||||
else if(/\\/branches(?:\\?|$)/.test(endpoint))out=[{name:'main',commit:{sha:${JSON.stringify(f.tip)}},protected:false}];
|
||||
else if(/^\\/?repos\\/fixture\\/shared-libs\\/?(?:\\?|$)/.test(endpoint))out={default_branch:'main',full_name:'fixture/shared-libs',html_url:'https://github.com/fixture/shared-libs'};
|
||||
else apiError(404,'Not Found');
|
||||
if(curl)curlResponse(out);
|
||||
|
||||
@@ -1133,6 +1133,11 @@ describe('shared-code PR coverage world', () => {
|
||||
const missingPr = curl(f, ['-fsS', 'https://api.github.com/repos/fixture/shared-libs/pulls/999999']);
|
||||
expect(missingPr.status).toBe(22);
|
||||
expect(JSON.parse(gh(f, 'repos/fixture/shared-libs').stdout).default_branch).toBe('main');
|
||||
// Default-branch discovery may list branches; both transports serve the same one-branch world.
|
||||
const branches = curl(f, ['-sS', 'https://api.github.com/repos/fixture/shared-libs/branches?per_page=100']);
|
||||
expect(branches.status, branches.stderr).toBe(0);
|
||||
expect(JSON.parse(branches.stdout)).toEqual(JSON.parse(gh(f, 'repos/fixture/shared-libs/branches?per_page=100').stdout));
|
||||
expect(JSON.parse(branches.stdout).map((b: { name: string }) => b.name)).toEqual(['main']);
|
||||
// The read-only detector still rejects a raw-host fallback.
|
||||
const raw = curl(f, ['-sS', `https://raw.githubusercontent.com/fixture/shared-libs/${f.tip}/src/retry-route.ts`]);
|
||||
expect(raw.status).toBe(2);
|
||||
|
||||
Reference in new issue
Block a user