github-repository-provider 7.24.2 → 7.24.6

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.2",
3
+ "version": "7.24.6",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -36,13 +36,13 @@
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.2"
39
+ "repository-provider": "^26.0.3"
40
40
  },
41
41
  "devDependencies": {
42
42
  "ava": "^3.15.0",
43
43
  "c8": "^7.10.0",
44
44
  "documentation": "^13.2.5",
45
- "repository-provider-test-support": "^1.8.13",
45
+ "repository-provider-test-support": "^1.8.15",
46
46
  "semantic-release": "^18.0.1"
47
47
  },
48
48
  "engines": {
@@ -15,17 +15,16 @@ export class GithubBranch extends Branch {
15
15
  * Writes content into the branch
16
16
  * {@link https://developer.github.com/v3/git/blobs/#get-a-blob}
17
17
  * @param {ConentEntry} entry
18
- * @return {Promise<Entry>} written content with sha values set
18
+ * @return {Promise<ConentEntry>} written content with sha values set
19
19
  */
20
20
  async writeEntry(entry) {
21
- const res = await this.provider.fetch(`repos/${this.slug}/git/blobs`, {
21
+ const json = await this.provider.fetchJSON(`repos/${this.slug}/git/blobs`, {
22
22
  method: "POST",
23
23
  body: JSON.stringify({
24
24
  content: await entry.string,
25
25
  encoding: "utf8"
26
26
  })
27
27
  });
28
- const json = await res.json();
29
28
 
30
29
  entry.sha = json.sha;
31
30
 
@@ -37,15 +36,10 @@ export class GithubBranch extends Branch {
37
36
  * @param {string} sha
38
37
  */
39
38
  async baseTreeSha(sha) {
40
- const res = await this.provider.fetch(
39
+ const json = await this.provider.fetchJSON(
41
40
  `repos/${this.slug}/git/commits/${sha}`
42
41
  );
43
- if (res.ok) {
44
- const json = await res.json();
45
- return json.tree.sha;
46
- }
47
-
48
- throw new Error(`Unable to decode ${res.url}`);
42
+ return json.tree.sha;
49
43
  }
50
44
 
51
45
  /**
@@ -72,7 +66,7 @@ export class GithubBranch extends Branch {
72
66
  const shaLatestCommit = await this.refId();
73
67
  const shaBaseTree = await this.baseTreeSha(shaLatestCommit);
74
68
 
75
- let result = await this.provider.fetch(`repos/${this.slug}/git/trees`, {
69
+ let json = await this.provider.fetchJSON(`repos/${this.slug}/git/trees`, {
76
70
  method: "POST",
77
71
  body: JSON.stringify({
78
72
  base_tree: shaBaseTree,
@@ -87,11 +81,9 @@ export class GithubBranch extends Branch {
87
81
  })
88
82
  });
89
83
 
90
- let json = await result.json();
91
-
92
84
  const shaNewTree = json.sha;
93
85
 
94
- result = await this.provider.fetch(`repos/${this.slug}/git/commits`, {
86
+ json = await this.provider.fetchJSON(`repos/${this.slug}/git/commits`, {
95
87
  method: "POST",
96
88
  body: JSON.stringify({
97
89
  message,
@@ -99,11 +91,10 @@ export class GithubBranch extends Branch {
99
91
  parents: [shaLatestCommit]
100
92
  })
101
93
  });
102
- json = await result.json();
103
94
 
104
95
  const sha = json.sha;
105
96
 
106
- result = await this.provider.fetch(
97
+ return await this.provider.fetchJSON(
107
98
  `repos/${this.slug}/git/refs/heads/${this.name}`,
108
99
  {
109
100
  method: "PATCH",
@@ -113,8 +104,6 @@ export class GithubBranch extends Branch {
113
104
  })
114
105
  }
115
106
  );
116
-
117
- return result.json();
118
107
  }
119
108
 
120
109
  /**
@@ -122,16 +111,11 @@ export class GithubBranch extends Branch {
122
111
  * @param {string} name
123
112
  */
124
113
  async entry(name) {
125
- const res = await this.provider.fetch(
114
+ const json = await this.provider.fetchJSON(
126
115
  `repos/${this.slug}/contents/${name}?ref=${this.ref}`
127
116
  );
128
117
 
129
- if (res.ok) {
130
- const json = await res.json();
131
- return new this.entryClass(name, Buffer.from(json.content, "base64"));
132
- }
133
-
134
- throw new Error(res.status);
118
+ return new this.entryClass(name, Buffer.from(json.content, "base64"));
135
119
  }
136
120
 
137
121
  /** @inheritdoc */
@@ -164,7 +148,7 @@ export class GithubBranch extends Branch {
164
148
  } catch (e) {
165
149
  // errno: 'ERR_STREAM_PREMATURE_CLOSE',
166
150
  // code: 'ERR_STREAM_PREMATURE_CLOSE',
167
-
151
+
168
152
  this.error(e);
169
153
  }
170
154
  }
@@ -220,11 +204,10 @@ class LazyBufferContentEntry extends BufferContentEntryMixin(ContentEntry) {
220
204
  }
221
205
 
222
206
  const branch = this.branch;
223
- const res = await branch.provider.fetch(
207
+ const json = await branch.provider.fetchJSON(
224
208
  `repos/${branch.slug}/contents/${this.name}?ref=${branch.ref}`
225
209
  );
226
210
 
227
- const json = await res.json();
228
211
  this._buffer = Buffer.from(json.content, "base64");
229
212
  return this._buffer;
230
213
  }
@@ -121,8 +121,7 @@ export class GithubProvider extends MultiGroupProvider {
121
121
  try {
122
122
  const response = await this.fetch(url, options);
123
123
  if (!response.ok) {
124
- this.error(`Unable to fetch ${response.status} ${response.url}`);
125
- throw new Error(`Unable to fetch ${response.status} ${response.url}`);
124
+ throw new Error(`Unable to fetch ${response.url} (${response.status})`);
126
125
  }
127
126
  return await response.json();
128
127
  } catch (e) {
@@ -72,7 +72,7 @@ export class GithubPullRequest extends PullRequest {
72
72
  return p;
73
73
  }
74
74
 
75
- const res = await destination.provider.fetch(
75
+ const json = await destination.provider.fetchJSON(
76
76
  `repos/${destination.repository.slug}/pulls`,
77
77
  {
78
78
  method: "POST",
@@ -84,13 +84,7 @@ export class GithubPullRequest extends PullRequest {
84
84
  }
85
85
  );
86
86
 
87
- const json = await res.json();
88
-
89
- if (res.ok) {
90
- return new this(source, destination, json.number, json);
91
- }
92
-
93
- throw new Error(json.errors.map(e => e.message).join(";"));
87
+ return new this(source, destination, json.number, json);
94
88
  }
95
89
 
96
90
  /**
@@ -112,13 +112,7 @@ export class GithubRepository extends Repository {
112
112
  async refId(ref) {
113
113
  ref = ref.replace(/^refs\//, "");
114
114
 
115
- const res = await this.provider.fetch(`repos/${this.slug}/git/ref/${ref}`);
116
-
117
- if (!res.ok) {
118
- throw new Error(`Unable to fetch ${res.url}: ${res.code}`);
119
- }
120
-
121
- const json = await res.json();
115
+ const json = await this.provider.fetchJSON(`repos/${this.slug}/git/ref/${ref}`);
122
116
 
123
117
  // TODO why does this happen ?
124
118
  if (!json.object.sha) {
@@ -153,12 +147,11 @@ export class GithubRepository extends Repository {
153
147
  console.log(res);
154
148
  */
155
149
  } else {
156
- const res = await this.provider.fetch(
150
+ const json = await this.provider.fetchJSON(
157
151
  `repos/${this.slug}/git/ref/heads/${
158
152
  from === undefined ? this.defaultBranchName : from.name
159
153
  }`
160
154
  );
161
- let json = await res.json();
162
155
  sha = json.object.sha;
163
156
  }
164
157