Skip to content

Commit 82ec5bb

Browse files
authored
Create cli (#19)
* Create cli * Lint
1 parent 89f3f57 commit 82ec5bb

File tree

5 files changed

+234
-14
lines changed

5 files changed

+234
-14
lines changed

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ Create a release pull request and return Promise.
1616
You must pass a config as an argument.
1717

1818
``` javascript
19-
var release = require('github-pr-release')
19+
const release = require('github-pr-release')
2020

21-
var config = {
21+
const config = {
2222
token: 'your github token',
2323
owner: 'uiur',
2424
repo: 'awesome-web-app',
@@ -29,12 +29,20 @@ var config = {
2929

3030
release(config).then(function (pullRequest) {
3131
// success
32+
// `pullRequest` is an object that github api returns.
33+
// See: https://developer.github.com/v3/pulls/#get-a-single-pull-request
3234
})
3335
```
3436

35-
`pullRequest` is an object that github api returns.
37+
Also, the following environment variables can be used for the config:
38+
39+
- `GITHUB_PR_RELEASE_OWNER`
40+
- `GITHUB_PR_RELEASE_REPO`
41+
- `GITHUB_PR_RELEASE_TOKEN`
42+
- `GITHUB_PR_RELEASE_HEAD`
43+
- `GITHUB_PR_RELEASE_BASE`
44+
- `GITHUB_PR_RELEASE_ENDPOINT`
3645

37-
See: https://developer.github.com/v3/pulls/#get-a-single-pull-request
3846

3947
## Install
4048
```

cli/index.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env node
2+
3+
const yargs = require('yargs/yargs')
4+
const { hideBin } = require('yargs/helpers')
5+
const argv = yargs(hideBin(process.argv))
6+
.usage('Usage: $0 [repo]')
7+
.example('$0 uiur/github-pr-release --head master --base production', '')
8+
.demandCommand(1)
9+
.default('head', 'master')
10+
.default('base', 'production')
11+
.argv
12+
13+
const createReleasePR = require('../')
14+
15+
async function main () {
16+
const repoInput = argv._[0]
17+
const [owner, repo] = repoInput.split('/')
18+
const config = {
19+
owner,
20+
repo,
21+
head: argv.head,
22+
base: argv.base
23+
}
24+
25+
const pullRequest = await createReleasePR(config)
26+
27+
console.log(pullRequest.html_url)
28+
}
29+
30+
main().catch(err => {
31+
console.error(err)
32+
process.exit(1)
33+
})

lib/github-client.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
var request = require('request')
2-
var Promise = require('es6-promise').Promise
3-
var parseLinkHeader = require('parse-link-header')
1+
const request = require('request')
2+
const Promise = require('es6-promise').Promise
3+
const parseLinkHeader = require('parse-link-header')
44

55
function GithubClient (config) {
6-
this.owner = config.owner
7-
this.repo = config.repo
8-
this.token = config.token
9-
this.head = config.head || 'master'
10-
this.base = config.base || 'production'
11-
this.endpoint = config.endpoint || 'https://api.github.com'
6+
this.owner = config.owner || process.env.GITHUB_PR_RELEASE_OWNER
7+
this.repo = config.repo || process.env.GITHUB_PR_RELEASE_REPO
8+
this.token = config.token || process.env.GITHUB_PR_RELEASE_TOKEN
9+
this.head = config.head || process.env.GITHUB_PR_RELEASE_HEAD || 'master'
10+
this.base = config.base || process.env.GITHUB_PR_RELEASE_BASE || 'production'
11+
this.endpoint = config.endpoint || process.env.GITHUB_PR_RELEASE_ENDPOINT || 'https://api.github.com'
1212
}
1313

1414
GithubClient.prototype.pullRequestEndpoint = function () {

package-lock.json

Lines changed: 175 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
"version": "1.3.2",
44
"description": "Create a release pull request by Github API",
55
"main": "index.js",
6+
"bin": {
7+
"github-pr-release": "cli/index.js"
8+
},
69
"author": "Kazato Sugimoto",
710
"license": "MIT",
811
"scripts": {
@@ -17,7 +20,8 @@
1720
"moment": "^2.9.0",
1821
"mustache": "^3.0.1",
1922
"parse-link-header": "^0.2.0",
20-
"request": "^2.58.0"
23+
"request": "^2.58.0",
24+
"yargs": "^17.3.1"
2125
},
2226
"devDependencies": {
2327
"espower-loader": "^1.2.2",

0 commit comments

Comments
 (0)