github-repository-provider 7.25.57 → 7.25.60
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 +1 -1
- package/src/github-branch.mjs +46 -14
- package/src/github-repository.mjs +16 -2
package/package.json
CHANGED
package/src/github-branch.mjs
CHANGED
|
@@ -84,16 +84,13 @@ export class GithubBranch extends Branch {
|
|
|
84
84
|
})
|
|
85
85
|
});
|
|
86
86
|
|
|
87
|
-
r = await this.provider.fetchJSON(
|
|
88
|
-
|
|
89
|
-
{
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
})
|
|
95
|
-
}
|
|
96
|
-
);
|
|
87
|
+
r = await this.provider.fetchJSON(`repos/${this.slug}/git/${this.ref}`, {
|
|
88
|
+
method: "PATCH",
|
|
89
|
+
body: JSON.stringify({
|
|
90
|
+
...options,
|
|
91
|
+
sha: r.json.sha
|
|
92
|
+
})
|
|
93
|
+
});
|
|
97
94
|
|
|
98
95
|
return r.json;
|
|
99
96
|
}
|
|
@@ -103,11 +100,26 @@ export class GithubBranch extends Branch {
|
|
|
103
100
|
* @param {string} name
|
|
104
101
|
*/
|
|
105
102
|
async entry(name) {
|
|
103
|
+
if (this._entries) {
|
|
104
|
+
const entry = this._entries.get(name);
|
|
105
|
+
if (entry) {
|
|
106
|
+
return entry;
|
|
107
|
+
}
|
|
108
|
+
} else {
|
|
109
|
+
this._entries = new Map();
|
|
110
|
+
}
|
|
111
|
+
|
|
106
112
|
const { json } = await this.provider.fetchJSON(
|
|
107
113
|
`repos/${this.slug}/contents/${name}?ref=${this.ref}`
|
|
108
114
|
);
|
|
109
115
|
|
|
110
|
-
|
|
116
|
+
const entry = new this.entryClass(
|
|
117
|
+
name,
|
|
118
|
+
Buffer.from(json.content, "base64")
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
this._entries.set(name, entry);
|
|
122
|
+
return entry;
|
|
111
123
|
}
|
|
112
124
|
|
|
113
125
|
/**
|
|
@@ -130,7 +142,7 @@ export class GithubBranch extends Branch {
|
|
|
130
142
|
);
|
|
131
143
|
|
|
132
144
|
this._commitForSha.set(sha, json);
|
|
133
|
-
|
|
145
|
+
|
|
134
146
|
return json;
|
|
135
147
|
}
|
|
136
148
|
|
|
@@ -140,15 +152,33 @@ export class GithubBranch extends Branch {
|
|
|
140
152
|
* @return {Object[]}
|
|
141
153
|
*/
|
|
142
154
|
async tree(sha) {
|
|
155
|
+
if (this._tree) {
|
|
156
|
+
const tree = this._tree.get(sha);
|
|
157
|
+
if (tree) {
|
|
158
|
+
return tree;
|
|
159
|
+
}
|
|
160
|
+
} else {
|
|
161
|
+
this._tree = new Map();
|
|
162
|
+
}
|
|
163
|
+
|
|
143
164
|
const { json } = await this.provider.fetchJSON(
|
|
144
165
|
`repos/${this.slug}/git/trees/${sha}?recursive=1`
|
|
145
166
|
);
|
|
146
|
-
|
|
167
|
+
|
|
168
|
+
const tree = json.tree;
|
|
169
|
+
|
|
170
|
+
this._tree.set(sha, tree);
|
|
171
|
+
|
|
172
|
+
return tree;
|
|
147
173
|
}
|
|
148
174
|
|
|
149
175
|
async *entries(patterns) {
|
|
150
176
|
const commit = await this.commitForSha(await this.refId());
|
|
151
177
|
|
|
178
|
+
if (!this._entries) {
|
|
179
|
+
this._entries = new Map();
|
|
180
|
+
}
|
|
181
|
+
|
|
152
182
|
for (const entry of matcher(await this.tree(commit.tree.sha), patterns, {
|
|
153
183
|
name: "path"
|
|
154
184
|
})) {
|
|
@@ -157,11 +187,13 @@ export class GithubBranch extends Branch {
|
|
|
157
187
|
yield new BaseCollectionEntry(entry.path);
|
|
158
188
|
break;
|
|
159
189
|
case "blob":
|
|
160
|
-
|
|
190
|
+
const e = new LazyBufferContentEntry(
|
|
161
191
|
entry.path,
|
|
162
192
|
parseInt(entry.mode, 8),
|
|
163
193
|
this
|
|
164
194
|
);
|
|
195
|
+
this._entries.set(e.path, e);
|
|
196
|
+
yield e;
|
|
165
197
|
break;
|
|
166
198
|
/* case "commit":
|
|
167
199
|
break;*/
|
|
@@ -100,13 +100,23 @@ export class GithubRepository extends Repository {
|
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
/**
|
|
103
|
+
* Get sha of a ref.
|
|
103
104
|
* {@link https://developer.github.com/v3/git/refs/}
|
|
104
105
|
* @param {string} ref
|
|
105
|
-
* @return {string} sha of the ref
|
|
106
|
+
* @return {Promise<string>} sha of the ref
|
|
106
107
|
*/
|
|
107
108
|
async refId(ref) {
|
|
108
109
|
ref = ref.replace(/^refs\//, "");
|
|
109
110
|
|
|
111
|
+
if (this._ref) {
|
|
112
|
+
const sha = this._ref.get(ref);
|
|
113
|
+
if (sha) {
|
|
114
|
+
return sha;
|
|
115
|
+
}
|
|
116
|
+
} else {
|
|
117
|
+
this._ref = new Map();
|
|
118
|
+
}
|
|
119
|
+
|
|
110
120
|
const { response, json } = await this.provider.fetchJSON(
|
|
111
121
|
`repos/${this.slug}/git/ref/${ref}`
|
|
112
122
|
);
|
|
@@ -116,7 +126,11 @@ export class GithubRepository extends Repository {
|
|
|
116
126
|
throw new Error(`No refId for '${this.fullName}' '${ref}'`);
|
|
117
127
|
}
|
|
118
128
|
|
|
119
|
-
|
|
129
|
+
const sha = json.object.sha;
|
|
130
|
+
|
|
131
|
+
this._ref.set(ref, sha);
|
|
132
|
+
|
|
133
|
+
return sha;
|
|
120
134
|
}
|
|
121
135
|
|
|
122
136
|
async createBranch(name, from, options) {
|