Skip to content

Commit

Permalink
feat: add gh username and token env aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Jun 21, 2022
1 parent 8fd7d62 commit 892bfdc
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/main/js/publish.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import {formatTag, getLatestTag} from './tag.js'
import {tempy, ctx, fs, path, $} from 'zx-extra'
import {tempy, ctx, fs, path} from 'zx-extra'
import {copydir} from 'git-glob-cp'

const branches = {}
const META_VERSION = '1'

export const getOrigin = (cwd) => ctx(async ($) => {
$.cwd = cwd
const gitAuth = `${$.env.GH_USER}:${$.env.GITHUB_TOKEN || $.env.GH_TOKEN}`
const {GH_USER, GH_USERNAME, GITHUB_USER, GITHUB_USERNAME, GH_TOKEN, GITHUB_TOKEN} = $.env
const username = GH_USER || GITHUB_USER || GH_USERNAME || GITHUB_USERNAME
const token = GH_TOKEN || GITHUB_TOKEN
const originUrl = (await $`git config --get remote.origin.url`).toString().trim()
const [,,repoHost, repoName] = originUrl.replace(':', '/').replace(/\.git/, '').match(/.+(@|\/\/)([^/]+)\/(.+)$/) || []

return repoHost && $.env.GH_USER?
`https://${gitAuth}@${repoHost}/${repoName}`
return token && username && repoHost && repoName?
`https://${username}:${token}@${repoHost}/${repoName}`
: originUrl
})

Expand Down Expand Up @@ -121,4 +123,4 @@ export const getLatest = async (cwd, name) => {
tag,
meta
}
}
}

0 comments on commit 892bfdc

Please sign in to comment.