github-repository-provider 7.26.41 → 7.28.0

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.26.41",
3
+ "version": "7.28.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -32,11 +32,11 @@
32
32
  "dependencies": {
33
33
  "content-entry": "^5.0.1",
34
34
  "fetch-link-util": "^1.0.8",
35
- "fetch-rate-limit-util": "^2.10.2",
35
+ "fetch-rate-limit-util": "^2.10.3",
36
36
  "matching-iterator": "^2.0.4",
37
37
  "node-fetch": "^3.2.4",
38
38
  "one-time-execution-method": "^3.0.1",
39
- "repository-provider": "^29.2.2"
39
+ "repository-provider": "^29.2.3"
40
40
  },
41
41
  "devDependencies": {
42
42
  "ava": "^4.2.0",
@@ -10,6 +10,12 @@ import {
10
10
  * Branch on GitHub.
11
11
  */
12
12
  export class GithubBranch extends Branch {
13
+
14
+ get api()
15
+ {
16
+ return this.repository.api;
17
+ }
18
+
13
19
  /**
14
20
  * Writes content into the branch
15
21
  * {@link https://developer.github.com/v3/git/blobs/#get-a-blob}
@@ -18,7 +24,7 @@ export class GithubBranch extends Branch {
18
24
  */
19
25
  async writeEntry(entry) {
20
26
  const { json } = await this.provider.fetchJSON(
21
- `repos/${this.slug}/git/blobs`,
27
+ `${this.api}/git/blobs`,
22
28
  {
23
29
  method: "POST",
24
30
  body: JSON.stringify({
@@ -58,7 +64,7 @@ export class GithubBranch extends Branch {
58
64
  const commit = await this.commitForSha(shaLatestCommit);
59
65
 
60
66
  let { json } = await this.provider.fetchJSON(
61
- `repos/${this.slug}/git/trees`,
67
+ `${this.api}/git/trees`,
62
68
  {
63
69
  method: "POST",
64
70
  body: JSON.stringify({
@@ -75,7 +81,7 @@ export class GithubBranch extends Branch {
75
81
  }
76
82
  );
77
83
 
78
- let r = await this.provider.fetchJSON(`repos/${this.slug}/git/commits`, {
84
+ let r = await this.provider.fetchJSON(`${this.api}/git/commits`, {
79
85
  method: "POST",
80
86
  body: JSON.stringify({
81
87
  message,
@@ -84,7 +90,7 @@ export class GithubBranch extends Branch {
84
90
  })
85
91
  });
86
92
 
87
- r = await this.provider.fetchJSON(`repos/${this.slug}/git/${this.ref}`, {
93
+ r = await this.provider.fetchJSON(`${this.api}/git/${this.ref}`, {
88
94
  method: "PATCH",
89
95
  body: JSON.stringify({
90
96
  ...options,
@@ -114,9 +120,7 @@ export class GithubBranch extends Branch {
114
120
  }
115
121
 
116
122
  const f = async () => {
117
- const { json } = await this.provider.fetchJSON(
118
- `repos/${this.slug}/contents/${name}?ref=${this.ref}`
119
- );
123
+ const { json } = await this.provider.fetchJSON(`${this.api}/contents/${name}?ref=${this.ref}`);
120
124
 
121
125
  const entry = new this.entryClass(
122
126
  name,
@@ -149,9 +153,7 @@ export class GithubBranch extends Branch {
149
153
  this.#commitForSha = new Map();
150
154
  }
151
155
 
152
- const { json } = await this.provider.fetchJSON(
153
- `repos/${this.slug}/git/commits/${sha}`
154
- );
156
+ const { json } = await this.provider.fetchJSON(`${this.api}/git/commits/${sha}`);
155
157
 
156
158
  this.#commitForSha.set(sha, json);
157
159
 
@@ -173,9 +175,7 @@ export class GithubBranch extends Branch {
173
175
  this.#tree = new Map();
174
176
  }
175
177
 
176
- const { json } = await this.provider.fetchJSON(
177
- `repos/${this.slug}/git/trees/${sha}?recursive=1`
178
- );
178
+ const { json } = await this.provider.fetchJSON(`${this.api}/git/trees/${sha}?recursive=1`);
179
179
 
180
180
  const tree = json.tree;
181
181
 
@@ -219,7 +219,7 @@ export class GithubBranch extends Branch {
219
219
  */
220
220
  async removeEntries(entries) {
221
221
  for await (const entry of entries) {
222
- await this.provider.fetch(`repos/${this.slug}/contents/${entry.name}`, {
222
+ await this.provider.fetch(`${this.api}/contents/${entry.name}`, {
223
223
  method: "DELETE",
224
224
  body: JSON.stringify({ branch: this.name, message: "", sha: "" })
225
225
  });
@@ -249,7 +249,7 @@ class LazyBufferContentEntry extends BufferContentEntryMixin(ContentEntry) {
249
249
 
250
250
  const f = async () => {
251
251
  const { json } = await branch.provider.fetchJSON(
252
- `repos/${branch.slug}/contents/${this.name}?ref=${branch.ref}`
252
+ `${branch.api}/contents/${this.name}?ref=${branch.ref}`
253
253
  );
254
254
 
255
255
  this.#buffer = Buffer.from(json.content, "base64");
@@ -39,7 +39,7 @@ export class GithubPullRequest extends PullRequest {
39
39
  for (const state of [
40
40
  ...(filter.states ? filter.states : this.defaultListStates)
41
41
  ]) {
42
- let next = `/repos/${repository.slug}/pulls?state=${state}${head}${base}`;
42
+ let next = `${repository.api}/pulls?state=${state}${head}${base}`;
43
43
 
44
44
  do {
45
45
  const provider = repository.provider;
@@ -73,7 +73,7 @@ export class GithubPullRequest extends PullRequest {
73
73
  }
74
74
 
75
75
  const { json } = await destination.provider.fetchJSON(
76
- `repos/${destination.repository.slug}/pulls`,
76
+ `${destination.repository.api}/pulls`,
77
77
  {
78
78
  method: "POST",
79
79
  body: JSON.stringify({
@@ -92,7 +92,7 @@ export class GithubPullRequest extends PullRequest {
92
92
  */
93
93
  async _merge(method = "MERGE") {
94
94
  const res = await this.provider.fetch(
95
- `repos/${this.source.repository.slug}/pulls/${this.number}/merge`,
95
+ `${this.source.repository.api}/pulls/${this.number}/merge`,
96
96
  {
97
97
  method: "PUT",
98
98
  body: JSON.stringify({ merge_method: method, sha: "???" })
@@ -105,7 +105,7 @@ export class GithubPullRequest extends PullRequest {
105
105
  */
106
106
  async update() {
107
107
  const res = await this.provider.fetch(
108
- `repos/${this.source.repository.slug}/pulls/${this.number}`,
108
+ `${this.source.repository.api}/pulls/${this.number}`,
109
109
  {
110
110
  method: "PATCH",
111
111
  body: JSON.stringify({
@@ -39,6 +39,9 @@ export class GithubRepository extends Repository {
39
39
  };
40
40
  }
41
41
 
42
+ /**
43
+ * @return {string} "main"
44
+ */
42
45
  get defaultBranchName() {
43
46
  return "main";
44
47
  }
@@ -49,7 +52,7 @@ export class GithubRepository extends Repository {
49
52
  * @returns {AsyncIterator<Commit>}
50
53
  */
51
54
  async *commits(options) {
52
- let next = `repos/${this.slug}/commits`;
55
+ let next = `${this.api}/commits`;
53
56
 
54
57
  do {
55
58
  const { response, json } = await this.provider.fetchJSON(next);
@@ -66,8 +69,8 @@ export class GithubRepository extends Repository {
66
69
  } while (next);
67
70
  }
68
71
 
69
- async _initializeSlot(typeName, addMethodName) {
70
- let next = `repos/${this.slug}/${typeName}`;
72
+ async #initializeSlot(typeName, addMethodName) {
73
+ let next = `${this.api}/${typeName}`;
71
74
 
72
75
  do {
73
76
  const { response, json } = await this.provider.fetchJSON(next);
@@ -80,14 +83,14 @@ export class GithubRepository extends Repository {
80
83
  * {@link https://developer.github.com/v3/repos/branches/#list-branches}
81
84
  */
82
85
  async initializeBranches() {
83
- return this._initializeSlot("branches", "addBranch");
86
+ return this.#initializeSlot("branches", "addBranch");
84
87
  }
85
88
 
86
89
  /**
87
90
  * {@link https://docs.github.com/en/rest/reference/repos#list-repository-tags}
88
91
  */
89
92
  async initializeTags() {
90
- return this._initializeSlot("tags", "addTag");
93
+ return this.#initializeSlot("tags", "addTag");
91
94
  }
92
95
 
93
96
  /**
@@ -113,11 +116,19 @@ export class GithubRepository extends Repository {
113
116
  return `${this.provider.url}${this.fullName}#readme`;
114
117
  }
115
118
 
119
+ /**
120
+ * API endpoint for ourselfs.
121
+ * @return {string}
122
+ */
123
+ get api() {
124
+ return `repos/${this.slug}`;
125
+ }
126
+
116
127
  /**
117
128
  * {@link https://developer.github.com/v3/repos/#update-a-repository}
118
129
  */
119
130
  async update() {
120
- return this.provider.fetch(`repos/${this.slug}`, {
131
+ return this.provider.fetch(this.api, {
121
132
  method: "PATCH",
122
133
  body: JSON.stringify(
123
134
  mapAttributesInverse(
@@ -128,7 +139,6 @@ export class GithubRepository extends Repository {
128
139
  });
129
140
  }
130
141
 
131
-
132
142
  #ref;
133
143
 
134
144
  /**
@@ -150,7 +160,7 @@ export class GithubRepository extends Repository {
150
160
  }
151
161
 
152
162
  const { response, json } = await this.provider.fetchJSON(
153
- `repos/${this.slug}/git/ref/${ref}`,
163
+ `${this.api}/git/ref/${ref}`,
154
164
  undefined,
155
165
  conflictErrorActions
156
166
  );
@@ -168,7 +178,7 @@ export class GithubRepository extends Repository {
168
178
 
169
179
  async createBranch(name, from, options) {
170
180
  await this.initializeBranches();
171
-
181
+
172
182
  const branch = await this.branch(name);
173
183
  if (branch) {
174
184
  return branch;
@@ -180,8 +190,7 @@ export class GithubRepository extends Repository {
180
190
  sha = await this.refId(
181
191
  `heads/${from ? from.name : this.defaultBranchName}`
182
192
  );
183
- }
184
- else {
193
+ } else {
185
194
  /*
186
195
  * https://stackoverflow.com/questions/9765453/is-gits-semi-secret-empty-tree-object-reliable-and-why-is-there-not-a-symbolic/9766506#9766506
187
196
  * sha1:4b825dc642cb6eb9a060e54bf8d69288fbee4904
@@ -199,7 +208,7 @@ export class GithubRepository extends Repository {
199
208
  */
200
209
  }
201
210
 
202
- const res = await this.provider.fetch(`repos/${this.slug}/git/refs`, {
211
+ const res = await this.provider.fetch(`${this.api}/git/refs`, {
203
212
  method: "POST",
204
213
  body: JSON.stringify({
205
214
  ref: `refs/heads/${name}`,
@@ -216,7 +225,7 @@ export class GithubRepository extends Repository {
216
225
 
217
226
  async deleteBranch(name) {
218
227
  const res = await this.provider.fetch(
219
- `repos/${this.slug}/git/refs/heads/${name}`,
228
+ `${this.api}/git/refs/heads/${name}`,
220
229
  {
221
230
  method: "DELETE"
222
231
  }
@@ -233,7 +242,7 @@ export class GithubRepository extends Repository {
233
242
  * @param {string} name
234
243
  */
235
244
  async deletePullRequest(name) {
236
- const res = await this.provider.fetch(`repos/${this.slug}/pulls/${name}`, {
245
+ const res = await this.provider.fetch(`${this.api}/pulls/${name}`, {
237
246
  method: "PATCH",
238
247
  body: JSON.stringify({ state: "closed" })
239
248
  });
@@ -247,7 +256,7 @@ export class GithubRepository extends Repository {
247
256
  * {@link https://developer.github.com/v3/repos/hooks/}
248
257
  */
249
258
  async initializeHooks() {
250
- let next = `repos/${this.slug}/hooks`;
259
+ let next = `${this.api}/hooks`;
251
260
 
252
261
  do {
253
262
  const { response, json } = await this.provider.fetchJSON(next);
@@ -261,6 +270,7 @@ export class GithubRepository extends Repository {
261
270
  next = getHeaderLink(response.headers);
262
271
  } while (next);
263
272
  }
273
+
264
274
  }
265
275
 
266
276
  replaceWithOneTimeExecutionMethod(