Skip to content

Commit

Permalink
Add info about wether repo should be urlencoded or not
Browse files Browse the repository at this point in the history
  • Loading branch information
yuvipanda committed Dec 12, 2024
1 parent 78bcdbf commit 771b52b
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 8 deletions.
24 changes: 18 additions & 6 deletions binderhub/repoproviders.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,7 @@ class FakeProvider(RepoProvider):
"id": "fake",
"enabled": False,
"spec": {"validateRegex": ".*"},
"repo": {
"label": "Fake Repo",
"placeholder": "",
},
"repo": {"label": "Fake Repo", "placeholder": "", "urlEncode": False},
"ref": {
"enabled": False,
},
Expand Down Expand Up @@ -267,6 +264,7 @@ class ZenodoProvider(RepoProvider):
"repo": {
"label": "Zenodo DOI",
"placeholder": "example: 10.5281/zenodo.3242074",
"urlEncode": False,
},
"ref": {"enabled": False},
}
Expand Down Expand Up @@ -320,6 +318,7 @@ class FigshareProvider(RepoProvider):
"repo": {
"label": "FigShare DOI",
"placeholder": "example: 10.6084/m9.figshare.9782777.v1",
"urlEncode": False,
},
"ref": {"enabled": False},
}
Expand Down Expand Up @@ -375,6 +374,7 @@ class DataverseProvider(RepoProvider):
"repo": {
"label": "Dataverse DOI",
"placeholder": "example: 10.7910/DVN/TJCLKP",
"urlEncode": False,
},
"ref": {"enabled": False},
}
Expand Down Expand Up @@ -443,7 +443,11 @@ class HydroshareProvider(RepoProvider):
"displayName": "Hydroshare resource",
"id": "hydroshare",
"spec": {"validateRegex": r"[^/]+"},
"repo": {"label": "Hydroshare resource id or URL", "placeholder": ""},
"repo": {
"label": "Hydroshare resource id or URL",
"placeholder": "",
"urlEncode": True,
},
"ref": {"enabled": False},
}

Expand Down Expand Up @@ -513,6 +517,7 @@ class CKANProvider(RepoProvider):
"repo": {
"label": "CKAN dataset URL",
"placeholder": "https://demo.ckan.org/dataset/sample-dataset-1",
"urlEncode": True,
},
"ref": {"enabled": False},
}
Expand Down Expand Up @@ -614,6 +619,7 @@ class GitRepoProvider(RepoProvider):
"repo": {
"label": "Arbitrary git repository URL",
"placeholder": "example: http://git.example.com/repo",
"urlEncode": True,
},
"ref": {"enabled": True, "default": "HEAD"},
}
Expand Down Expand Up @@ -723,6 +729,7 @@ class GitLabRepoProvider(RepoProvider):
"repo": {
"label": "GitLab repository name or URL",
"placeholder": "example: https://gitlab.com/mosaik/examples/mosaik-tutorials-on-binder or mosaik/examples/mosaik-tutorials-on-binder",
"urlEncode": True,
},
"ref": {"enabled": True, "default": "HEAD"},
}
Expand Down Expand Up @@ -851,6 +858,7 @@ class GitHubRepoProvider(RepoProvider):
"repo": {
"label": "GitHub repository name or URL",
"placeholder": "example: yuvipanda/requirements or https://github.com/yuvipanda/requirements",
"urlEncode": False,
},
"ref": {"enabled": True, "default": "HEAD"},
}
Expand Down Expand Up @@ -1124,7 +1132,11 @@ class GistRepoProvider(GitHubRepoProvider):
"id": "gist",
"spec": {"validateRegex": r".+/.+(/.+)"},
"detect": {"regex": "^(https?://gist.github.com/)?(?<repo>.*)"},
"repo": {"label": "Gist ID (username/gistId) or URL", "placeholder": ""},
"repo": {
"label": "Gist ID (username/gistId) or URL",
"placeholder": "",
"urlEncode": False,
},
"ref": {"enabled": True, "default": "HEAD"},
}

Expand Down
1 change: 1 addition & 0 deletions binderhub/static/js/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const PAGE_CONFIG = window.pageConfig;
* @typedef {object} RepoConfig
* @prop {string} label
* @prop {string} placeholder
* @prop {boolean} urlEncode
*
* @typedef {object} DetectConfig
* @prop {string} regex
Expand Down
12 changes: 11 additions & 1 deletion binderhub/static/js/components/LinkGenerator.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,18 @@ function UrlSelector({ setUrlPath }) {
);
}

/**
*
* @param {URL} publicBaseUrl
* @param {import("../App").Provider} provider
* @param {string} repo
* @param {string} ref
* @param {string} urlPath
* @returns
*/
function makeShareableUrl(publicBaseUrl, provider, repo, ref, urlPath) {
const url = new URL(`v2/${provider.id}/${repo}/${ref}`, publicBaseUrl);
const encodedRepo = provider.repo.urlEncode ? encodeURIComponent(repo) : repo;
const url = new URL(`v2/${provider.id}/${encodedRepo}/${ref}`, publicBaseUrl);
if (urlPath) {
url.searchParams.set("urlpath", urlPath);
}
Expand Down
5 changes: 4 additions & 1 deletion binderhub/static/js/pages/HomePage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ export function HomePage({ providers, publicBaseUrl, baseUrl }) {
const [progressState, setProgressState] = useState(null);

useEffect(() => {
const encodedRepo = selectedProvider.repo.urlEncode
? encodeURIComponent(repo)
: repo;
let actualRef = "";
if (selectedProvider.ref.enabled) {
actualRef = ref !== "" ? ref : selectedProvider.ref.default;
}
setSpec(
new Spec(
`${selectedProvider.id}/${repo}/${actualRef}`,
`${selectedProvider.id}/${encodedRepo}/${actualRef}`,
new LaunchSpec(urlPath),
),
);
Expand Down
1 change: 1 addition & 0 deletions binderhub/static/js/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export class Spec {
*/
constructor(buildSpec, launchSpec) {
this.buildSpec = buildSpec;
console.log(`spec is ${this.buildSpec}`);
this.launchSpec = launchSpec;
}
}

0 comments on commit 771b52b

Please sign in to comment.