github-repository-provider 7.30.19 → 7.30.22

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
@@ -40,17 +40,15 @@ console.log(entry.name);
40
40
  * [Parameters](#parameters-1)
41
41
  * [commitForSha](#commitforsha)
42
42
  * [Parameters](#parameters-2)
43
- * [tree](#tree)
44
- * [Parameters](#parameters-3)
45
43
  * [entry](#entry)
46
- * [Parameters](#parameters-4)
44
+ * [Parameters](#parameters-3)
47
45
  * [removeEntries](#removeentries)
48
- * [Parameters](#parameters-5)
46
+ * [Parameters](#parameters-4)
49
47
  * [GithubOwner](#githubowner)
50
48
  * [createRepository](#createrepository)
51
- * [Parameters](#parameters-6)
49
+ * [Parameters](#parameters-5)
52
50
  * [deleteRepository](#deleterepository)
53
- * [Parameters](#parameters-7)
51
+ * [Parameters](#parameters-6)
54
52
  * [attributeMapping](#attributemapping)
55
53
  * [GithubProvider](#githubprovider)
56
54
  * [Examples](#examples)
@@ -60,17 +58,21 @@ console.log(entry.name);
60
58
  * [instanceIdentifier](#instanceidentifier)
61
59
  * [GithubPullRequest](#githubpullrequest)
62
60
  * [\_merge](#\_merge)
63
- * [Parameters](#parameters-8)
61
+ * [Parameters](#parameters-7)
64
62
  * [update](#update)
65
63
  * [validMergeMethods](#validmergemethods)
66
64
  * [list](#list)
67
- * [Parameters](#parameters-9)
65
+ * [Parameters](#parameters-8)
68
66
  * [open](#open)
69
- * [Parameters](#parameters-10)
67
+ * [Parameters](#parameters-9)
70
68
  * [GithubRepository](#githubrepository)
71
69
  * [defaultBranchName](#defaultbranchname)
72
70
  * [commits](#commits)
71
+ * [Parameters](#parameters-10)
72
+ * [tree](#tree)
73
73
  * [Parameters](#parameters-11)
74
+ * [addTree](#addtree)
75
+ * [Parameters](#parameters-12)
74
76
  * [initializeBranches](#initializebranches)
75
77
  * [initializeTags](#initializetags)
76
78
  * [url](#url)
@@ -79,9 +81,9 @@ console.log(entry.name);
79
81
  * [api](#api)
80
82
  * [update](#update-1)
81
83
  * [refId](#refid)
82
- * [Parameters](#parameters-12)
83
- * [deletePullRequest](#deletepullrequest)
84
84
  * [Parameters](#parameters-13)
85
+ * [deletePullRequest](#deletepullrequest)
86
+ * [Parameters](#parameters-14)
85
87
  * [initializeHooks](#initializehooks)
86
88
 
87
89
  ## GithubBranch
@@ -123,16 +125,6 @@ Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/
123
125
 
124
126
  Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** response
125
127
 
126
- ### tree
127
-
128
- * **See**: <https://developer.github.com/v3/git/trees/>
129
-
130
- #### Parameters
131
-
132
- * `sha` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
133
-
134
- Returns **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)>**
135
-
136
128
  ### entry
137
129
 
138
130
  <https://developer.github.com/v3/repos/contents/#get-repository-content>
@@ -296,6 +288,27 @@ Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G
296
288
 
297
289
  Returns **AsyncIterator\<Commit>**
298
290
 
291
+ ### tree
292
+
293
+ * **See**: <https://developer.github.com/v3/git/trees/>
294
+
295
+ #### Parameters
296
+
297
+ * `sha` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
298
+
299
+ Returns **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)>**
300
+
301
+ ### addTree
302
+
303
+ * **See**: <https://developer.github.com/v3/git/trees/>
304
+
305
+ #### Parameters
306
+
307
+ * `updates` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)>**
308
+ * `base` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** base tree sha
309
+
310
+ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** newly created tree
311
+
299
312
  ### initializeBranches
300
313
 
301
314
  <https://developer.github.com/v3/repos/branches/#list-branches>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "github-repository-provider",
3
- "version": "7.30.19",
3
+ "version": "7.30.22",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -36,7 +36,7 @@
36
36
  "matching-iterator": "^2.0.6",
37
37
  "node-fetch": "^3.2.6",
38
38
  "one-time-execution-method": "^3.0.3",
39
- "repository-provider": "^31.2.7"
39
+ "repository-provider": "^31.2.8"
40
40
  },
41
41
  "devDependencies": {
42
42
  "ava": "^4.3.0",
@@ -11,7 +11,6 @@ import {
11
11
  */
12
12
  export class GithubBranch extends Branch {
13
13
  #entries = new Map();
14
- #commits = new Map();
15
14
 
16
15
  /**
17
16
  * Writes content into the branch
@@ -44,10 +43,6 @@ export class GithubBranch extends Branch {
44
43
  * @param {Object} options
45
44
  */
46
45
  async commit(message, entries, options) {
47
- const updates = await Promise.all(
48
- entries.map(entry => this.writeEntry(entry))
49
- );
50
-
51
46
  /*
52
47
  * 1st. commit on empty tree
53
48
  * https://stackoverflow.com/questions/9765453/is-gits-semi-secret-empty-tree-object-reliable-and-why-is-there-not-a-symbolic/9766506#9766506
@@ -56,42 +51,20 @@ export class GithubBranch extends Branch {
56
51
  * sha256:6ef19b41225c5369f1c104d45d8d85efa9b057b53b14b4b9b939dd74decc5321
57
52
  */
58
53
 
59
- const shaLatestCommit = await this.refId();
60
- const commit = await this.commitForSha(shaLatestCommit);
61
- const tree = await this.owner.addTree(updates, commit.tree.sha);
62
-
63
- let r = await this.provider.fetchJSON(`${this.api}/git/commits`, {
64
- method: "POST",
65
- body: JSON.stringify({
66
- message,
67
- tree: tree.sha,
68
- parents: [shaLatestCommit]
69
- })
70
- });
71
-
72
- this.#commits.set(r.json.sha, r.json);
73
-
74
- return this.owner.setRefId(this.ref, r.json.sha, options);
75
- }
76
-
77
- /**
78
- * {@link https://developer.github.com/v3/git/commits/#get-a-commit}
79
- * @param {string} sha
80
- * @return {Object} response
81
- */
82
- async commitForSha(sha) {
83
- const commit = this.#commits.get(sha);
84
- if (commit) {
85
- return commit;
86
- }
87
-
88
- const { json } = await this.provider.fetchJSON(
89
- `${this.api}/git/commits/${sha}`
54
+ const updates = await Promise.all(
55
+ entries.map(entry => this.writeEntry(entry))
90
56
  );
91
57
 
92
- this.#commits.set(sha, json);
58
+ const shaLatestCommit = await this.refId();
59
+ const latestCommit = await this.owner.commitForSha(shaLatestCommit);
60
+ const tree = await this.owner.addTree(updates, latestCommit.tree.sha);
61
+ const commit = await this.owner.addCommit(
62
+ tree.sha,
63
+ [shaLatestCommit],
64
+ message
65
+ );
93
66
 
94
- return json;
67
+ return this.owner.setRefId(this.ref, commit.sha, options);
95
68
  }
96
69
 
97
70
  /**
@@ -126,7 +99,7 @@ export class GithubBranch extends Branch {
126
99
  }
127
100
 
128
101
  async *entries(patterns) {
129
- const commit = await this.commitForSha(await this.refId());
102
+ const commit = await this.owner.commitForSha(await this.refId());
130
103
 
131
104
  for (const entry of matcher(
132
105
  await this.owner.tree(commit.tree.sha),
@@ -14,6 +14,7 @@ const conflictErrorActions = {
14
14
  export class GithubRepository extends Repository {
15
15
  #refs = new Map();
16
16
  #trees = new Map();
17
+ #commits = new Map();
17
18
 
18
19
  static get attributeMapping() {
19
20
  return {
@@ -62,6 +63,8 @@ export class GithubRepository extends Repository {
62
63
  const { response, json } = await this.provider.fetchJSON(next);
63
64
 
64
65
  for (const c of json) {
66
+ this.#commits.set(c.sha, json);
67
+
65
68
  yield {
66
69
  sha: c.sha,
67
70
  message: c.message,
@@ -73,6 +76,40 @@ export class GithubRepository extends Repository {
73
76
  } while (next);
74
77
  }
75
78
 
79
+ async addCommit(tree, parents, message) {
80
+ let r = await this.provider.fetchJSON(`${this.api}/git/commits`, {
81
+ method: "POST",
82
+ body: JSON.stringify({
83
+ tree,
84
+ parents,
85
+ message
86
+ })
87
+ });
88
+
89
+ this.#commits.set(r.json.sha, r.json);
90
+ return r.json;
91
+ }
92
+
93
+ /**
94
+ * {@link https://developer.github.com/v3/git/commits/#get-a-commit}
95
+ * @param {string} sha
96
+ * @return {Object} response
97
+ */
98
+ async commitForSha(sha) {
99
+ const commit = this.#commits.get(sha);
100
+ if (commit) {
101
+ return commit;
102
+ }
103
+
104
+ const { json } = await this.provider.fetchJSON(
105
+ `${this.api}/git/commits/${sha}`
106
+ );
107
+
108
+ this.#commits.set(sha, json);
109
+
110
+ return json;
111
+ }
112
+
76
113
  /**
77
114
  * @see https://developer.github.com/v3/git/trees/
78
115
  * @param {string} sha
@@ -97,7 +134,7 @@ export class GithubRepository extends Repository {
97
134
 
98
135
  /**
99
136
  * @see https://developer.github.com/v3/git/trees/
100
- * @param {Object[]} updates
137
+ * @param {Object[]} updates
101
138
  * @param {string} base base tree sha
102
139
  * @returns {Object} newly created tree
103
140
  */
@@ -222,11 +259,19 @@ export class GithubRepository extends Repository {
222
259
  return sha;
223
260
  }
224
261
 
225
- // TODO belongs into Ref ?
262
+ /**
263
+ * {@link https://docs.github.com/en/github-ae@latest/rest/git/refs#update-a-reference}
264
+ * @param {string} ref
265
+ * @param {string} sha
266
+ * @param {Object} options
267
+ * @returns
268
+ *
269
+ * @TODO: belongs into Ref ?
270
+ */
226
271
  async setRefId(ref, sha, options) {
227
- //console.log("NEW HEAD", sha, ref);
272
+ ref = ref.replace(/^refs\//, "");
228
273
 
229
- const r = await this.provider.fetchJSON(`${this.api}/git/${ref}`, {
274
+ const r = await this.provider.fetchJSON(`${this.api}/git/refs/${ref}`, {
230
275
  method: "PATCH",
231
276
  body: JSON.stringify({
232
277
  ...options,
@@ -234,8 +279,6 @@ export class GithubRepository extends Repository {
234
279
  })
235
280
  });
236
281
 
237
- console.log(ref, sha, r.response.ok, r.response.status, r.json);
238
-
239
282
  if (r.response.ok) {
240
283
  this.#refs.set(ref, sha);
241
284
  return r.json;
@@ -270,7 +313,6 @@ export class GithubRepository extends Repository {
270
313
  tree: sha
271
314
  })
272
315
  });
273
- console.log(res);
274
316
  */
275
317
  }
276
318