diff --git a/packages/cli/src/config/extensions/github.test.ts b/packages/cli/src/config/extensions/github.test.ts index 6019cfda57..a23e330612 100644 --- a/packages/cli/src/config/extensions/github.test.ts +++ b/packages/cli/src/config/extensions/github.test.ts @@ -292,13 +292,20 @@ describe('git extension helpers', () => { expect(repo).toBe('repo'); }); - it('should parse owner and repo from a full GitHub UR without .git', () => { + it('should parse owner and repo from a full GitHub URL without .git', () => { const source = 'https://github.com/owner/repo'; const { owner, repo } = parseGitHubRepoForReleases(source); expect(owner).toBe('owner'); expect(repo).toBe('repo'); }); + it('should parse owner and repo from a full GitHub URL with a trailing slash', () => { + const source = 'https://github.com/owner/repo/'; + const { owner, repo } = parseGitHubRepoForReleases(source); + expect(owner).toBe('owner'); + expect(repo).toBe('repo'); + }); + it('should fail on a GitHub SSH URL', () => { const source = 'git@github.com:owner/repo.git'; expect(() => parseGitHubRepoForReleases(source)).toThrow( diff --git a/packages/cli/src/config/extensions/github.ts b/packages/cli/src/config/extensions/github.ts index 3bc148c82d..9a54a29f9d 100644 --- a/packages/cli/src/config/extensions/github.ts +++ b/packages/cli/src/config/extensions/github.ts @@ -85,7 +85,11 @@ export function parseGitHubRepoForReleases(source: string): { // Default to a github repo path, so `source` can be just an org/repo const parsedUrl = URL.parse(source, 'https://github.com'); // The pathname should be "/owner/repo". - const parts = parsedUrl?.pathname.substring(1).split('/'); + const parts = parsedUrl?.pathname + .substring(1) + .split('/') + // Remove the empty segments, fixes trailing slashes + .filter((part) => part !== ''); if (parts?.length !== 2 || parsedUrl?.host !== 'github.com') { throw new Error( `Invalid GitHub repository source: ${source}. Expected "owner/repo" or a github repo uri.`,