Skip to content

Commit

Permalink
Merge pull request #20 from milesj/ghopts
Browse files Browse the repository at this point in the history
Pass github options to API instance.
  • Loading branch information
ericclemmons committed Nov 9, 2017
2 parents ea2151d + 638355d commit 7e1ea53
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,23 @@ calculate the package version of a repo. Ex:
If you're working on a private project, you can leave out `--publish`, which
means you have no need for your `NPM_TOKEN` either.

#### github

You can add a `github` object to the `gsv` section of `package.json` (or to `gsv.json`),
which are options that will be passed to the [Github API](https://www.npmjs.com/package/github).

```json
{
...
"gsv": {
"github": {
"host": "github.my-GHE-enabled-company.com"
},
...
},
...
}
```

### License

Expand Down
3 changes: 2 additions & 1 deletion src/Github.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import Github from "github";

export default class GithubAPI {
constructor(userRepo) {
constructor(userRepo, apiOptions = {}) {
this.defaultOptions = {
owner: userRepo.user,
repo: userRepo.repo,
};

this.github = new Github({
version: "3.0.0",
...apiOptions,
});

// this buys you 5000 requests an hour in all but the Search API, where you get 30 requests/min
Expand Down
14 changes: 9 additions & 5 deletions src/Version.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default class Version {
const commitSHA = Utils.getLastCommit();

// get the last commit from github
const githubapi = new GithubAPI(Utils.getUserRepo());
const githubapi = this.getGithubAPI();
const commit = await githubapi.getCommit(commitSHA);
commit.increment = Version.INCREMENT_PATCH;

Expand All @@ -77,7 +77,7 @@ export default class Version {

// returns a pull request with increment level noted
async getIncrementFromPullRequest(number) {
const githubapi = new GithubAPI(Utils.getUserRepo());
const githubapi = this.getGithubAPI();
const prDetails = await githubapi.getPullRequest(number);
prDetails.labels = await githubapi.getIssueLabels(number);

Expand Down Expand Up @@ -210,7 +210,7 @@ export default class Version {
}

async getPullRequestCommits(prs) {
const githubapi = new GithubAPI(Utils.getUserRepo());
const githubapi = this.getGithubAPI();

const prCommits = prs.map(async (pr) => {
const commits = await githubapi.getCommitsFromPullRequest(pr.number);
Expand All @@ -226,7 +226,7 @@ export default class Version {
return this.timeline;
}

const githubapi = new GithubAPI(Utils.getUserRepo());
const githubapi = this.getGithubAPI();
debug.info(`Fetching all merged pull requests for the repo...`);
const allIssues = await githubapi.searchIssues({ state: "closed", type: "pr", is: "merged" });
debug.info(`Merged pull requests fetched: ${allIssues.length}`);
Expand Down Expand Up @@ -264,6 +264,10 @@ export default class Version {
return theTimeline;
}

getGithubAPI() {
return new GithubAPI(Utils.getUserRepo(), this.config.github);
}

getIncrementFromIssueLabels(issue) {
const regex = new RegExp(`^${this.config["major-label"]}|^${this.config["minor-label"]}|^${this.config["patch-label"]}`);
// commits won't have labels property
Expand All @@ -290,7 +294,7 @@ export default class Version {

async getChangeLogContents() {
const spinner = ora("Generating the changelog contents").start();
const githubapi = new GithubAPI(Utils.getUserRepo());
const githubapi = this.getGithubAPI();
const allEvents = await this.getRepoTimeline();

const lines = [];
Expand Down

0 comments on commit 7e1ea53

Please sign in to comment.