Skip to content

Commit

Permalink
Merge pull request #19 from harmti/extended_gh2ch
Browse files Browse the repository at this point in the history
 extended support for importing issues from GitHub to Clubhouse
  • Loading branch information
harmti committed Oct 18, 2018
2 parents 7329e83 + f39a7bc commit cae1864
Show file tree
Hide file tree
Showing 22 changed files with 365 additions and 10,278 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -3,3 +3,6 @@
.nyc_output
coverage
node_modules
lib/
*¯
*.*~
77 changes: 47 additions & 30 deletions README.md
Expand Up @@ -12,42 +12,59 @@ This module functions both as a library as well as a command-line tool.
## Getting Started

1. Install the module in your project, or globally:

$ npm install --save github-clubhouse
$ # ... OR ...
$ npm install -g github-clubhouse
```
$ npm install --save github-clubhouse
$ # ... OR ...
$ npm install -g github-clubhouse
```

## Using the Command-line Interface (CLI)

1. Learn about how to use the CLI:

$ gh2ch --help
Usage:
gh2ch GITHUB_ISSUE_URL CLUBHOUSE_PROJECT_NAME

Options:
-h, --help display this help message
-s, --save-config save configuration into ~/.github-clubhouse
--github-token=TOKEN your GitHub API token
--clubhouse-token=TOKEN your Clubhouse API token

$ ch2gh --help
Usage:
ch2gh CLUBHOUSE_STORY_NUMBER GITHUB_REPO_URL

Options:
-h, --help display this help message
-s, --save-config save configuration into ~/.github-clubhouse
--github-token=TOKEN your GitHub API token
--clubhouse-token=TOKEN your Clubhouse API token

2. Import an issue from GitHub into Clubhouse:
```
Usage:
gh2ch.js [OPTIONS]
Options:
-h, --help display this help message
-n, --dry-run test run, do not import
-s, --save-config save configuration into ~/.github-clubhouse
--issue=NUMBER GitHub issue number
--query=QUERY GitHub issue query
e.g. "state:closed created:>2017"
--github-token=TOKEN your GitHub API token
--clubhouse-token=TOKEN your Clubhouse API token
--github-project=REPO/PROJECT your GitHub repo/project name
--clubhouse-project=PROJECT your Clubhouse project name
--user-map=JSON-USER_MAP json object of gh-user:clubhouse-user mappings
use "*" for default
e.g. '{"my_gh_id":"my_ch_id", "*":"default_id"}'
$ ch2gh --help
Usage:
ch2gh CLUBHOUSE_STORY_NUMBER GITHUB_REPO_URL
Options:
-h, --help display this help message
-s, --save-config save configuration into ~/.github-clubhouse
--github-token=TOKEN your GitHub API token
--clubhouse-token=TOKEN your Clubhouse API token
```

$ gh2ch --save-config --github-token <GH-TOKEN> --clubhouse-token <CH-TOKEN> https://github.com/myorg/myrepo/issues/1 myproject
2. Import from GitHub into Clubhouse:
```
# a single issue
$ gh2ch.js --github-project <owner>/<repo> --clubhouse-project testing --issue 2950
#
# multiple issues
$ gh2ch.js --github-project <owner>/<repo> --clubhouse-project testing --query "state:open label:bug"
```

3. Export a story from Clubhouse to GitHub:

$ ch2ch --save-config --github-token <GH-TOKEN> --clubhouse-token <CH-TOKEN> 234 https://github.com/myorg/myrepo
```
$ ch2gh --save-config --github-token <GH-TOKEN> --clubhouse-token <CH-TOKEN> 234 https://github.com/myorg/myrepo
```

### Configuration

Expand All @@ -70,11 +87,11 @@ The library exports:

**Parameters:**

- `githubIssueURL` **(String)**: the GitHub issue URL
- `clubhouseProject` **(String)**: the Clubhouse project name into which to import the issue
- `options` **(Object)**:
- `githubToken` **(String)**: the GitHub API token
- `clubhouseToken` **(String)**: the Clubhouse API token
- `githubRepo` **(String)**: the GitHub repository (owner/repo)
- `clubhouseProject` **(String)**: the Clubhouse project name into which to import the issue

