glu-cli
Version:
Git stacked branch management with GitHub integration
30 lines • 1.23 kB
JavaScript
// TODO: Allow custom Git URL from config
export function buildPullRequestUrl(remoteUrl, branch) {
// GitHub (SSH)
let match = remoteUrl.match(/git@github\.com:(.+?)\/(.+?)(\.git)?$/);
if (match) {
const [, owner, repo] = match;
return `https://github.com/${owner}/${repo}/pull/new/${branch}`;
}
// GitHub (HTTPS)
match = remoteUrl.match(/https:\/\/github\.com\/(.+?)\/(.+?)(\.git)?$/);
if (match) {
const [, owner, repo] = match;
return `https://github.com/${owner}/${repo}/pull/new/${branch}`;
}
// GitLab
match = remoteUrl.match(/(?:git@|https:\/\/)gitlab\.com[:/](.+?)\/(.+?)(\.git)?$/);
if (match) {
const [, owner, repo] = match;
const encodedBranch = encodeURIComponent(branch);
return `https://gitlab.com/${owner}/${repo}/-/merge_requests/new?merge_request[source_branch]=${encodedBranch}`;
}
// Bitbucket
match = remoteUrl.match(/(?:git@|https:\/\/)bitbucket\.org[:/](.+?)\/(.+?)(\.git)?$/);
if (match) {
const [, owner, repo] = match;
return `https://bitbucket.org/${owner}/${repo}/pull-requests/new?source=${branch}`;
}
return null;
}
//# sourceMappingURL=pr-url-builder.js.map