diff --git a/src/release/configure-origin.ts b/src/release/configure-origin.ts index eb15c28..ea6b087 100644 --- a/src/release/configure-origin.ts +++ b/src/release/configure-origin.ts @@ -1,26 +1,23 @@ export const configureOrigin = async (git: any) => { - if (process.env.GITHUB_TOKEN) { - // This doesn't work- it's possible the checkout command needs to use the - // github token (in the workflow yaml) - const remote_url = await git.remote(["get-url", "origin"]) + const token = process.env.PVER_GITHUB_TOKEN || process.env.GITHUB_TOKEN + if (!token) return - // if the remote is in the form of git@github.com:foo/bar.git, convert it to - // https://github.com/foo/bar.git - if (remote_url.includes("git@")) { - const new_url = remote_url!.replace("git@", "https://") - await git.removeRemote("origin") - await git.addRemote("origin", new_url) - } + let remote_url = (await git.remote(["get-url", "origin"])) as string - if (!remote_url.includes("oauth2:")) { - const new_url = remote_url! - .replace( - "https://", - `https://oauth2:${process.env.GITHUB_TOKEN.trim()}@` - ) - .replace(/\n/g, "") - await git.removeRemote("origin") - await git.addRemote("origin", new_url) - } + if (remote_url?.includes("git@")) { + remote_url = remote_url + .replace("git@github.com:", "https://github.com/") + .replace("git@", "https://") + await git.removeRemote("origin") + await git.addRemote("origin", remote_url) + } + + if (!remote_url?.includes("oauth2:")) { + const new_url = remote_url.replace( + "https://", + `https://oauth2:${encodeURIComponent(token.trim())}@` + ) + await git.removeRemote("origin") + await git.addRemote("origin", new_url) } }