mirror of
https://github.com/Mintplex-Labs/anything-llm.git
synced 2025-05-02 09:03:12 +00:00
Apply .git
logic handler for repo URLs (#3655)
* Apply `.git` logic handler for repo URLs * remove comment
This commit is contained in:
parent
713f939ab3
commit
fd174cab86
1 changed files with 31 additions and 1 deletions
|
@ -18,7 +18,7 @@ class GitHubRepoLoader {
|
|||
*/
|
||||
constructor(args = {}) {
|
||||
this.ready = false;
|
||||
this.repo = args?.repo;
|
||||
this.repo = this.#processRepoUrl(args?.repo);
|
||||
this.branch = args?.branch;
|
||||
this.accessToken = args?.accessToken || null;
|
||||
this.ignorePaths = args?.ignorePaths || [];
|
||||
|
@ -28,6 +28,36 @@ class GitHubRepoLoader {
|
|||
this.branches = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes a repository URL to ensure it is in the correct format
|
||||
* - remove the .git suffix if present
|
||||
* - ensure the url is valid
|
||||
* @param {string} repoUrl - The repository URL to process.
|
||||
* @returns {string|null} The processed repository URL, or null if the URL is invalid.
|
||||
*/
|
||||
#processRepoUrl(repoUrl) {
|
||||
if (!repoUrl) return repoUrl;
|
||||
try {
|
||||
const url = new URL(repoUrl);
|
||||
if (url.pathname.endsWith(".git"))
|
||||
url.pathname = url.pathname.slice(0, -4);
|
||||
return url.toString();
|
||||
} catch (e) {
|
||||
console.error(
|
||||
`[GitHub Loader]: Error processing repository URL ${this.repo}: ${e.message}`
|
||||
);
|
||||
return repoUrl;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the GitHub URL format.
|
||||
* - ensure the url is valid
|
||||
* - ensure the hostname is github.com
|
||||
* - ensure the pathname is in the format of github.com/{author}/{project}
|
||||
* - sets the author and project properties of class instance
|
||||
* @returns {boolean} True if the URL is valid, false otherwise.
|
||||
*/
|
||||
#validGithubUrl() {
|
||||
try {
|
||||
const url = new URL(this.repo);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue