Skip to content

Commit 6140a3e

Browse files
committed
Provide owner/ repo as cli arguments
1 parent 0596b08 commit 6140a3e

File tree

4 files changed

+14
-29
lines changed

4 files changed

+14
-29
lines changed

.env.example

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
GITHUB_USER_NAME=facebook
2-
GITHUB_REPO_NAME=react
31
GITHUB_TOKEN=create a new token here https://github.com/settings/tokens/new
42
DATABASE_PATH=path to your sqlite3 database

README.md

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,6 @@ The pull request size calculated based on the total lines of code changed (`tota
3232
## Usage
3333

3434
```sh
35-
# The user and repo name you want to collect and display metrics
36-
# e.g. https://github.com/facebook/react
37-
# GITHUB_USER_NAME=facebook
38-
# GITHUB_REPO_NAME=react
39-
$ export GITHUB_USER_NAME=github-user-name
40-
$ export GITHUB_REPO_NAME=github-repo-name
41-
4235
# Create a personal access tokens (https://github.com/settings/tokens/new)
4336
$ export GITHUB_TOKEN=github-token
4437

@@ -48,10 +41,12 @@ $ export DATABASE_PATH=data/github.db
4841
$ npm install
4942

5043
# Collect data from GitHub
51-
$ npm start collect
44+
# npm start collect <owner> <repository>
45+
$ npm start collect facebook react
5246

5347
# Push data to graphite
54-
$ npm start export | nc localhost 2003
48+
# npm start export <owner> <repository>
49+
$ npm start export facebook react | nc localhost 2003
5550

5651
# The generated time series will be written to `stdout`.
5752
# github.github-user-name.repository-name.pull_requests.size_m.time_to_merge 3450 1554125772

docker-compose.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ services:
55
build:
66
context: .
77
dockerfile: ./Dockerfile
8-
command: bash -c "npm start collect && npm start export:toGraphite | nc graphite 2003"
8+
command: bash -c "npm test"
99
depends_on:
1010
- graphite
1111
tty: true
@@ -14,8 +14,6 @@ services:
1414
- ./data:/opt/github-metrics/data
1515
- ./src:/opt/github-metrics/src
1616
environment:
17-
GITHUB_USER_NAME: ${GITHUB_USER_NAME}
18-
GITHUB_REPO_NAME: ${GITHUB_REPO_NAME}
1917
GITHUB_TOKEN: ${GITHUB_TOKEN}
2018
DATABASE_PATH: ${DATABASE_PATH}
2119

src/cli.js

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,25 @@ const pkg = require('../package.json');
88

99
program
1010
.version(pkg.version)
11-
.command('collect')
12-
.action(async () => {
11+
.command('collect <owner> <repository>')
12+
.action(async (owner, repository) => {
1313
const database = new Database(getOrFail('DATABASE_PATH'), {
1414
fileMustExist: true,
1515
});
1616
const githubClient = new GitHub({
1717
token: getOrFail('GITHUB_TOKEN'),
1818
});
1919

20-
const githubUserName = getOrFail('GITHUB_USER_NAME');
21-
const githubRepoName = getOrFail('GITHUB_REPO_NAME');
2220
const { numberOfPullRequestProcessed, lastCursor } = await collector(
2321
database,
2422
githubClient,
25-
githubUserName,
26-
githubRepoName
23+
owner,
24+
repository
2725
);
2826

2927
process.stdout.write(
30-
`Stats for "${githubUserName}-${githubRepoName}":\n` +
31-
` Url "https://github.com/${githubUserName}/${githubRepoName}/pulls?utf8=✓&q=is%3Apr+is%3Amerged":\n` +
28+
`Stats for "${owner}-${repository}":\n` +
29+
` Url "https://github.com/${owner}/${repository}/pulls?utf8=✓&q=is%3Apr+is%3Amerged":\n` +
3230
` Number of processed pull requests: ${numberOfPullRequestProcessed}\n` +
3331
` Last cursor: ${lastCursor}\n`
3432
);
@@ -40,17 +38,13 @@ program
4038

4139
program
4240
.version(pkg.version)
43-
.command('export:toGraphite')
44-
.action(async () => {
41+
.command('export:toGraphite <owner> <repository>')
42+
.action(async (owner, repository) => {
4543
const database = new Database(getOrFail('DATABASE_PATH'), {
4644
fileMustExist: true,
4745
});
4846

49-
await graphiteExporter(
50-
database,
51-
getOrFail('GITHUB_USER_NAME'),
52-
getOrFail('GITHUB_REPO_NAME')
53-
);
47+
await graphiteExporter(database, owner, repository);
5448

5549
if (database.open) {
5650
database.close();

0 commit comments

Comments
 (0)