### `clubhouseStoryToGithubIssue`

Expand Down
55 changes: 37 additions & 18 deletions bin/gh2ch.js
Expand Up @@ -2,6 +2,7 @@

var path = require('path')
var parseArgs = require('minimist')
var camelcaseObject = require('camelcase-object');

var ghCh
try {
Expand All @@ -16,26 +17,38 @@ var githubIssueToClubhouseStory = ghCh.githubIssueToClubhouseStory

function run() {
var args = parseArgs(process.argv.slice(2), {
string: ['github-token', 'clubhouse-token'],
boolean: ['s', 'h'],
string: ['github-token', 'clubhouse-token', 'github-repo', 'clubhouse-project', 'user-map', 'issue', 'query'],
boolean: ['s', 'h', 'n'],
alias: {
h: 'help',
s: 'save-config',
n: 'dry-run',
u: 'user-map',
},
})
//console.log(args)

if (args.h) {
console.info(_usage())
return process.exit(0)
}
if (args._.length !== 2) {
return _die('GITHUB_ISSUE_URL and CLUBHOUSE_PROJECT_NAME are both required.')
if (args._.length > 0) {
return _die('Syntax error, run --help for usage')
}

if (!(('issue' in args) != ('query' in args))) {
return _die('Use --issue or --query, run --help for usage')
}

if (!('user-map' in args))
args['user-map'] = "{}"

var options = _loadAndOrSaveOptions(args)
//console.log(options)

githubIssueToClubhouseStory(args._[0], args._[1], options)
.then(function(story) {
console.info('Created story with ID:', story.id)
githubIssueToClubhouseStory(options)
.then(function(count) {
console.info(`\nImported ${count} stories`)
})
.catch(function(err) {
console.error(err)
Expand All @@ -50,23 +63,29 @@ function _die(message) {

function _usage() {
return 'Usage:\n' +
' ' + path.basename(process.argv[1]) + ' GITHUB_ISSUE_URL CLUBHOUSE_PROJECT_NAME\n' +
' ' + path.basename(process.argv[1]) + ' [OPTIONS]\n' +
'\n' +
'Options:\n' +
' -h, --help display this help message\n' +
' -s, --save-config save configuration into ~/.github-clubhouse\n' +
' --github-token=TOKEN your GitHub API token\n' +
' --clubhouse-token=TOKEN your Clubhouse API token'
' -h, --help display this help message\n' +
' -n, --dry-run test run, fetch but do not import\n' +
' -s, --save-config save configuration into ~/.github-clubhouse\n' +
' --issue=NUMBER GitHub issue number OR\n' +
' --query=QUERY GitHub issue query (excluding pull requests)\n' +
' e.g. "state:open created:>2017"\n' +
' if empty all issues are imported\n' +
' --github-token=TOKEN your GitHub API token\n' +
' --clubhouse-token=TOKEN your Clubhouse API token\n' +
' --github-repo=OWNER/REPO your GitHub owner/repo\n' +
' --clubhouse-project=PROJECT your Clubhouse project name\n' +
' --user-map=JSON-USER_MAP json object of gh-user:clubhouse-user mappings\n' +
' use "*" for default\n' +
' e.g. \'{"my_gh_id":"my_ch_id", "*":"default_id"}\'\n'
}

function _loadAndOrSaveOptions(args) {
var options = loadConfig()
if (args['github-token']) {
options.githubToken = args['github-token']
}
if (args['clubhouse-token']) {
options.clubhouseToken = args['clubhouse-token']
}
options = Object.assign(options, camelcaseObject(args))
//console.log(options)
if (args.s) {
if (!args['github-token'] || !args['clubhouse-token']) {
return _die('Cannot save configuration unless both `--github-token` and `--clubhouse-token` are provided.')
Expand Down
114 changes: 0 additions & 114 deletions lib/fetchers/__tests__/clubhouse.test.js

This file was deleted.

0 comments on commit cae1864

Please sign in to comment.