Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
azu committed Mar 5, 2017
0 parents commit a100bfe
Show file tree
Hide file tree
Showing 12 changed files with 2,627 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .babelrc
@@ -0,0 +1,13 @@
{
"presets": [
"latest"
],
"env": {
"development": {
"presets": [
"jsdoc-to-assert",
"power-assert"
]
}
}
}
88 changes: 88 additions & 0 deletions .gitignore
@@ -0,0 +1,88 @@
### https://raw.github.com/github/gitignore/608690d6b9a78c2a003affc792e49a84905b3118/Node.gitignore

# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
node_modules

# Debug log from npm
npm-debug.log


### https://raw.github.com/github/gitignore/608690d6b9a78c2a003affc792e49a84905b3118/Global/JetBrains.gitignore

# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm

*.iml

## Directory-based project format:
.idea/
# if you remove the above rule, at least ignore the following:

# User-specific stuff:
# .idea/workspace.xml
# .idea/tasks.xml
# .idea/dictionaries

# Sensitive or high-churn files:
# .idea/dataSources.ids
# .idea/dataSources.xml
# .idea/sqlDataSources.xml
# .idea/dynamic.xml
# .idea/uiDesigner.xml

# Gradle:
# .idea/gradle.xml
# .idea/libraries

# Mongo Explorer plugin:
# .idea/mongoSettings.xml

## File-based project format:
*.ipr
*.iws

## Plugin-specific files:

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties


/lib
/example.js
/example.sh
/lib/
3 changes: 3 additions & 0 deletions .travis.yml
@@ -0,0 +1,3 @@
sudo: false
language: node_js
node_js: "stable"
19 changes: 19 additions & 0 deletions LICENSE
@@ -0,0 +1,19 @@
Copyright (c) 2017 azu

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
60 changes: 60 additions & 0 deletions README.md
@@ -0,0 +1,60 @@
# get-github-pr-review-comments

Get PR review comments.

## Install

Install with [npm](https://www.npmjs.com/):

npm install get-github-pr-review-comments

## Usage

Usage
$ get-github-pr-review-comments --repo owner/repo --projectRoot /path/to/project --token <GitHubToken> <sha>

Options
--repo owner/repo
e.g.) azu/get-github-pr-review-comments
--projectRoot -p /path/to/root-project
e.g.) /Users/azu/get-github-pr-review-comments
--token GitHub Token
Get from https://github.com/settings/tokens/new
or
export GH_TOKEN=XXX
Example:
get-github-pr-review-comments --repo azu/get-github-pr-review-comments --projectRoot /path/to/get-github-pr-review-comments --token xxx \`git rev-parse HEAD\`



## Changelog

See [Releases page](https://github.com/azu/get-github-pr-review-comments/releases).

## Running tests

Install devDependencies and Run `npm test`:

npm i -d && npm test

## Contributing

Pull requests and stars are always welcome.

For bugs and feature requests, [please create an issue](https://github.com/azu/get-github-pr-review-comments/issues).

1. Fork it!
2. Create your feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request :D

## Author

- [github/azu](https://github.com/azu)
- [twitter/azu_re](https://twitter.com/azu_re)

## License

MIT © azu
40 changes: 40 additions & 0 deletions bin/cmd.js
@@ -0,0 +1,40 @@
#!/usr/bin/env node
'use strict';
const meow = require('meow');
const run = require("../lib/cli");

const cli = meow(`
Usage
$ get-github-pr-review-comments --repo owner/repo --projectRoot /path/to/project --token <GitHubToken> <sha>
Options
--repo owner/repo
e.g.) azu/get-github-pr-review-comments
--projectRoot -p /path/to/root-project
e.g.) /Users/azu/get-github-pr-review-comments
--token GitHub Token
Get from https://github.com/settings/tokens/new
or
export GH_TOKEN=XXX
Example:
get-github-pr-review-comments --repo azu/get-github-pr-review-comments --projectRoot /path/to/get-github-pr-review-comments --token xxx \`git rev-parse HEAD\`
`, {
alias: {
p: 'projectRoot'
}
});
/*
{
input: ['2101f5606f2c594f4e8d8262a0c7c99b9679f2f9'],
flags: {rainbow: true},
...
}
*/

