github-repository-provider 7.30.14 → 7.30.17
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 +1 -1
- package/package.json +3 -3
- package/src/github-branch.mjs +52 -73
- package/src/github-pull-request.mjs +7 -5
- package/src/github-repository.mjs +21 -0
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)**
|
|
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.
|
|
3
|
+
"version": "7.30.17",
|
|
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,6 +10,10 @@ import {
|
|
|
10
10
|
* Branch on GitHub.
|
|
11
11
|
*/
|
|
12
12
|
export class GithubBranch extends Branch {
|
|
13
|
+
#entries = new Map();
|
|
14
|
+
#trees = new Map();
|
|
15
|
+
#commits = new Map();
|
|
16
|
+
|
|
13
17
|
/**
|
|
14
18
|
* Writes content into the branch
|
|
15
19
|
* {@link https://developer.github.com/v3/git/blobs/#get-a-blob}
|
|
@@ -25,9 +29,7 @@ export class GithubBranch extends Branch {
|
|
|
25
29
|
})
|
|
26
30
|
});
|
|
27
31
|
|
|
28
|
-
|
|
29
|
-
this.#entries.set(entry.name, entry);
|
|
30
|
-
}
|
|
32
|
+
this.#entries.set(entry.name, entry);
|
|
31
33
|
|
|
32
34
|
entry.sha = json.sha;
|
|
33
35
|
|
|
@@ -42,7 +44,7 @@ export class GithubBranch extends Branch {
|
|
|
42
44
|
* @param {ContentEntry[]} entries
|
|
43
45
|
* @param {Object} options
|
|
44
46
|
*/
|
|
45
|
-
async commit(message, entries, options
|
|
47
|
+
async commit(message, entries, options) {
|
|
46
48
|
const updates = await Promise.all(
|
|
47
49
|
entries.map(entry => this.writeEntry(entry))
|
|
48
50
|
);
|
|
@@ -73,63 +75,21 @@ export class GithubBranch extends Branch {
|
|
|
73
75
|
})
|
|
74
76
|
});
|
|
75
77
|
|
|
78
|
+
const treeSHA = json.sha;
|
|
79
|
+
this.#trees.set(treeSHA, json);
|
|
80
|
+
|
|
76
81
|
let r = await this.provider.fetchJSON(`${this.api}/git/commits`, {
|
|
77
82
|
method: "POST",
|
|
78
83
|
body: JSON.stringify({
|
|
79
84
|
message,
|
|
80
|
-
tree:
|
|
85
|
+
tree: treeSHA,
|
|
81
86
|
parents: [shaLatestCommit]
|
|
82
87
|
})
|
|
83
88
|
});
|
|
84
89
|
|
|
85
|
-
|
|
86
|
-
method: "PATCH",
|
|
87
|
-
body: JSON.stringify({
|
|
88
|
-
...options,
|
|
89
|
-
sha: r.json.sha
|
|
90
|
-
})
|
|
91
|
-
});
|
|
90
|
+
this.#commits.set(r.json.sha, r.json);
|
|
92
91
|
|
|
93
|
-
return r.json;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
#entries;
|
|
97
|
-
#tree;
|
|
98
|
-
#commitForSha;
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* {@link https://developer.github.com/v3/repos/contents/#get-repository-content}
|
|
102
|
-
* @param {string} name
|
|
103
|
-
*/
|
|
104
|
-
async entry(name) {
|
|
105
|
-
if (this.#entries) {
|
|
106
|
-
const entry = this.#entries.get(name);
|
|
107
|
-
if (entry) {
|
|
108
|
-
return entry;
|
|
109
|
-
}
|
|
110
|
-
} else {
|
|
111
|
-
this.#entries = new Map();
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const f = async () => {
|
|
115
|
-
const { json } = await this.provider.fetchJSON(
|
|
116
|
-
`${this.api}/contents/${name}?ref=${this.ref}`
|
|
117
|
-
);
|
|
118
|
-
|
|
119
|
-
const entry = new this.entryClass(
|
|
120
|
-
name,
|
|
121
|
-
Buffer.from(json.content, "base64")
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
this.#entries.set(name, entry);
|
|
125
|
-
return entry;
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
const p = f();
|
|
129
|
-
|
|
130
|
-
this.#entries.set(name, p);
|
|
131
|
-
|
|
132
|
-
return p;
|
|
92
|
+
return this.owner.setRefId(this.ref, r.json.sha, options);
|
|
133
93
|
}
|
|
134
94
|
|
|
135
95
|
/**
|
|
@@ -138,20 +98,16 @@ export class GithubBranch extends Branch {
|
|
|
138
98
|
* @return {Object} response
|
|
139
99
|
*/
|
|
140
100
|
async commitForSha(sha) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
return json;
|
|
145
|
-
}
|
|
146
|
-
} else {
|
|
147
|
-
this.#commitForSha = new Map();
|
|
101
|
+
const commit = this.#commits.get(sha);
|
|
102
|
+
if (commit) {
|
|
103
|
+
return commit;
|
|
148
104
|
}
|
|
149
105
|
|
|
150
106
|
const { json } = await this.provider.fetchJSON(
|
|
151
107
|
`${this.api}/git/commits/${sha}`
|
|
152
108
|
);
|
|
153
109
|
|
|
154
|
-
this.#
|
|
110
|
+
this.#commits.set(sha, json);
|
|
155
111
|
|
|
156
112
|
return json;
|
|
157
113
|
}
|
|
@@ -162,33 +118,56 @@ export class GithubBranch extends Branch {
|
|
|
162
118
|
* @return {Object[]}
|
|
163
119
|
*/
|
|
164
120
|
async tree(sha) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
return tree;
|
|
169
|
-
}
|
|
170
|
-
} else {
|
|
171
|
-
this.#tree = new Map();
|
|
121
|
+
let tree = this.#trees.get(sha);
|
|
122
|
+
if (tree) {
|
|
123
|
+
return tree;
|
|
172
124
|
}
|
|
173
125
|
|
|
174
126
|
const { json } = await this.provider.fetchJSON(
|
|
175
127
|
`${this.api}/git/trees/${sha}?recursive=1`
|
|
176
128
|
);
|
|
177
129
|
|
|
178
|
-
|
|
130
|
+
tree = json.tree;
|
|
179
131
|
|
|
180
|
-
this.#
|
|
132
|
+
this.#trees.set(sha, tree);
|
|
181
133
|
|
|
182
134
|
return tree;
|
|
183
135
|
}
|
|
184
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
|
+
|
|
185
168
|
async *entries(patterns) {
|
|
186
169
|
const commit = await this.commitForSha(await this.refId());
|
|
187
170
|
|
|
188
|
-
if (!this.#entries) {
|
|
189
|
-
this.#entries = new Map();
|
|
190
|
-
}
|
|
191
|
-
|
|
192
171
|
for (const entry of matcher(await this.tree(commit.tree.sha), patterns, {
|
|
193
172
|
name: "path"
|
|
194
173
|
})) {
|
|
@@ -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
|
-
|
|
94
|
-
|
|
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
|
|