volunteer-contributions-fetch 2.3.3 → 2.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -119,28 +119,28 @@ This section documents all the possible configuration values. For examples see t
119
119
 
120
120
  #### GitHub
121
121
 
122
- | Field | Data Type | Required | Default | Description |
123
- | -------------------------- | --------- | -------- | ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
124
- | `enabled` | boolean | Yes | - | Indicates whether this data source is enabled. Alternatively you can also leave off the `github` object entirely. |
125
- | `allowPrivate` | boolean | No | false | Indicates whether fetching from private repositories is allowed. If not set, the script will throw if you pass a `GITHUB_TOKEN` with private repo scope. In most cases you will not want to have a token with private scope as you do not want to leak any private information in your contribution overview. Please think twice before enabling this config. |
126
- | `commentsEnabled` | boolean | No | true | Indicates whether fetching comments is enabled. |
127
- | `commitsEnabled` | boolean | No | true | Indicates whether fetching commits is enabled. |
128
- | `issuesEnabled` | boolean | No | true | Indicates whether fetching issues is enabled. |
129
- | `reviewsEnabled` | boolean | No | true | Indicates whether fetching reviews is enabled. |
130
- | `username` | string | Yes | - | Username on GitHub |
131
- | `stopDate` | string | Yes | - | `new Date()` parseable string containing a date of possibly earliest contribution to track |
132
- | `filter` | string | Yes | - | Regex to apply to each entry to filter for organization/repo names. For example: `^mozilla` to only include orgs and repos that start with "mozilla". |
133
- | `types` | Object | No | - | Object containing the different labels below |
134
- | `types.commit` | string | No | GitHub Commit | Label for entries related to GitHub commits |
135
- | `types.privateCommit` | string | No | Commit in private repository | Label for entries related to private GitHub commits |
136
- | `types.createdPR` | string | No | Created PR | Label for entries related to opening GitHub PRs |
137
- | `types.createdIssue` | string | No | Created Issue Report | Label for entries related to creating GitHub issues |
138
- | `types.commented` | string | No | Commented on an Issue | Label for entries related to commenting on an issue |
139
- | `types.commentedPR` | string | No | Commented on a Pull Request | Label for entries related to commenting on a GitHub PR (review) |
140
- | `types.approvedPR` | string | No | Approved a Pull Request | Label for entries related to approving a GitHub PR |
141
- | `types.changesRequestedPR` | string | No | Requested changes on a Pull Request | Label for entries related to requesting changes on a GitHub PR |
142
- | `types.reviewedPR` | string | No | Reviewed a Pull Request | Label for entries related to reviewing a GitHub PR (fallback) |
143
- | `delayMsPerRequest` | number | No | 2000 | Delay between each request to GitHub. You might hit rate limiting if you set this lower than default. |
122
+ | Field | Data Type | Required | Default | Description |
123
+ | -------------------------- | --------- | -------- | ----------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
124
+ | `enabled` | boolean | Yes | - | Indicates whether this data source is enabled. Alternatively you can also leave off the `github` object entirely. |
125
+ | `allowPrivate` | boolean | No | false | Will throw if you pass a `GITHUB_TOKEN` with possible private repo scope. In most cases you will not want to have a token with private scope. Please think twice before enabling this config. When using fine-grained tokens, you need to set this to `true` manually as we can't detect the scopes. In that case, we can't guarantee anything! |
126
+ | `commentsEnabled` | boolean | No | true | Indicates whether fetching comments is enabled. |
127
+ | `commitsEnabled` | boolean | No | true | Indicates whether fetching commits is enabled. |
128
+ | `issuesEnabled` | boolean | No | true | Indicates whether fetching issues is enabled. |
129
+ | `reviewsEnabled` | boolean | No | true | Indicates whether fetching reviews is enabled. |
130
+ | `username` | string | Yes | - | Username on GitHub |
131
+ | `stopDate` | string | Yes | - | `new Date()` parseable string containing a date of possibly earliest contribution to track |
132
+ | `filter` | string | Yes | - | Regex to apply to each entry to filter for organization/repo names. For example: `^mozilla` to only include orgs and repos that start with "mozilla". |
133
+ | `types` | Object | No | - | Object containing the different labels below |
134
+ | `types.commit` | string | No | GitHub Commit | Label for entries related to GitHub commits |
135
+ | `types.privateCommit` | string | No | Commit in private repository | Label for entries related to private GitHub commits |
136
+ | `types.createdPR` | string | No | Created PR | Label for entries related to opening GitHub PRs |
137
+ | `types.createdIssue` | string | No | Created Issue Report | Label for entries related to creating GitHub issues |
138
+ | `types.commented` | string | No | Commented on an Issue | Label for entries related to commenting on an issue |
139
+ | `types.commentedPR` | string | No | Commented on a Pull Request | Label for entries related to commenting on a GitHub PR (review) |
140
+ | `types.approvedPR` | string | No | Approved a Pull Request | Label for entries related to approving a GitHub PR |
141
+ | `types.changesRequestedPR` | string | No | Requested changes on a Pull Request | Label for entries related to requesting changes on a GitHub PR |
142
+ | `types.reviewedPR` | string | No | Reviewed a Pull Request | Label for entries related to reviewing a GitHub PR (fallback) |
143
+ | `delayMsPerRequest` | number | No | 2000 | Delay between each request to GitHub. You might hit rate limiting if you set this lower than default. |
144
144
 
