github-repository-provider 7.30.18 → 7.30.19

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.30.18",
3
+ "version": "7.30.19",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -11,7 +11,6 @@ import {
11
11
  */
12
12
  export class GithubBranch extends Branch {
13
13
  #entries = new Map();
14
- #trees = new Map();
15
14
  #commits = new Map();
16
15
 
17
16
  /**
@@ -59,30 +58,13 @@ export class GithubBranch extends Branch {
59
58
 
60
59
  const shaLatestCommit = await this.refId();
61
60
  const commit = await this.commitForSha(shaLatestCommit);
62
-
63
- let { json } = await this.provider.fetchJSON(`${this.api}/git/trees`, {
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
- })
75
- })
76
- });
77
-
78
- const treeSHA = json.sha;
79
- this.#trees.set(treeSHA, json);
61
+ const tree = await this.owner.addTree(updates, commit.tree.sha);
80
62
 
81
63
  let r = await this.provider.fetchJSON(`${this.api}/git/commits`, {
82
64
  method: "POST",
83
65
  body: JSON.stringify({
84
66
  message,
85
- tree: treeSHA,
67
+ tree: tree.sha,
86
68
  parents: [shaLatestCommit]
87
69
  })
88
70
  });
@@ -112,28 +94,6 @@ export class GithubBranch extends Branch {
112
94
  return json;
113
95
  }
114
96
 
115
- /**
116
- * @see https://developer.github.com/v3/git/trees/
117
- * @param {string} sha
118
- * @return {Object[]}
119
- */
120
- async tree(sha) {
121
- let tree = this.#trees.get(sha);
122
- if (tree) {
123
- return tree;
124
- }
125
-
126
- const { json } = await this.provider.fetchJSON(
127
- `${this.api}/git/trees/${sha}?recursive=1`
128
- );
129
-
130
- tree = json.tree;
131
-
132
- this.#trees.set(sha, tree);
133
-
134
- return tree;
135
- }
136
-
137
97
  /**
138
98
  * {@link https://developer.github.com/v3/repos/contents/#get-repository-content}
139
99
  * @param {string} name
@@ -168,9 +128,13 @@ export class GithubBranch extends Branch {
168
128
  async *entries(patterns) {
169
129
  const commit = await this.commitForSha(await this.refId());
170
130
 
171
- for (const entry of matcher(await this.tree(commit.tree.sha), patterns, {
172
- name: "path"
173
- })) {
131
+ for (const entry of matcher(
132
+ await this.owner.tree(commit.tree.sha),
133
+ patterns,
134
+ {
135
+ name: "path"
136
+ }
137
+ )) {
174
138
  switch (entry.type) {
175
139
  case "tree":
176
140
  yield new BaseCollectionEntry(entry.path);
@@ -12,7 +12,8 @@ const conflictErrorActions = {
12
12
  * Repository on GitHub.
13
13
  */
14
14
  export class GithubRepository extends Repository {
15
- #ref = new Map();
15
+ #refs = new Map();
16
+ #trees = new Map();
16
17
 
17
18
  static get attributeMapping() {
18
19
  return {
@@ -72,6 +73,55 @@ export class GithubRepository extends Repository {
72
73
  } while (next);
73
74
  }
74
75
 
76
+ /**
77
+ * @see https://developer.github.com/v3/git/trees/
78
+ * @param {string} sha
79
+ * @return {Object[]}
80
+ */
81
+ async tree(sha) {
82
+ let tree = this.#trees.get(sha);
83
+ if (tree) {
84
+ return tree;
85
+ }
86
+
87
+ const { json } = await this.provider.fetchJSON(
88
+ `${this.api}/git/trees/${sha}?recursive=1`
89
+ );
90
+
91
+ tree = json.tree;
92
+
93
+ this.#trees.set(sha, tree);
94
+
95
+ return tree;
96
+ }
97
+
98
+ /**
99
+ * @see https://developer.github.com/v3/git/trees/
100
+ * @param {Object[]} updates
101
+ * @param {string} base base tree sha
102
+ * @returns {Object} newly created tree
103
+ */
104
+ async addTree(updates, base) {
105
+ let { json } = await this.provider.fetchJSON(`${this.api}/git/trees`, {
106
+ method: "POST",
107
+ body: JSON.stringify({
108
+ base_tree: base,
109
+ tree: updates.map(u => {
110
+ return {
111
+ path: u.name,
112
+ sha: u.sha,
113
+ type: "blob",
114
+ mode: "100" + u.mode.toString(8)
115
+ };
116
+ })
117
+ })
118
+ });
119
+
120
+ this.#trees.set(json.sha, json);
121
+
122
+ return json;
123
+ }
124
+
75
125
  async #initializeSlot(typeName, addMethodName) {
76
126
  let next = `${this.api}/${typeName}`;
77
127
 
@@ -151,7 +201,7 @@ export class GithubRepository extends Repository {
151
201
  async refId(ref) {
152
202
  ref = ref.replace(/^refs\//, "");
153
203
 
154
- let sha = this.#ref.get(ref);
204
+ let sha = this.#refs.get(ref);
155
205
  if (sha) {
156
206
  return sha;
157
207
  }
@@ -167,7 +217,7 @@ export class GithubRepository extends Repository {
167
217
 
168
218
  sha = json.object.sha;
169
219
 
170
- this.#ref.set(ref, sha);
220
+ this.#refs.set(ref, sha);
171
221
 
172
222
  return sha;
173
223
  }
@@ -184,13 +234,12 @@ export class GithubRepository extends Repository {
184
234
  })
185
235
  });
186
236
 
187
- if (r.response.ok && this.#ref) {
188
- this.#ref.set(ref, sha);
189
- }
190
-
191
- //console.log(ref, sha, r.response.ok, r.response.status, r.json);
237
+ console.log(ref, sha, r.response.ok, r.response.status, r.json);
192
238
 
193
- return r.json;
239
+ if (r.response.ok) {
240
+ this.#refs.set(ref, sha);
241
+ return r.json;
242
+ }
194
243
  }
195
244
 
196
245
  async createBranch(name, from, options) {