Skip to content

Commit

Permalink
feat(plugin-git): add support for github tarball urls (#1321)
Browse files Browse the repository at this point in the history
* feat(plugin-git): add support for github tarball urls

Fixes #885.

* chore(release-workflow): set releases

* test(plugin-git): add tarball pattern and update snapshots
  • Loading branch information
paul-soporan authored May 11, 2020
1 parent b1d046b commit 563abf8
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 10 deletions.
31 changes: 31 additions & 0 deletions .yarn/versions/f239bb28.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
releases:
"@yarnpkg/plugin-git": prerelease
"@yarnpkg/cli": prerelease

declined:
- "@yarnpkg/plugin-compat"
- "@yarnpkg/plugin-constraints"
- "@yarnpkg/plugin-dlx"
- "@yarnpkg/plugin-essentials"
- "@yarnpkg/plugin-exec"
- "@yarnpkg/plugin-file"
- "@yarnpkg/plugin-git"
- "@yarnpkg/plugin-github"
- "@yarnpkg/plugin-http"
- "@yarnpkg/plugin-init"
- "@yarnpkg/plugin-interactive-tools"
- "@yarnpkg/plugin-link"
- "@yarnpkg/plugin-node-modules"
- "@yarnpkg/plugin-npm"
- "@yarnpkg/plugin-npm-cli"
- "@yarnpkg/plugin-pack"
- "@yarnpkg/plugin-patch"
- "@yarnpkg/plugin-pnp"
- "@yarnpkg/plugin-stage"
- "@yarnpkg/plugin-typescript"
- "@yarnpkg/plugin-version"
- "@yarnpkg/plugin-workspace-tools"
- "@yarnpkg/core"
- "@yarnpkg/builder"
- "@yarnpkg/doctor"
- "@yarnpkg/pnpify"
33 changes: 23 additions & 10 deletions packages/plugin-git/sources/__snapshots__/gitUtils.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ exports[`gitUtils should properly normalize https://github.com/TooTallNate/util-

exports[`gitUtils should properly normalize https://github.com/TooTallNate/util-deprecate.git#v1.0.0 1`] = `"https://github.com/TooTallNate/util-deprecate.git#v1.0.0"`;

exports[`gitUtils should properly normalize https://github.com/TooTallNate/util-deprecate/tarball/b3562c2798507869edb767da869cd7b85487726d 1`] = `"https://github.com/TooTallNate/util-deprecate.git#b3562c2798507869edb767da869cd7b85487726d"`;

exports[`gitUtils should properly normalize ssh://[email protected]/TooTallNate/util-deprecate.git#v1.0.1 1`] = `"ssh://[email protected]/TooTallNate/util-deprecate.git#v1.0.1"`;

exports[`gitUtils should properly split GitHubOrg/foo-bar.js 1`] = `
Object {
"extra": Object {},
"repo": "GitHubOrg/foo-bar.js",
"repo": "https://github.com/GitHubOrg/foo-bar.js.git",
"treeish": Object {
"protocol": "head",
"request": "master",
Expand All @@ -48,7 +50,7 @@ Object {
exports[`gitUtils should properly split GitHubOrg/foo-bar.js#commit:hash 1`] = `
Object {
"extra": Object {},
"repo": "GitHubOrg/foo-bar.js",
"repo": "https://github.com/GitHubOrg/foo-bar.js.git",
"treeish": Object {
"protocol": "commit",
"request": "hash",
Expand All @@ -59,7 +61,7 @@ Object {
exports[`gitUtils should properly split GitHubOrg/foo-bar.js#commit=hash 1`] = `
Object {
"extra": Object {},
"repo": "GitHubOrg/foo-bar.js",
"repo": "https://github.com/GitHubOrg/foo-bar.js.git",
"treeish": Object {
"protocol": "commit",
"request": "hash",
Expand All @@ -72,7 +74,7 @@ Object {
"extra": Object {
"workspace": "foo",
},
"repo": "GitHubOrg/foo-bar.js",
"repo": "https://github.com/GitHubOrg/foo-bar.js.git",
"treeish": Object {
"protocol": "commit",
"request": "hash",
Expand All @@ -83,7 +85,7 @@ Object {
exports[`gitUtils should properly split GitHubOrg/foo-bar.js#hash 1`] = `
Object {
"extra": Object {},
"repo": "GitHubOrg/foo-bar.js",
"repo": "https://github.com/GitHubOrg/foo-bar.js.git",
"treeish": Object {
"protocol": null,
"request": "hash",
Expand All @@ -94,7 +96,7 @@ Object {
exports[`gitUtils should properly split GitHubOrg/foo-bar.js#tag=hello 1`] = `
Object {
"extra": Object {},
"repo": "GitHubOrg/foo-bar.js",
"repo": "https://github.com/GitHubOrg/foo-bar.js.git",
"treeish": Object {
"protocol": "tag",
"request": "hello",
Expand All @@ -107,7 +109,7 @@ Object {
"extra": Object {
"workspace": "foo",
},
"repo": "GitHubOrg/foo-bar.js",
"repo": "https://github.com/GitHubOrg/foo-bar.js.git",
"treeish": Object {
"protocol": "head",
"request": "master",
Expand All @@ -118,7 +120,7 @@ Object {
exports[`gitUtils should properly split GitHubOrg/foo2bar.js 1`] = `
Object {
"extra": Object {},
"repo": "GitHubOrg/foo2bar.js",
"repo": "https://github.com/GitHubOrg/foo2bar.js.git",
"treeish": Object {
"protocol": "head",
"request": "master",
Expand Down Expand Up @@ -151,7 +153,7 @@ Object {
exports[`gitUtils should properly split github:GitHubOrg/foo-bar.js 1`] = `
Object {
"extra": Object {},
"repo": "github:GitHubOrg/foo-bar.js",
"repo": "https://github.com/GitHubOrg/foo-bar.js.git",
"treeish": Object {
"protocol": "head",
"request": "master",
Expand All @@ -162,7 +164,7 @@ Object {
exports[`gitUtils should properly split github:GitHubOrg/foo-bar.js#hash 1`] = `
Object {
"extra": Object {},
"repo": "github:GitHubOrg/foo-bar.js",
"repo": "https://github.com/GitHubOrg/foo-bar.js.git",
"treeish": Object {
"protocol": null,
"request": "hash",
Expand Down Expand Up @@ -214,6 +216,17 @@ Object {
}
`;

exports[`gitUtils should properly split https://github.com/TooTallNate/util-deprecate/tarball/b3562c2798507869edb767da869cd7b85487726d 1`] = `
Object {
"extra": Object {},
"repo": "https://github.com/TooTallNate/util-deprecate.git",
"treeish": Object {
"protocol": null,
"request": "b3562c2798507869edb767da869cd7b85487726d",
},
}
`;

exports[`gitUtils should properly split ssh://[email protected]/TooTallNate/util-deprecate.git#v1.0.1 1`] = `
Object {
"extra": Object {},
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-git/sources/gitUtils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const VALID_PATTERNS = [
`https://github.com/TooTallNate/util-deprecate.git#semver:v1.0.0`,
`https://github.com/TooTallNate/util-deprecate.git#master`,
`https://github.com/TooTallNate/util-deprecate.git#b3562c2798507869edb767da869cd7b85487726d`,
`https://github.com/TooTallNate/util-deprecate/tarball/b3562c2798507869edb767da869cd7b85487726d`,
`git://github.com/TooTallNate/util-deprecate.git#v1.0.1`,
`git+ssh://[email protected]/TooTallNate/util-deprecate.git#v1.0.1`,
`ssh://[email protected]/TooTallNate/util-deprecate.git#v1.0.1`,
Expand Down
7 changes: 7 additions & 0 deletions packages/plugin-git/sources/gitUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const gitPatterns = [
/^(?:git\+)?https?:[^#]+\/[^#]+\.git(?:#.*)?$/,
/^git@[^#]+\/[^#]+\.git(?:#.*)?$/,
/^(?:github:|https:\/\/github\.com\/)?(?!\.{1,2}\/)([a-zA-Z._0-9-]+)\/(?!\.{1,2}(?:#|$))([a-zA-Z._0-9-]+?)(?:\.git)?(?:#.*)?$/,
// GitHub `/tarball/` URLs
/^https:\/\/github\.com\/(?!\.{1,2}\/)([a-zA-Z0-9._-]+)\/(?!\.{1,2}(?:#|$))([a-zA-Z0-9._-]+?)\/tarball\/(.+)?$/,
];

export enum TreeishProtocols {
Expand Down Expand Up @@ -45,6 +47,8 @@ export type RepoUrlParts = {
};

export function splitRepoUrl(url: string): RepoUrlParts {
url = normalizeRepoUrl(url);

const hashIndex = url.indexOf(`#`);
if (hashIndex === -1) {
return {
Expand Down Expand Up @@ -126,6 +130,9 @@ export function normalizeRepoUrl(url: string) {
// We support this as an alias to GitHub repositories
url = url.replace(/^(?:github:|https:\/\/github\.com\/)?(?!\.{1,2}\/)([a-zA-Z0-9._-]+)\/(?!\.{1,2}(?:#|$))([a-zA-Z0-9._-]+?)(?:\.git)?(#.*)?$/, `https://github.com/$1/$2.git$3`);

// We support GitHub `/tarball/` URLs
url = url.replace(/^https:\/\/github\.com\/(?!\.{1,2}\/)([a-zA-Z0-9._-]+)\/(?!\.{1,2}(?:#|$))([a-zA-Z0-9._-]+?)\/tarball\/(.+)?$/, `https://github.com/$1/$2.git#$3`);

return url;
}

Expand Down

0 comments on commit 563abf8

Please sign in to comment.