|
9 | 9 | checkForExtensionUpdate, |
10 | 10 | cloneFromGit, |
11 | 11 | findReleaseAsset, |
| 12 | + parseGitHubRepoForReleases, |
12 | 13 | } from './github.js'; |
13 | 14 | import { simpleGit, type SimpleGit } from 'simple-git'; |
14 | 15 | import { ExtensionUpdateState } from '../../ui/state/extensions.js'; |
@@ -231,4 +232,55 @@ describe('git extension helpers', () => { |
231 | 232 | expect(result).toBeUndefined(); |
232 | 233 | }); |
233 | 234 | }); |
| 235 | + |
| 236 | + describe('parseGitHubRepoForReleases', () => { |
| 237 | + it('should parse owner and repo from a full GitHub URL', () => { |
| 238 | + const source = 'https://github.com/owner/repo.git'; |
| 239 | + const { owner, repo } = parseGitHubRepoForReleases(source); |
| 240 | + expect(owner).toBe('owner'); |
| 241 | + expect(repo).toBe('repo'); |
| 242 | + }); |
| 243 | + |
| 244 | + it('should parse owner and repo from a full GitHub UR without .git', () => { |
| 245 | + const source = 'https://github.com/owner/repo'; |
| 246 | + const { owner, repo } = parseGitHubRepoForReleases(source); |
| 247 | + expect(owner).toBe('owner'); |
| 248 | + expect(repo).toBe('repo'); |
| 249 | + }); |
| 250 | + |
| 251 | + it('should fail on a GitHub SSH URL', () => { |
| 252 | + const source = 'git@github.com:owner/repo.git'; |
| 253 | + expect(() => parseGitHubRepoForReleases(source)).toThrow( |
| 254 | + 'GitHub release-based extensions are not supported for SSH. You must use an HTTPS URI with a personal access token to download releases from private repositories. You can set your personal access token in the GITHUB_TOKEN environment variable and install the extension via SSH.', |
| 255 | + ); |
| 256 | + }); |
| 257 | + |
| 258 | + it('should parse owner and repo from a shorthand string', () => { |
| 259 | + const source = 'owner/repo'; |
| 260 | + const { owner, repo } = parseGitHubRepoForReleases(source); |
| 261 | + expect(owner).toBe('owner'); |
| 262 | + expect(repo).toBe('repo'); |
| 263 | + }); |
| 264 | + |
| 265 | + it('should handle .git suffix in repo name', () => { |
| 266 | + const source = 'owner/repo.git'; |
| 267 | + const { owner, repo } = parseGitHubRepoForReleases(source); |
| 268 | + expect(owner).toBe('owner'); |
| 269 | + expect(repo).toBe('repo'); |
| 270 | + }); |
| 271 | + |
| 272 | + it('should throw error for invalid source format', () => { |
| 273 | + const source = 'invalid-format'; |
| 274 | + expect(() => parseGitHubRepoForReleases(source)).toThrow( |
| 275 | + 'Invalid GitHub repository source: invalid-format. Expected "owner/repo" or a github repo uri.', |
| 276 | + ); |
| 277 | + }); |
| 278 | + |
| 279 | + it('should throw error for source with too many parts', () => { |
| 280 | + const source = 'https://github.com/owner/repo/extra'; |
| 281 | + expect(() => parseGitHubRepoForReleases(source)).toThrow( |
| 282 | + 'Invalid GitHub repository source: https://github.com/owner/repo/extra. Expected "owner/repo" or a github repo uri.', |
| 283 | + ); |
| 284 | + }); |
| 285 | + }); |
234 | 286 | }); |
0 commit comments