github-repository-provider 7.25.0 → 7.25.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/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2017-2021 by arlac77
1
+ Copyright (c) 2017-2022 by arlac77
2
2
  All rights reserved.
3
3
 
4
4
  Redistribution and use in source and binary forms, with or without
package/README.md CHANGED
@@ -36,13 +36,13 @@ console.log(entry.name);
36
36
  * [GithubBranch](#githubbranch)
37
37
  * [writeEntry](#writeentry)
38
38
  * [Parameters](#parameters)
39
- * [baseTreeSha](#basetreesha)
40
- * [Parameters](#parameters-1)
41
39
  * [commit](#commit)
42
- * [Parameters](#parameters-2)
40
+ * [Parameters](#parameters-1)
43
41
  * [entry](#entry)
44
- * [Parameters](#parameters-3)
42
+ * [Parameters](#parameters-2)
45
43
  * [maybeEntry](#maybeentry)
44
+ * [Parameters](#parameters-3)
45
+ * [baseTreeSha](#basetreesha)
46
46
  * [Parameters](#parameters-4)
47
47
  * [tree](#tree)
48
48
  * [Parameters](#parameters-5)
@@ -99,14 +99,6 @@ Writes content into the branch
99
99
 
100
100
  Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<ConentEntry>** written content with sha values set
101
101
 
102
- ### baseTreeSha
103
-
104
- <https://developer.github.com/v3/git/commits/#get-a-commit>
105
-
106
- #### Parameters
107
-
108
- * `sha` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
109
-
110
102
  ### commit
111
103
 
112
104
  <https://developer.github.com/v3/git/trees/#create-a-tree>
@@ -133,6 +125,14 @@ Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/
133
125
 
134
126
  * `name`
135
127
 
128
+ ### baseTreeSha
129
+
130
+ <https://developer.github.com/v3/git/commits/#get-a-commit>
131
+
132
+ #### Parameters
133
+
134
+ * `sha` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
135
+
136
136
  ### tree
137
137
 
138
138
  * **See**: <https://developer.github.com/v3/git/trees/>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "github-repository-provider",
3
- "version": "7.25.0",
3
+ "version": "7.25.4",
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": "^2.0.2",
35
+ "fetch-rate-limit-util": "^2.3.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.1.0"
39
+ "repository-provider": "^26.1.2"
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.1",
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";
@@ -42,7 +42,7 @@ 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() {
@@ -74,9 +74,7 @@ export class GithubProvider extends MultiGroupProvider {
74
74
  // @see https://cli.github.com/manual/gh_help_environment
75
75
  env: [
76
76
  "{{instanceIdentifier}}TOKEN",
77
- "GH_TOKEN",
78
- "GITHUB_ENTERPRISE_TOKEN",
79
- "GH_ENTERPRISE_TOKEN"
77
+ "GH_TOKEN" // declare GH_ as identifier
80
78
  ],
81
79
  additionalAttributes: { "authentication.type": "token" },
82
80
  private: true,
@@ -100,7 +98,17 @@ export class GithubProvider extends MultiGroupProvider {
100
98
  }
101
99
 
102
100
  fetch(url, options = {}) {
103
- return rateLimitHandler(
101
+ return stateActionHandler(fetch, new URL(url, this.api), {
102
+ ...options,
103
+ headers: {
104
+ authorization: `token ${this.authentication.token}`,
105
+ ...options.headers
106
+ }
107
+ });
108
+ }
109
+
110
+ fetchJSON(url, options = {}) {
111
+ return stateActionHandler(
104
112
  fetch,
105
113
  new URL(url, this.api),
106
114
  {
@@ -110,50 +118,12 @@ export class GithubProvider extends MultiGroupProvider {
110
118
  ...options.headers
111
119
  }
112
120
  },
113
- (millisecondsToWait, rateLimitRemaining, nthTry, response) => {
114
- this.rateLimitRemaining = rateLimitRemaining;
115
-
116
- const msecs = defaultWaitDecide(
117
- millisecondsToWait,
118
- rateLimitRemaining,
119
- nthTry,
120
- response
121
- );
122
-
123
- if (msecs > 0) {
124
- this.warn(`Rate limit reached: waiting for ${msecs / 1000}s`);
125
- }
126
- return msecs;
121
+ async response => {
122
+ return { response, json: await response.json() };
127
123
  }
128
124
  );
129
125
  }
130
126
 
131
- async fetchJSON(url, options) {
132
- for (let i = 1; ; i++) {
133
- try {
134
- const response = await this.fetch(url, options);
135
- if (response.ok) {
136
- return { response, json: await response.json() };
137
- }
138
-
139
- if (i >= 3 || response.status == 401) {
140
- // none repeatable
141
- throw new Error(
142
- `Unable to fetch ${response.url} (${response.status})`
143
- );
144
- }
145
- this.info(
146
- `Unable to fetch ${response.url} (${response.status}) try #${i}`
147
- );
148
- } catch (e) {
149
- if (i >= 3) {
150
- throw e;
151
- }
152
- this.error(e);
153
- }
154
- }
155
- }
156
-
157
127
  /**
158
128
  * {@link https://developer.github.com/v3/repos/#list-repositories-for-the-authenticated-user}
159
129
  */