145
145
  #### MediaWiki
146
146
 
@@ -2,9 +2,11 @@ const debug = require('debug')('contributions:github-fetcher');
2
2
  const { Octokit } = require('@octokit/rest');
3
3
 
4
4
  const RESULTS_PER_PAGE = 100;
5
+ const PRIVATE_SCOPE_ERROR = 'PRIVATE_SCOPE';
5
6
 
6
7
  module.exports = {
7
8
  RESULTS_PER_PAGE,
9
+ PRIVATE_SCOPE_ERROR,
8
10
  searchCommits,
9
11
  searchIssues,
10
12
  listReviews,
@@ -76,8 +78,16 @@ async function listComments(options) {
76
78
  async function throwIfTokenHasPrivateRepoScope() {
77
79
  const octokit = getOctokit();
78
80
  const response = await octokit.rest.meta.root();
81
+ // If we don't have the scopes, such as for fine-grained
82
+ // access tokens, we error as well. We can't guarantee
83
+ // that the passed token is not indeed allowing private
84
+ // access.
85
+ if (!response.headers['x-oauth-scopes']) {
86
+ throw new Error(PRIVATE_SCOPE_ERROR);
87
+ }
88
+
79
89
  const scopes = response.headers['x-oauth-scopes'].split(', ');
80
90
  if (scopes.includes('repo')) {
81
- throw new Error('PRIVATE_SCOPE');
91
+ throw new Error(PRIVATE_SCOPE_ERROR);
82
92
  }
83
93
  }
package/lib/github.js CHANGED
@@ -70,10 +70,10 @@ async function gather({ github }, existingContributions = []) {
70
70
  try {
71
71
  await fetcher.throwIfTokenHasPrivateRepoScope();
72
72
  } catch (error) {
73
- if (error.message === 'PRIVATE_SCOPE') {
73
+ if (error.message === fetcher.PRIVATE_SCOPE_ERROR) {
74
74
  if (!github.allowPrivate) {
75
75
  throw new Error(
76
- 'GITHUB_TOKEN has private repo scope, but the config does not specify allowPrivate to fetch private repos. Are you sure you want to fetch private information?'
76
+ 'GITHUB_TOKEN might have private repo scope, but the config does not specify `allowPrivate` to fetch private repos. Are you sure you want to fetch private information? This might also be because you passed a fine-grained token. In that case we can not check the permissions it has and we assume it is private. You can double check the permissions and if you are sure it is correct, you may set `allowPrivate` to true.'
77
77
  );
78
78
  }
79
79
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "volunteer-contributions-fetch",
3
- "version": "2.3.3",
3
+ "version": "2.3.4",
4
4
  "description": "Library to fetch volunteer contributions from several sources such as GitHub",
5
5
  "author": "Michael Kohler",
6
6
  "license": "MIT",