Skip to content

Commit 6bdd0ab

Browse files
authored
fix(plugin-github): parse new style github urls (#1318)
* fix(plugin-github): parse new style github urls Fixes #1317. * chore(release-workflow): set releases * refactor(plugin-github): extract commit using querystring * refactor: make `parseGithubUrl` support both old style and new style urls
1 parent 8d38dc2 commit 6bdd0ab

File tree

4 files changed

+51
-2
lines changed

4 files changed

+51
-2
lines changed

.yarn/versions/d8dd0ce4.yml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
releases:
2+
"@yarnpkg/plugin-github": prerelease
3+
"@yarnpkg/cli": prerelease
4+
5+
declined:
6+
- "@yarnpkg/plugin-compat"
7+
- "@yarnpkg/plugin-constraints"
8+
- "@yarnpkg/plugin-dlx"
9+
- "@yarnpkg/plugin-essentials"
10+
- "@yarnpkg/plugin-exec"
11+
- "@yarnpkg/plugin-file"
12+
- "@yarnpkg/plugin-git"
13+
- "@yarnpkg/plugin-github"
14+
- "@yarnpkg/plugin-http"
15+
- "@yarnpkg/plugin-init"
16+
- "@yarnpkg/plugin-interactive-tools"
17+
- "@yarnpkg/plugin-link"
18+
- "@yarnpkg/plugin-node-modules"
19+
- "@yarnpkg/plugin-npm"
20+
- "@yarnpkg/plugin-npm-cli"
21+
- "@yarnpkg/plugin-pack"
22+
- "@yarnpkg/plugin-patch"
23+
- "@yarnpkg/plugin-pnp"
24+
- "@yarnpkg/plugin-stage"
25+
- "@yarnpkg/plugin-typescript"
26+
- "@yarnpkg/plugin-version"
27+
- "@yarnpkg/plugin-workspace-tools"
28+
- "@yarnpkg/core"
29+
- "@yarnpkg/builder"
30+
- "@yarnpkg/doctor"
31+
- "@yarnpkg/pnpify"
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
const {npath} = require('@yarnpkg/fslib');
1+
const {npath} = require(`@yarnpkg/fslib`);
22

33
module.exports = npath.toPortablePath(__dirname);

packages/plugin-github/sources/githubUtils.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import querystring from 'querystring';
2+
13
type ParsedGithubUrl = {
24
auth?: string;
35
username: string;
@@ -35,7 +37,17 @@ export function parseGithubUrl(urlStr: string): ParsedGithubUrl {
3537

3638
let [, auth, username, reponame, treeish = `master`] = match;
3739

38-
treeish = treeish.replace(/[^:]*:/, ``);
40+
const {commit} = querystring.parse(treeish) as {commit?: string};
41+
42+
treeish =
43+
// New style:
44+
// The URLs have already been normalized by `gitUtils.resolveUrl`,
45+
// so it's certain in the context of the `GithubFetcher`
46+
// that the `commit` querystring parameter exists
47+
commit
48+
// Old style:
49+
// Shouldn't ever be needed by the GithubFetcher
50+
|| treeish.replace(/[^:]*:/, ``);
3951

4052
return {auth, username, reponame, treeish};
4153
}

packages/plugin-github/tests/githubUtils.test.ts

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ const validScenarios = [{
2121
}, {
2222
url: `https://github.com/owner/repo.git#abcdef`,
2323
auth: undefined, username: `owner`, reponame: `repo`, treeish: `abcdef`,
24+
}, {
25+
url: `https://github.com/owner/repo.git#commit=abcdef`,
26+
auth: undefined, username: `owner`, reponame: `repo`, treeish: `abcdef`,
27+
}, {
28+
url: `https://github.com/owner/repo.git#commit=abcdef&workspace=foobar`,
29+
auth: undefined, username: `owner`, reponame: `repo`, treeish: `abcdef`,
2430
}];
2531

2632
const invalidScenarios = [{

0 commit comments

Comments
 (0)