Github data connector improvements (#2439)
* fix tree/blob github urls from branches not being loaded * improve ux of github data connector * lint * patch Github URL parser to just validate with `URL` native parser * uncheck LocalStorage of PAT for security reasons --------- Co-authored-by: Timothy Carambat <rambat1010@gmail.com>
This commit is contained in:
parent
c734742189
commit
0074ededdd
@ -29,20 +29,36 @@ class GitHubRepoLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#validGithubUrl() {
|
#validGithubUrl() {
|
||||||
const UrlPattern = require("url-pattern");
|
try {
|
||||||
const pattern = new UrlPattern(
|
const url = new URL(this.repo);
|
||||||
"https\\://github.com/(:author)/(:project(*))",
|
|
||||||
{
|
|
||||||
// fixes project names with special characters (.github)
|
|
||||||
segmentValueCharset: "a-zA-Z0-9-._~%/+",
|
|
||||||
}
|
|
||||||
);
|
|
||||||
const match = pattern.match(this.repo);
|
|
||||||
if (!match) return false;
|
|
||||||
|
|
||||||
this.author = match.author;
|
// Not a github url at all.
|
||||||
this.project = match.project;
|
if (url.hostname !== "github.com") {
|
||||||
return true;
|
console.log(
|
||||||
|
`[Github Loader]: Invalid Github URL provided! Hostname must be 'github.com'. Got ${url.hostname}`
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assume the url is in the format of github.com/{author}/{project}
|
||||||
|
// Remove the first slash from the pathname so we can split it properly.
|
||||||
|
const [author, project, ..._rest] = url.pathname.slice(1).split("/");
|
||||||
|
if (!author || !project) {
|
||||||
|
console.log(
|
||||||
|
`[Github Loader]: Invalid Github URL provided! URL must be in the format of 'github.com/{author}/{project}'. Got ${url.pathname}`
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.author = author;
|
||||||
|
this.project = project;
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
console.log(
|
||||||
|
`[Github Loader]: Invalid Github URL provided! Error: ${e.message}`
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure the branch provided actually exists
|
// Ensure the branch provided actually exists
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user