github-repository-provider 7.30.15 → 7.30.18
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 +12 -12
- package/package.json +3 -3
- package/src/github-branch.mjs +49 -64
- package/src/github-repository.mjs +7 -11
package/README.md
CHANGED
|
@@ -38,11 +38,11 @@ console.log(entry.name);
|
|
|
38
38
|
* [Parameters](#parameters)
|
|
39
39
|
* [commit](#commit)
|
|
40
40
|
* [Parameters](#parameters-1)
|
|
41
|
-
* [entry](#entry)
|
|
42
|
-
* [Parameters](#parameters-2)
|
|
43
41
|
* [commitForSha](#commitforsha)
|
|
44
|
-
* [Parameters](#parameters-
|
|
42
|
+
* [Parameters](#parameters-2)
|
|
45
43
|
* [tree](#tree)
|
|
44
|
+
* [Parameters](#parameters-3)
|
|
45
|
+
* [entry](#entry)
|
|
46
46
|
* [Parameters](#parameters-4)
|
|
47
47
|
* [removeEntries](#removeentries)
|
|
48
48
|
* [Parameters](#parameters-5)
|
|
@@ -111,15 +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)**
|
|
115
|
-
|
|
116
|
-
### entry
|
|
117
|
-
|
|
118
|
-
<https://developer.github.com/v3/repos/contents/#get-repository-content>
|
|
119
|
-
|
|
120
|
-
#### Parameters
|
|
121
|
-
|
|
122
|
-
* `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
|
|
114
|
+
* `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
|
|
123
115
|
|
|
124
116
|
### commitForSha
|
|
125
117
|
|
|
@@ -141,6 +133,14 @@ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G
|
|
|
141
133
|
|
|
142
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)>**
|
|
143
135
|
|
|
136
|
+
### entry
|
|
137
|
+
|
|
138
|
+
<https://developer.github.com/v3/repos/contents/#get-repository-content>
|
|
139
|
+
|
|
140
|
+
#### Parameters
|
|
141
|
+
|
|
142
|
+
* `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
|
|
143
|
+
|
|
144
144
|
### removeEntries
|
|
145
145
|
|
|
146
146
|
<https://developer.github.com/v3/repos/contents/>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "github-repository-provider",
|
|
3
|
-
"version": "7.30.
|
|
3
|
+
"version": "7.30.18",
|
|
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.
|
|
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.
|
|
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",
|
package/src/github-branch.mjs
CHANGED
|
@@ -10,9 +10,9 @@ import {
|
|
|
10
10
|
* Branch on GitHub.
|
|
11
11
|
*/
|
|
12
12
|
export class GithubBranch extends Branch {
|
|
13
|
-
#entries;
|
|
14
|
-
#
|
|
15
|
-
#
|
|
13
|
+
#entries = new Map();
|
|
14
|
+
#trees = new Map();
|
|
15
|
+
#commits = new Map();
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Writes content into the branch
|
|
@@ -29,9 +29,7 @@ export class GithubBranch extends Branch {
|
|
|
29
29
|
})
|
|
30
30
|
});
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
this.#entries.set(entry.name, entry);
|
|
34
|
-
}
|
|
32
|
+
this.#entries.set(entry.name, entry);
|
|
35
33
|
|
|
36
34
|
entry.sha = json.sha;
|
|
37
35
|
|
|
@@ -77,53 +75,21 @@ export class GithubBranch extends Branch {
|
|
|
77
75
|
})
|
|
78
76
|
});
|
|
79
77
|
|
|
80
|
-
|
|
78
|
+
const treeSHA = json.sha;
|
|
79
|
+
this.#trees.set(treeSHA, json);
|
|
81
80
|
|
|
82
81
|
let r = await this.provider.fetchJSON(`${this.api}/git/commits`, {
|
|
83
82
|
method: "POST",
|
|
84
83
|
body: JSON.stringify({
|
|
85
84
|
message,
|
|
86
|
-
tree:
|
|
85
|
+
tree: treeSHA,
|
|
87
86
|
parents: [shaLatestCommit]
|
|
88
87
|
})
|
|
89
88
|
});
|
|
90
89
|
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* {@link https://developer.github.com/v3/repos/contents/#get-repository-content}
|
|
96
|
-
* @param {string} name
|
|
97
|
-
*/
|
|
98
|
-
async entry(name) {
|
|
99
|
-
if (this.#entries) {
|
|
100
|
-
const entry = this.#entries.get(name);
|
|
101
|
-
if (entry) {
|
|
102
|
-
return entry;
|
|
103
|
-
}
|
|
104
|
-
} else {
|
|
105
|
-
this.#entries = new Map();
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const f = async () => {
|
|
109
|
-
const { json } = await this.provider.fetchJSON(
|
|
110
|
-
`${this.api}/contents/${name}?ref=${this.ref}`
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
const entry = new this.entryClass(
|
|
114
|
-
name,
|
|
115
|
-
Buffer.from(json.content, "base64")
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
this.#entries.set(name, entry);
|
|
119
|
-
return entry;
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
const p = f();
|
|
123
|
-
|
|
124
|
-
this.#entries.set(name, p);
|
|
90
|
+
this.#commits.set(r.json.sha, r.json);
|
|
125
91
|
|
|
126
|
-
return
|
|
92
|
+
return this.owner.setRefId(this.ref, r.json.sha, options);
|
|
127
93
|
}
|
|
128
94
|
|
|
129
95
|
/**
|
|
@@ -132,20 +98,16 @@ export class GithubBranch extends Branch {
|
|
|
132
98
|
* @return {Object} response
|
|
133
99
|
*/
|
|
134
100
|
async commitForSha(sha) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
return json;
|
|
139
|
-
}
|
|
140
|
-
} else {
|
|
141
|
-
this.#commitForSha = new Map();
|
|
101
|
+
const commit = this.#commits.get(sha);
|
|
102
|
+
if (commit) {
|
|
103
|
+
return commit;
|
|
142
104
|
}
|
|
143
105
|
|
|
144
106
|
const { json } = await this.provider.fetchJSON(
|
|
145
107
|
`${this.api}/git/commits/${sha}`
|
|
146
108
|
);
|
|
147
109
|
|
|
148
|
-
this.#
|
|
110
|
+
this.#commits.set(sha, json);
|
|
149
111
|
|
|
150
112
|
return json;
|
|
151
113
|
}
|
|
@@ -156,33 +118,56 @@ export class GithubBranch extends Branch {
|
|
|
156
118
|
* @return {Object[]}
|
|
157
119
|
*/
|
|
158
120
|
async tree(sha) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
return tree;
|
|
163
|
-
}
|
|
164
|
-
} else {
|
|
165
|
-
this.#tree = new Map();
|
|
121
|
+
let tree = this.#trees.get(sha);
|
|
122
|
+
if (tree) {
|
|
123
|
+
return tree;
|
|
166
124
|
}
|
|
167
125
|
|
|
168
126
|
const { json } = await this.provider.fetchJSON(
|
|
169
127
|
`${this.api}/git/trees/${sha}?recursive=1`
|
|
170
128
|
);
|
|
171
129
|
|
|
172
|
-
|
|
130
|
+
tree = json.tree;
|
|
173
131
|
|
|
174
|
-
this.#
|
|
132
|
+
this.#trees.set(sha, tree);
|
|
175
133
|
|
|
176
134
|
return tree;
|
|
177
135
|
}
|
|
178
136
|
|
|
137
|
+
/**
|
|
138
|
+
* {@link https://developer.github.com/v3/repos/contents/#get-repository-content}
|
|
139
|
+
* @param {string} name
|
|
140
|
+
*/
|
|
141
|
+
async entry(name) {
|
|
142
|
+
const entry = this.#entries.get(name);
|
|
143
|
+
if (entry) {
|
|
144
|
+
return entry;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const f = async () => {
|
|
148
|
+
const { json } = await this.provider.fetchJSON(
|
|
149
|
+
`${this.api}/contents/${name}?ref=${this.ref}`
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
const entry = new this.entryClass(
|
|
153
|
+
name,
|
|
154
|
+
Buffer.from(json.content, "base64")
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
this.#entries.set(name, entry);
|
|
158
|
+
return entry;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
const p = f();
|
|
162
|
+
|
|
163
|
+
this.#entries.set(name, p);
|
|
164
|
+
|
|
165
|
+
return p;
|
|
166
|
+
}
|
|
167
|
+
|
|
179
168
|
async *entries(patterns) {
|
|
180
169
|
const commit = await this.commitForSha(await this.refId());
|
|
181
170
|
|
|
182
|
-
if (!this.#entries) {
|
|
183
|
-
this.#entries = new Map();
|
|
184
|
-
}
|
|
185
|
-
|
|
186
171
|
for (const entry of matcher(await this.tree(commit.tree.sha), patterns, {
|
|
187
172
|
name: "path"
|
|
188
173
|
})) {
|
|
@@ -12,6 +12,8 @@ const conflictErrorActions = {
|
|
|
12
12
|
* Repository on GitHub.
|
|
13
13
|
*/
|
|
14
14
|
export class GithubRepository extends Repository {
|
|
15
|
+
#ref = new Map();
|
|
16
|
+
|
|
15
17
|
static get attributeMapping() {
|
|
16
18
|
return {
|
|
17
19
|
...super.attributeMapping,
|
|
@@ -140,8 +142,6 @@ export class GithubRepository extends Repository {
|
|
|
140
142
|
});
|
|
141
143
|
}
|
|
142
144
|
|
|
143
|
-
#ref;
|
|
144
|
-
|
|
145
145
|
/**
|
|
146
146
|
* Get sha of a ref.
|
|
147
147
|
* {@link https://developer.github.com/v3/git/refs/}
|
|
@@ -151,13 +151,9 @@ export class GithubRepository extends Repository {
|
|
|
151
151
|
async refId(ref) {
|
|
152
152
|
ref = ref.replace(/^refs\//, "");
|
|
153
153
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
return sha;
|
|
158
|
-
}
|
|
159
|
-
} else {
|
|
160
|
-
this.#ref = new Map();
|
|
154
|
+
let sha = this.#ref.get(ref);
|
|
155
|
+
if (sha) {
|
|
156
|
+
return sha;
|
|
161
157
|
}
|
|
162
158
|
|
|
163
159
|
const { response, json } = await this.provider.fetchJSON(
|
|
@@ -169,7 +165,7 @@ export class GithubRepository extends Repository {
|
|
|
169
165
|
throw new Error(`No refId for '${this.fullName}' '${ref}'`);
|
|
170
166
|
}
|
|
171
167
|
|
|
172
|
-
|
|
168
|
+
sha = json.object.sha;
|
|
173
169
|
|
|
174
170
|
this.#ref.set(ref, sha);
|
|
175
171
|
|
|
@@ -192,7 +188,7 @@ export class GithubRepository extends Repository {
|
|
|
192
188
|
this.#ref.set(ref, sha);
|
|
193
189
|
}
|
|
194
190
|
|
|
195
|
-
//console.log(r.response.ok, r.response.status, r.json);
|
|
191
|
+
//console.log(ref, sha, r.response.ok, r.response.status, r.json);
|
|
196
192
|
|
|
197
193
|
return r.json;
|
|
198
194
|
}
|