Skip to content

Commit

Permalink
refactor: separate git url builder
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Jun 17, 2022
1 parent c65a0de commit 1f07a97
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/main/js/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@ import {copydir} from 'git-glob-cp'

const branches = {}

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

return repoHost ?
`https://${gitAuth}@${repoHost}/${repoName}`
: originUrl
})

export const fetch = async ({cwd: _cwd, branch, origin: _origin}) => ctx(async ($) => {
let cwd = branches[branch]
if (cwd) return cwd

$.cwd = _cwd
const origin = _origin || (await $`git remote get-url origin`).toString().trim()
const origin = _origin || await getOrigin(_cwd)

cwd = tempy.temporaryDirectory()
$.cwd = cwd
Expand Down

0 comments on commit 1f07a97

Please sign in to comment.