github-repository-provider 7.30.16 → 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/package.json +1 -1
- package/src/github-branch.mjs +49 -64
package/package.json
CHANGED
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
|
})) {
|