run(cli.input[0], cli.flags).then(function(result) {
console.log(result);
}).catch(function(error) {
console.error(error.message, error.stack);
});
46 changes: 46 additions & 0 deletions package.json
@@ -0,0 +1,46 @@
{
"directories": {
"test": "test"
},
"author": "azu",
"license": "MIT",
"files": [
"bin/",
"lib/",
"src/"
],
"name": "get-github-pr-review-comments",
"version": "1.0.0",
"description": "Get PR review comments.",
"main": "lib/GitHub.js",
"bin": {
"get-github-pr-review-comments": "bin/cmd.js"
},
"scripts": {
"build": "cross-env NODE_ENV=production babel src --out-dir lib --source-maps",
"watch": "babel src --out-dir lib --watch --source-maps",
"prepublish": "npm run --if-present build"
},
"repository": {
"type": "git",
"url": "https://github.com/azu/get-github-pr-review-comments.git"
},
"bugs": {
"url": "https://github.com/azu/get-github-pr-review-comments/issues"
},
"homepage": "https://github.com/azu/get-github-pr-review-comments",
"devDependencies": {
"babel-cli": "^6.23.0",
"babel-preset-jsdoc-to-assert": "^4.0.0",
"babel-preset-latest": "^6.22.0",
"babel-preset-power-assert": "^1.0.0",
"babel-register": "^6.23.0",
"cross-env": "^3.1.4",
"mocha": "^3.2.0",
"power-assert": "^1.4.2"
},
"dependencies": {
"github": "^9.1.0",
"meow": "^3.7.0"
}
}
47 changes: 47 additions & 0 deletions src/GitHub.js
@@ -0,0 +1,47 @@
// MIT © 2017 azu
"use strict";
const GitHubApi = require("github");
export default class GitHubClient {
constructor(token) {
this.github = new GitHubApi({
debug: false,
protocol: "https",
followRedirects: false, // default: true; there's currently an issue with non-get redirects, so allow ability to disable follow-redirects
timeout: 5000
});
this.github.authenticate({
type: "oauth",
token: token
});

}

/**
*
* @param {string} owner
* @param {string} repo
* @param {string} commitSha
* @returns {Promise<{data:Object}>}
*/
getPR({owner, repo, commitSha}) {
const repoPath = this._createRepoString({owner, repo});
return this.github.search.issues({
q: `repo:${repoPath} type:pr ${commitSha}`
});
}

/**
* @param {string} owner
* @param {string} repo
* @param {number} number
* @param {number} id
* @returns {Promise<{data:Object}>}
*/
getComments({owner, repo, number, id}) {
return this.github.pullRequests.getComments({owner, repo, number, id});
}

_createRepoString({owner, repo}) {
return `${owner}/${repo}`;
}
};
52 changes: 52 additions & 0 deletions src/cli.js
@@ -0,0 +1,52 @@
// MIT © 2017 azu
"use strict";
const assert = require("assert");
const GH_TOKEN = process.env.GH_TOKEN;
import GitHubAPI from "./GitHub";
import {format} from "./formatter";

/**
*
* @param {string} commitSha
* @param {{
* token: string,
* projectRoot: string,
* repo: string
* }} flag
*/
module.exports = function(commitSha, flag) {
const [owner, repo] = flag.repo.split("/");
assert(owner && repo, "--repo owner/repo");
const ghToken = GH_TOKEN || flag.token;
assert(ghToken, "--token xxx or export GH_TOKEN=xxx");
const projectRoot = flag.projectRoot;
assert(projectRoot, "--projectRoot /path/to/dir");

const github = new GitHubAPI(ghToken);
return github.getPR({
owner: owner,
repo: repo,
commitSha: commitSha
}).then(response => {
if (response.data.total_count === 0) {
return;
}
const item = response.data.items[0];
return github.getComments({
owner: owner,
repo: repo,
id: item.id,
number: item.number
});
}).then(response => {
const formatData = response.data.map(data => {
return format(data, {
owner,
repo,
projectRoot,
commitSha
});
});
return formatData.join("\n----\n");
});
};

0 comments on commit a100bfe

Please sign in to comment.