chore: refactor contribute script (#5985)

This commit is contained in:
Aaron 2024-07-04 16:51:12 +08:00 committed by GitHub
parent 8160df7201
commit aa51954a7b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -30,12 +30,13 @@ function checkStagingArea() {
}
function parseGithubUrl(url) {
const regex = /https:\/\/github\.com\/([^/]+)\/([^/]+)\/tree\/([^/]+)\/(.+)/;
const regex = /https:\/\/github\.com\/([^/]+)\/([^/]+)\/tree\/([^/]+)(\/(.+))*/;
const match = url.match(regex);
if (!match) {
throw new Error('无法解析 GitHub URL');
}
return { username: match[1], repository: match[2], branch: match[3] + '/' + match[4] };
const [, username, repository, ...branch] = match;
return { username, repository, branch: branch.filter(Boolean).join('/') };
}
function addRemoteAndCheckoutBranch(username, branch) {