Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 18 additions & 21 deletions src/release/configure-origin.ts
Original file line number Diff line number Diff line change
@@ -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)
}
}