github-repository-provider 7.25.1 → 7.25.5

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.1",
3
+ "version": "7.25.5",
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.4.1",
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.1"
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";
@@ -98,7 +98,17 @@ export class GithubProvider extends MultiGroupProvider {
98
98
  }
99
99
 
100
100
  fetch(url, options = {}) {
101
- 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(
102
112
  fetch,
103
113
  new URL(url, this.api),
104
114
  {
@@ -108,50 +118,12 @@ export class GithubProvider extends MultiGroupProvider {
108
118
  ...options.headers
109
119
  }
110
120
  },
111
- (millisecondsToWait, rateLimitRemaining, nthTry, response) => {
112
- this.rateLimitRemaining = rateLimitRemaining;
113
-
114
- const msecs = defaultWaitDecide(
115
- millisecondsToWait,
116
- rateLimitRemaining,
117
- nthTry,
118
- response
119
- );
120
-
121
- if (msecs > 0) {
122
- this.warn(`Rate limit reached: waiting for ${msecs / 1000}s`);
123
- }
124
- return msecs;
121
+ async response => {
122
+ return { response, json: await response.json() };
125
123
  }
126
124
  );
127
125
  }
128
126
 
129
- async fetchJSON(url, options) {
130
- for (let i = 1; ; i++) {
131
- try {
132
- const response = await this.fetch(url, options);
133
- if (response.ok) {
134
- return { response, json: await response.json() };
135
- }
136
-
137
- if (i >= 3 || response.status == 401) {
138
- // none repeatable
139
- throw new Error(
140
- `Unable to fetch ${response.url} (${response.status})`
141
- );
142
- }
143
- this.info(
144
- `Unable to fetch ${response.url} (${response.status}) try #${i}`
145
- );
146
- } catch (e) {
147
- if (i >= 3) {
148
- throw e;
149
- }
150
- this.error(e);
151
- }
152
- }
153
- }
154
-
155
127
  /**
156
128
  * {@link https://developer.github.com/v3/repos/#list-repositories-for-the-authenticated-user}
157
129
  */