-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Release: v0.11.0
- Loading branch information
Showing
15 changed files
with
206 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import refs, { getRefs, postRefs } from './refs' | ||
|
||
export { | ||
refs, | ||
getRefs, | ||
postRefs | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { exec } from '@cp' | ||
import log, { c } from '@clog' | ||
import { Options } from './types' | ||
|
||
const deleteRefs = async (owner: string, repo: string, branch: string, { | ||
verbose | ||
}: Options = {}) => new Promise<string>((resolve, reject) => { | ||
try { | ||
const args = ['api'] | ||
|
||
args.push('--method DELETE') | ||
args.push('-H "Accept: application/vnd.github.v3+json"') | ||
args.push(`/repos/${owner}/${repo}/git/refs/heads/${branch}`) | ||
|
||
const cli = ['gh', ...args].join(' ') | ||
|
||
verbose && log(c.blue(`• ${cli}`)) | ||
|
||
exec(cli).then(({ stdall }) => { | ||
verbose && log(c.grey(` branch: ${branch}`)) | ||
resolve(stdall) | ||
}).catch(reject) | ||
} catch (err) { | ||
reject(err) | ||
} | ||
}) | ||
|
||
export default deleteRefs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { exec } from '@cp' | ||
import log, { c } from '@clog' | ||
import { Data, Options } from './types' | ||
|
||
const getRefs = async (owner: string, repo: string, branch: string, { | ||
verbose | ||
}: Options = {}) => new Promise<Data>((resolve, reject) => { | ||
try { | ||
const args = ['api'] | ||
|
||
args.push('--method GET') | ||
args.push('-H "Accept: application/vnd.github.v3+json"') | ||
args.push(`/repos/${owner}/${repo}/git/refs/heads/${branch}`) | ||
|
||
const cli = ['gh', ...args].join(' ') | ||
|
||
verbose && log(c.blue(`• ${cli}`)) | ||
|
||
exec(cli).then(({ stdall }) => { | ||
try { | ||
const data: Data = JSON.parse(stdall) | ||
verbose && log(c.grey(` sha: ${data && data.object && data.object.sha ? data.object.sha : '-'}`)) | ||
resolve(data) | ||
} catch (err) { | ||
reject(err) | ||
} | ||
}).catch(reject) | ||
} catch (err) { | ||
reject(err) | ||
} | ||
}) | ||
|
||
export default getRefs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import getRefs from './getRefs' | ||
import postRefs from './postRefs' | ||
import deleteRefs from './deleteRefs' | ||
import refs from './refs' | ||
|
||
export { | ||
getRefs, | ||
postRefs, | ||
deleteRefs | ||
} | ||
|
||
export default refs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { exec } from '@cp' | ||
import log, { c } from '@clog' | ||
import { Data, Options } from './types' | ||
|
||
const postRefs = async (owner: string, repo: string, sha: string, branch: string, { | ||
verbose | ||
}: Options = {}) => new Promise<Data>((resolve, reject) => { | ||
try { | ||
const args = ['api'] | ||
|
||
args.push('--method POST') | ||
args.push('-H "Accept: application/vnd.github.v3+json"') | ||
args.push(`/repos/${owner}/${repo}/git/refs`) | ||
args.push(`-f ref="refs/heads/${branch}"`) | ||
args.push(`-f sha="${sha}"`) | ||
|
||
const cli = ['gh', ...args].join(' ') | ||
|
||
verbose && log(c.blue(`• ${cli}`)) | ||
|
||
exec(cli).then(({ stdall }) => { | ||
try { | ||
const data: Data = JSON.parse(stdall) | ||
verbose && log(c.grey(` sha: ${data && data.object && data.object.sha ? data.object.sha : '-'}, branch: ${branch}`)) | ||
resolve(data) | ||
} catch (err) { | ||
reject(err) | ||
} | ||
}).catch(reject) | ||
} catch (err) { | ||
reject(err) | ||
} | ||
}) | ||
|
||
export default postRefs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import getRefs from './getRefs' | ||
import postRefs from './postRefs' | ||
import deleteRefs from './deleteRefs' | ||
import { RefsProps, Options } from './types' | ||
|
||
const refs = async ({ owner, repo }: RefsProps) => { | ||
const get = async (branch: string, opt: Options) => await getRefs(owner, repo, branch, opt) | ||
const post = async (sha: string, branch: string, opt: Options) => await postRefs(owner, repo, sha, branch, opt) | ||
const del = async (branch: string, opt: Options) => await deleteRefs(owner, repo, branch, opt) | ||
|
||
return { | ||
get, | ||
post, | ||
delete: del | ||
} | ||
} | ||
|
||
export default refs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
type Object = { | ||
sha: string, | ||
type: string, | ||
url: string | ||
} | ||
|
||
export type Data = { | ||
ref: string, | ||
node_id: string, | ||
url: string, | ||
object: Object, | ||
} | ||
|
||
export type RefsProps = { | ||
owner: string, | ||
repo: string | ||
} | ||
|
||
export type Options = { | ||
verbose?: boolean, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import ghVersion from './ghVersion' | ||
import ghAuthStatus from './ghAuthStatus' | ||
import ghRepoCreate from './ghRepoCreate' | ||
import * as ghAPIs from './ghAPIs' | ||
|
||
export { | ||
ghVersion, | ||
ghAuthStatus, | ||
ghRepoCreate | ||
ghRepoCreate, | ||
ghAPIs | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { exec } from '@cp' | ||
import log, { c } from '@clog' | ||
import { Options } from './types' | ||
|
||
const gitCheckout = async (branch: string, { | ||
verbose | ||
}: Options = {}) => { | ||
const cmd = `git checkout ${branch}` | ||
|
||
verbose && log(c.blue(`• ${cmd}`)) | ||
|
||
const { stdall } = await exec(cmd) | ||
|
||
if (stdall.includes('command not found')) { | ||
log(c.red(`You don't have ${c.bold('Git')}.`)) | ||
log(c.red(`Please follow ${c.underline('https://git-scm.com/downloads')} to install ${c.bold('git')} command line.`)) | ||
process.exit() | ||
} | ||
|
||
verbose && log(c.grey(` ${stdall}`)) | ||
|
||
return stdall | ||
} | ||
|
||
export default gitCheckout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import gitCheckout from './gitCheckout' | ||
|
||
export default gitCheckout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export type Options = { | ||
verbose?: boolean, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import gitVersion from './gitVersion' | ||
import gitClone from './gitClone' | ||
import gitCheckout from './gitCheckout' | ||
|
||
export { | ||
gitVersion, | ||
gitClone | ||
gitClone, | ||
gitCheckout | ||
} |