Skip to content

Commit b3940ab

Browse files
Merge pull request #62 from w3c/labelstructure
Use consistent structure to expose repository labels
2 parents fc7267c + e4352a7 commit b3940ab

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

validate.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const octo = new Octokat({token: config.ghToken});
1818
const orgs = ["w3c", "WebAudio", "immersive-web", "webassembly", "w3ctag", "WICG", "w3cping"];
1919
const errortypes = ["inconsistentgroups", "now3cjson", "invalidw3cjson", "illformedw3cjson", "incompletew3cjson", "nocontributing", "invalidcontributing", "nolicense", "nocodeofconduct", "invalidlicense", "noreadme", "noashnazg", "inconsistentstatus", "unprotectedbranch", "missingashnazghook", "duplicateashnazghooks"];
2020

21-
async function fetchLabelPage(org, repo, acc = [], cursor = null) {
21+
async function fetchLabelPage(org, repo, acc = {edges: []}, cursor = null) {
2222
console.warn("Fetching labels for " + repo);
2323
let res;
2424
try {
@@ -44,15 +44,15 @@ async function fetchLabelPage(org, repo, acc = [], cursor = null) {
4444
console.error("query failed " + JSON.stringify(err));
4545
}
4646
if (res && res.repository) {
47-
const data = acc.concat(res.repository.labels.edges);
47+
const labels = {edges: acc.edges.concat(res.repository.labels.edges)};
4848
if (res.repository.labels.pageInfo.hasNextPage) {
49-
return fetchLabelPage(org, repo, data, res.repository.labels.pageInfo.endCursor);
49+
return fetchLabelPage(org, repo, labels, res.repository.labels.pageInfo.endCursor);
5050
} else {
51-
return {"repo": {"owner": org, "name": repo}, "labels": data.map(e => e.node)};
51+
return {"repo": {"owner": org, "name": repo}, labels};
5252
}
5353
} else {
5454
console.error("Fetching label for " + repo + " at cursor " + cursor + " failed with " + JSON.stringify(res) + ", not retrying");
55-
return {"repo": {"owner": org, "name": repo}, "labels": acc.map(e => e.node)};
55+
return {"repo": {"owner": org, "name": repo}, "labels": acc};
5656
//return fetchLabelPage(org, repo, acc, cursor);
5757
}
5858
}
@@ -141,12 +141,18 @@ async function fetchRepoPage(org, acc = [], cursor = null) {
141141
return Promise.all(
142142
res.organization.repositories.edges
143143
.filter(e => e.node.labels.pageInfo.hasNextPage)
144-
.map(e => fetchLabelPage(e.node.owner.login, e.node.name, e.node.labels.edges, e.node.labels.pageInfo.endCursor))
144+
.map(e => fetchLabelPage(e.node.owner.login, e.node.name, e.node.labels, e.node.labels.pageInfo.endCursor))
145145
).then((labelsPerRepos) => {
146146
const data = acc.concat(res.organization.repositories.edges.map(e => e.node));
147147
labelsPerRepos.forEach(({repo, labels}) => {
148148
data.find(r => r.owner.login == repo.owner && r.name == repo.name).labels = labels;
149149
});
150+
// Clean up labels data structure
151+
data.forEach(r => {
152+
if (r.labels && r.labels.edges) {
153+
r.labels = r.labels.edges.map(e => e.node);
154+
}
155+
});
150156
if (res.organization.repositories.pageInfo.hasNextPage) {
151157
return fetchRepoPage(org, data, res.organization.repositories.pageInfo.endCursor);
152158
} else {

0 commit comments

Comments
 (0)