github-repository-provider 7.30.13 → 7.30.16

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/README.md CHANGED
@@ -111,7 +111,7 @@ Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/
111
111
 
112
112
  * `message` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
113
113
  * `entries` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)\<ContentEntry>**
114
- * `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** (optional, default `{}`)
114
+ * `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
115
115
 
116
116
  ### entry
117
117
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "github-repository-provider",
3
- "version": "7.30.13",
3
+ "version": "7.30.16",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -32,7 +32,7 @@
32
32
  "dependencies": {
33
33
  "content-entry": "^5.0.6",
34
34
  "fetch-link-util": "^1.0.10",
35
- "fetch-rate-limit-util": "^3.0.13",
35
+ "fetch-rate-limit-util": "^3.0.14",
36
36
  "matching-iterator": "^2.0.6",
37
37
  "node-fetch": "^3.2.6",
38
38
  "one-time-execution-method": "^3.0.3",
@@ -42,7 +42,7 @@
42
42
  "ava": "^4.3.0",
43
43
  "c8": "^7.11.3",
44
44
  "documentation": "^13.2.5",
45
- "etag-cache-leveldb": "^1.2.2",
45
+ "etag-cache-leveldb": "^1.2.4",
46
46
  "leveldown": "^6.1.1",
47
47
  "levelup": "^5.1.1",
48
48
  "repository-provider-test-support": "^2.2.5",
@@ -10,7 +10,10 @@ import {
10
10
  * Branch on GitHub.
11
11
  */
12
12
  export class GithubBranch extends Branch {
13
-
13
+ #entries;
14
+ #tree;
15
+ #commitForSha;
16
+
14
17
  /**
15
18
  * Writes content into the branch
16
19
  * {@link https://developer.github.com/v3/git/blobs/#get-a-blob}
@@ -18,16 +21,17 @@ export class GithubBranch extends Branch {
18
21
  * @return {Promise<ContentEntry>} written content with sha values set
19
22
  */
20
23
  async writeEntry(entry) {
21
- const { json } = await this.provider.fetchJSON(
22
- `${this.api}/git/blobs`,
23
- {
24
- method: "POST",
25
- body: JSON.stringify({
26
- content: await entry.string,
27
- encoding: "utf8"
28
- })
29
- }
30
- );
24
+ const { json } = await this.provider.fetchJSON(`${this.api}/git/blobs`, {
25
+ method: "POST",
26
+ body: JSON.stringify({
27
+ content: await entry.string,
28
+ encoding: "utf8"
29
+ })
30
+ });
31
+
32
+ if (this.#entries) {
33
+ this.#entries.set(entry.name, entry);
34
+ }
31
35
 
32
36
  entry.sha = json.sha;
33
37
 
@@ -42,7 +46,7 @@ export class GithubBranch extends Branch {
42
46
  * @param {ContentEntry[]} entries
43
47
  * @param {Object} options
44
48
  */
45
- async commit(message, entries, options = {}) {
49
+ async commit(message, entries, options) {
46
50
  const updates = await Promise.all(
47
51
  entries.map(entry => this.writeEntry(entry))
48
52
  );
@@ -58,23 +62,22 @@ export class GithubBranch extends Branch {
58
62
  const shaLatestCommit = await this.refId();
59
63
  const commit = await this.commitForSha(shaLatestCommit);
60
64
 
61
- let { json } = await this.provider.fetchJSON(
62
- `${this.api}/git/trees`,
63
- {
64
- method: "POST",
65
- body: JSON.stringify({
66
- base_tree: commit.tree.sha,
67
- tree: updates.map(u => {
68
- return {
69
- path: u.name,
70
- sha: u.sha,
71
- type: "blob",
72
- mode: "100" + u.mode.toString(8)
73
- };
74
- })
65
+ let { json } = await this.provider.fetchJSON(`${this.api}/git/trees`, {
66
+ method: "POST",
67
+ body: JSON.stringify({
68
+ base_tree: commit.tree.sha,
69
+ tree: updates.map(u => {
70
+ return {
71
+ path: u.name,
72
+ sha: u.sha,
73
+ type: "blob",
74
+ mode: "100" + u.mode.toString(8)
75
+ };
75
76
  })
76
- }
77
- );
77
+ })
78
+ });
79
+
80
+ //console.log("TREE", json.sha, shaLatestCommit);
78
81
 
79
82
  let r = await this.provider.fetchJSON(`${this.api}/git/commits`, {
80
83
  method: "POST",
@@ -85,21 +88,9 @@ export class GithubBranch extends Branch {
85
88
  })
86
89
  });
87
90
 
88
- r = await this.provider.fetchJSON(`${this.api}/git/${this.ref}`, {
89
- method: "PATCH",
90
- body: JSON.stringify({
91
- ...options,
92
- sha: r.json.sha
93
- })
94
- });
95
-
96
- return r.json;
91
+ return this.owner.setRefId(this.ref, r.json.sha, options);
97
92
  }
98
93
 
99
- #entries;
100
- #tree;
101
- #commitForSha;
102
-
103
94
  /**
104
95
  * {@link https://developer.github.com/v3/repos/contents/#get-repository-content}
105
96
  * @param {string} name
@@ -115,7 +106,9 @@ export class GithubBranch extends Branch {
115
106
  }
116
107
 
117
108
  const f = async () => {
118
- const { json } = await this.provider.fetchJSON(`${this.api}/contents/${name}?ref=${this.ref}`);
109
+ const { json } = await this.provider.fetchJSON(
110
+ `${this.api}/contents/${name}?ref=${this.ref}`
111
+ );
119
112
 
120
113
  const entry = new this.entryClass(
121
114
  name,
@@ -148,7 +141,9 @@ export class GithubBranch extends Branch {
148
141
  this.#commitForSha = new Map();
149
142
  }
150
143
 
151
- const { json } = await this.provider.fetchJSON(`${this.api}/git/commits/${sha}`);
144
+ const { json } = await this.provider.fetchJSON(
145
+ `${this.api}/git/commits/${sha}`
146
+ );
152
147
 
153
148
  this.#commitForSha.set(sha, json);
154
149
 
@@ -170,7 +165,9 @@ export class GithubBranch extends Branch {
170
165
  this.#tree = new Map();
171
166
  }
172
167
 
173
- const { json } = await this.provider.fetchJSON(`${this.api}/git/trees/${sha}?recursive=1`);
168
+ const { json } = await this.provider.fetchJSON(
169
+ `${this.api}/git/trees/${sha}?recursive=1`
170
+ );
174
171
 
175
172
  const tree = json.tree;
176
173
 
@@ -234,7 +231,7 @@ class LazyBufferContentEntry extends BufferContentEntryMixin(ContentEntry) {
234
231
  }
235
232
 
236
233
  #buffer;
237
-
234
+
238
235
  async getBuffer() {
239
236
  if (this.#buffer) {
240
237
  return this.#buffer;
@@ -19,7 +19,7 @@ export class GithubPullRequest extends PullRequest {
19
19
  url: "api"
20
20
  };
21
21
  }
22
-
22
+
23
23
  static get attributes() {
24
24
  return {
25
25
  ...super.attributes,
@@ -79,6 +79,7 @@ export class GithubPullRequest extends PullRequest {
79
79
  return p;
80
80
  }
81
81
 
82
+
82
83
  const { response, json } = await destination.provider.fetchJSON(
83
84
  `${destination.repository.api}/pulls`,
84
85
  {
@@ -90,10 +91,11 @@ export class GithubPullRequest extends PullRequest {
90
91
  })
91
92
  }
92
93
  );
93
- if(!response.ok) {
94
- throw new Error(response.statusText);
95
- }
96
-
94
+
95
+ if (!response.ok) {
96
+ throw new Error(response.statusText);
97
+ }
98
+
97
99
  return new this(source, destination, json.number, json);
98
100
  }
99
101
 
@@ -176,6 +176,27 @@ export class GithubRepository extends Repository {
176
176
  return sha;
177
177
  }
178
178
 
179
+ // TODO belongs into Ref ?
180
+ async setRefId(ref, sha, options) {
181
+ //console.log("NEW HEAD", sha, ref);
182
+
183
+ const r = await this.provider.fetchJSON(`${this.api}/git/${ref}`, {
184
+ method: "PATCH",
185
+ body: JSON.stringify({
186
+ ...options,
187
+ sha
188
+ })
189
+ });
190
+
191
+ if (r.response.ok && this.#ref) {
192
+ this.#ref.set(ref, sha);
193
+ }
194
+
195
+ //console.log(r.response.ok, r.response.status, r.json);
196
+
197
+ return r.json;
198
+ }
199
+
179
200
  async createBranch(name, from, options) {
180
201
  await this.initializeBranches();
181
202