github-repository-provider 7.24.8 → 7.24.9

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.8",
3
+ "version": "7.24.9",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -18,13 +18,16 @@ export class GithubBranch extends Branch {
18
18
  * @return {Promise<ConentEntry>} written content with sha values set
19
19
  */
20
20
  async writeEntry(entry) {
21
- const json = await this.provider.fetchJSON(`repos/${this.slug}/git/blobs`, {
22
- method: "POST",
23
- body: JSON.stringify({
24
- content: await entry.string,
25
- encoding: "utf8"
26
- })
27
- });
21
+ const { json } = await this.provider.fetchJSON(
22
+ `repos/${this.slug}/git/blobs`,
23
+ {
24
+ method: "POST",
25
+ body: JSON.stringify({
26
+ content: await entry.string,
27
+ encoding: "utf8"
28
+ })
29
+ }
30
+ );
28
31
 
29
32
  entry.sha = json.sha;
30
33
 
@@ -36,7 +39,7 @@ export class GithubBranch extends Branch {
36
39
  * @param {string} sha
37
40
  */
38
41
  async baseTreeSha(sha) {
39
- const json = await this.provider.fetchJSON(
42
+ const { json } = await this.provider.fetchJSON(
40
43
  `repos/${this.slug}/git/commits/${sha}`
41
44
  );
42
45
  return json.tree.sha;
@@ -66,24 +69,27 @@ export class GithubBranch extends Branch {
66
69
  const shaLatestCommit = await this.refId();
67
70
  const shaBaseTree = await this.baseTreeSha(shaLatestCommit);
68
71
 
69
- let json = await this.provider.fetchJSON(`repos/${this.slug}/git/trees`, {
70
- method: "POST",
71
- body: JSON.stringify({
72
- base_tree: shaBaseTree,
73
- tree: updates.map(u => {
74
- return {
75
- path: u.name,
76
- sha: u.sha,
77
- type: "blob",
78
- mode: "100" + u.mode.toString(8)
79
- };
72
+ let { json } = await this.provider.fetchJSON(
73
+ `repos/${this.slug}/git/trees`,
74
+ {
75
+ method: "POST",
76
+ body: JSON.stringify({
77
+ base_tree: shaBaseTree,
78
+ tree: updates.map(u => {
79
+ return {
80
+ path: u.name,
81
+ sha: u.sha,
82
+ type: "blob",
83
+ mode: "100" + u.mode.toString(8)
84
+ };
85
+ })
80
86
  })
81
- })
82
- });
87
+ }
88
+ );
83
89
 
84
90
  const shaNewTree = json.sha;
85
91
 
86
- json = await this.provider.fetchJSON(`repos/${this.slug}/git/commits`, {
92
+ const r = await this.provider.fetchJSON(`repos/${this.slug}/git/commits`, {
87
93
  method: "POST",
88
94
  body: JSON.stringify({
89
95
  message,
@@ -92,7 +98,7 @@ export class GithubBranch extends Branch {
92
98
  })
93
99
  });
94
100
 
95
- const sha = json.sha;
101
+ const sha = r.json.sha;
96
102
 
97
103
  return await this.provider.fetchJSON(
98
104
  `repos/${this.slug}/git/refs/heads/${this.name}`,
@@ -111,7 +117,7 @@ export class GithubBranch extends Branch {
111
117
  * @param {string} name
112
118
  */
113
119
  async entry(name) {
114
- const json = await this.provider.fetchJSON(
120
+ const { json } = await this.provider.fetchJSON(
115
121
  `repos/${this.slug}/contents/${name}?ref=${this.ref}`
116
122
  );
117
123
 
@@ -135,7 +141,7 @@ export class GithubBranch extends Branch {
135
141
  * @return {Object[]}
136
142
  */
137
143
  async tree(treeSha) {
138
- const json = await this.provider.fetchJSON(
144
+ const { json } = await this.provider.fetchJSON(
139
145
  `repos/${this.slug}/git/trees/${treeSha}?recursive=1`
140
146
  );
141
147
  return json.tree;
@@ -187,7 +193,7 @@ class LazyBufferContentEntry extends BufferContentEntryMixin(ContentEntry) {
187
193
  }
188
194
 
189
195
  const branch = this.branch;
190
- const json = await branch.provider.fetchJSON(
196
+ const { json } = await branch.provider.fetchJSON(
191
197
  `repos/${branch.slug}/contents/${this.name}?ref=${branch.ref}`
192
198
  );
193
199
 
@@ -39,12 +39,12 @@ export class GithubOwner extends RepositoryGroup {
39
39
  );
40
40
 
41
41
  if (response.ok) {
42
- this.provider.info(`Repository ${name} created`);
42
+ this.info(`Repository ${name} created`);
43
43
  options.defaultBranchName = "main";
44
44
  return this.addRepository(name, options);
45
45
  }
46
46
 
47
- this.provider.error(`Repository ${name} creation error ${response.status}`);
47
+ this.error(`Repository ${name} creation error ${response.status}`);
48
48
  }
49
49
 
50
50
  /**
@@ -117,18 +117,24 @@ export class GithubProvider extends MultiGroupProvider {
117
117
  }
118
118
 
119
119
  async fetchJSON(url, options) {
120
- let i = 1;
121
- while (true) {
120
+ for (let i = 1; ; i++) {
122
121
  try {
123
122
  const response = await this.fetch(url, options);
124
- if (!response.ok) {
123
+ if (response.ok) {
124
+ return { response, json: await response.json() };
125
+ }
126
+
127
+ if (i >= 3 || response.status == 401) {
128
+ // none repeatable
125
129
  throw new Error(
126
- `Unable to fetch ${response.url} (${response.status}) try #${i}`
130
+ `Unable to fetch ${response.url} (${response.status})`
127
131
  );
128
132
  }
129
- return await response.json();
133
+ this.info(
134
+ `Unable to fetch ${response.url} (${response.status}) try #${i}`
135
+ );
130
136
  } catch (e) {
131
- if (i++ >= 3) {
137
+ if (i >= 3) {
132
138
  throw e;
133
139
  }
134
140
  this.error(e);
@@ -140,9 +146,9 @@ export class GithubProvider extends MultiGroupProvider {
140
146
  * {@link https://developer.github.com/v3/repos/#list-repositories-for-the-authenticated-user}
141
147
  */
142
148
  async initializeRepositories() {
143
- for (let page = 1; ; page++) {
144
- try {
145
- const json = await this.fetchJSON(
149
+ try {
150
+ for (let page = 1; ; page++) {
151
+ const { json } = await this.fetchJSON(
146
152
  `user/repos?page=${page}&per_page=100`,
147
153
  {
148
154
  headers: {
@@ -162,10 +168,8 @@ export class GithubProvider extends MultiGroupProvider {
162
168
  r
163
169
  );
164
170
  });
165
- } catch (e) {
166
- return;
167
171
  }
168
- }
172
+ } catch {}
169
173
  }
170
174
 
171
175
  /**
@@ -43,8 +43,8 @@ export class GithubPullRequest extends PullRequest {
43
43
 
44
44
  do {
45
45
  const provider = repository.provider;
46
- const response = await provider.fetch(next);
47
- for (const node of await response.json()) {
46
+ const { response, json } = await provider.fetchJSON(next);
47
+ for (const node of json) {
48
48
  const [source, dest] = await Promise.all(
49
49
  [node.head, node.base].map(r =>
50
50
  provider.branch([r.repo.full_name, r.ref].join("#"))
@@ -72,7 +72,7 @@ export class GithubPullRequest extends PullRequest {
72
72
  return p;
73
73
  }
74
74
 
75
- const json = await destination.provider.fetchJSON(
75
+ const { json } = await destination.provider.fetchJSON(
76
76
  `repos/${destination.repository.slug}/pulls`,
77
77
  {
78
78
  method: "POST",
@@ -37,16 +37,7 @@ export class GithubRepository extends Repository {
37
37
  let next = `repos/${this.slug}/${typeName}`;
38
38
 
39
39
  do {
40
- const response = await this.provider.fetch(next);
41
-
42
- if (!response.ok) {
43
- this.error(
44
- `Unable to fetch ${typeName} ${response.status} ${response.url}`
45
- );
46
- return;
47
- }
48
-
49
- const json = await response.json();
40
+ const { response, json } = await this.provider.fetchJSON(next);
50
41
  json.forEach(b => this[addMethodName](b.name, b));
51
42
  next = getHeaderLink(response.headers);
52
43
  } while (next);
@@ -112,7 +103,9 @@ export class GithubRepository extends Repository {
112
103
  async refId(ref) {
113
104
  ref = ref.replace(/^refs\//, "");
114
105
 
115
- const json = await this.provider.fetchJSON(`repos/${this.slug}/git/ref/${ref}`);
106
+ const { json } = await this.provider.fetchJSON(
107
+ `repos/${this.slug}/git/ref/${ref}`
108
+ );
116
109
 
117
110
  // TODO why does this happen ?
118
111
  if (!json.object.sha) {
@@ -147,7 +140,7 @@ export class GithubRepository extends Repository {
147
140
  console.log(res);
148
141
  */
149
142
  } else {
150
- const json = await this.provider.fetchJSON(
143
+ const { json } = await this.provider.fetchJSON(
151
144
  `repos/${this.slug}/git/ref/heads/${
152
145
  from === undefined ? this.defaultBranchName : from.name
153
146
  }`
@@ -204,9 +197,9 @@ export class GithubRepository extends Repository {
204
197
  let next = `repos/${this.slug}/hooks`;
205
198
 
206
199
  do {
207
- const response = await this.provider.fetch(next);
200
+ const { response, json } = await this.provider.fetchJSON(next);
208
201
 
209
- for (const h of await response.json()) {
202
+ for (const h of json) {
210
203
  const id = h.id;
211
204
  delete h.id;
212
205
  new this.hookClass(this, id, new Set(h.events), {