github-repository-provider 7.24.9 → 7.25.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "github-repository-provider",
3
- "version": "7.24.9",
3
+ "version": "7.25.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -32,17 +32,17 @@
32
32
  "dependencies": {
33
33
  "content-entry": "^3.0.2",
34
34
  "fetch-link-util": "^1.0.4",
35
- "fetch-rate-limit-util": "^1.1.6",
35
+ "fetch-rate-limit-util": "^2.1.0",
36
36
  "matching-iterator": "^2.0.0",
37
37
  "node-fetch": "3.1.0",
38
38
  "one-time-execution-method": "^2.0.9",
39
- "repository-provider": "^26.0.3"
39
+ "repository-provider": "^26.1.1"
40
40
  },
41
41
  "devDependencies": {
42
42
  "ava": "^3.15.0",
43
43
  "c8": "^7.11.0",
44
44
  "documentation": "^13.2.5",
45
- "repository-provider-test-support": "^1.9.0",
45
+ "repository-provider-test-support": "^1.9.2",
46
46
  "semantic-release": "^18.0.1"
47
47
  },
48
48
  "engines": {
@@ -34,17 +34,6 @@ export class GithubBranch extends Branch {
34
34
  return entry;
35
35
  }
36
36
 
37
- /**
38
- * {@link https://developer.github.com/v3/git/commits/#get-a-commit}
39
- * @param {string} sha
40
- */
41
- async baseTreeSha(sha) {
42
- const { json } = await this.provider.fetchJSON(
43
- `repos/${this.slug}/git/commits/${sha}`
44
- );
45
- return json.tree.sha;
46
- }
47
-
48
37
  /**
49
38
  * {@link https://developer.github.com/v3/git/trees/#create-a-tree}
50
39
  * {@link https://developer.github.com/v3/git/commits/#create-a-commit}
@@ -135,6 +124,17 @@ export class GithubBranch extends Branch {
135
124
  }
136
125
  }
137
126
 
127
+ /**
128
+ * {@link https://developer.github.com/v3/git/commits/#get-a-commit}
129
+ * @param {string} sha
130
+ */
131
+ async baseTreeSha(sha) {
132
+ const { json } = await this.provider.fetchJSON(
133
+ `repos/${this.slug}/git/commits/${sha}`
134
+ );
135
+ return json.tree.sha;
136
+ }
137
+
138
138
  /**
139
139
  * @see https://developer.github.com/v3/git/trees/
140
140
  * @param {string } treeSha
@@ -1,6 +1,6 @@
1
1
  import fetch from "node-fetch";
2
2
  import { replaceWithOneTimeExecutionMethod } from "one-time-execution-method";
3
- import { rateLimitHandler, defaultWaitDecide } from "fetch-rate-limit-util";
3
+ import { stateActionHandler } from "fetch-rate-limit-util";
4
4
 
5
5
  import { MultiGroupProvider } from "repository-provider";
6
6
  import { GithubRepository } from "./github-repository.mjs";
@@ -9,7 +9,7 @@ import { GithubOwner } from "./github-owner.mjs";
9
9
  import { GithubPullRequest } from "./github-pull-request.mjs";
10
10
  export { GithubRepository, GithubBranch, GithubOwner, GithubPullRequest };
11
11
 
12
- const domain = "github.com";
12
+ const host = "github.com";
13
13
 
14
14
  /**
15
15
  * <!-- skip-example -->
@@ -42,31 +42,40 @@ export class GithubProvider extends MultiGroupProvider {
42
42
  * @return {string} default instance environment name prefix
43
43
  */
44
44
  static get instanceIdentifier() {
45
- return "GITHUB_";
45
+ return "GITHUB_"; // "GH_" "GH_ENTERPRISE_"
46
46
  }
47
47
 
48
48
  static get attributes() {
49
49
  return {
50
50
  ...super.attributes,
51
+ host: {
52
+ type: "string",
53
+ env: ["{{instanceIdentifier}}HOST", "GH_HOST"],
54
+ default: "github.com"
55
+ },
51
56
  ssh: {
52
57
  type: "url",
53
- default: `git@${domain}:`
58
+ default: `git@${host}:`
54
59
  },
55
60
  url: {
56
61
  type: "url",
57
62
  env: ["{{instanceIdentifier}}SERVER_URL"],
58
63
  set: value => (value.endsWith("/") ? value : value + "/"),
59
- default: `https://${domain}/`
64
+ default: `https://${host}/`
60
65
  },
61
66
  api: {
62
67
  type: "url",
63
68
  env: ["{{instanceIdentifier}}API_URL"],
64
69
  set: value => value.replace(/\/$/, ""),
65
- default: `https://api.${domain}`
70
+ default: `https://api.${host}`
66
71
  },
67
72
  "authentication.token": {
68
73
  type: "string",
69
- env: ["{{instanceIdentifier}}TOKEN", "GH_TOKEN"],
74
+ // @see https://cli.github.com/manual/gh_help_environment
75
+ env: [
76
+ "{{instanceIdentifier}}TOKEN",
77
+ "GH_TOKEN" // declare GH_ as identifier
78
+ ],
70
79
  additionalAttributes: { "authentication.type": "token" },
71
80
  private: true,
72
81
  mandatory: true
@@ -89,31 +98,13 @@ export class GithubProvider extends MultiGroupProvider {
89
98
  }
90
99
 
91
100
  fetch(url, options = {}) {
92
- return rateLimitHandler(
93
- () =>
94
- fetch(new URL(url, this.api), {
95
- ...options,
96
- headers: {
97
- authorization: `token ${this.authentication.token}`,
98
- ...options.headers
99
- }
100
- }),
101
- (millisecondsToWait, rateLimitRemaining, nthTry, response) => {
102
- this.rateLimitRemaining = rateLimitRemaining;
103
-
104
- const msecs = defaultWaitDecide(
105
- millisecondsToWait,
106
- rateLimitRemaining,
107
- nthTry,
108
- response
109
- );
110
-
111
- if (msecs > 0) {
112
- this.warn(`Rate limit reached: waiting for ${msecs / 1000}s`);
113
- }
114
- return msecs;
101
+ return stateActionHandler(fetch, new URL(url, this.api), {
102
+ ...options,
103
+ headers: {
104
+ authorization: `token ${this.authentication.token}`,
105
+ ...options.headers
115
106
  }
116
- );
107
+ });
117
108
  }
118
109
 
119
110
  async fetchJSON(url, options) {
@@ -186,9 +177,9 @@ export class GithubProvider extends MultiGroupProvider {
186
177
  return super.repositoryBases.concat([
187
178
  this.url,
188
179
  "git+" + this.url,
189
- `git+ssh://${domain}`,
190
- `git://${domain}/`,
191
- `git@${domain}:`
180
+ `git+ssh://${host}`,
181
+ `git://${host}/`,
182
+ `git@${host}:`
192
183
  ]);
193
184
  }
194
185