Skip to content

Commit f1aa20d

Browse files
Merge pull request #82 from w3c/sort-labels
Sort labels in `github.listRepos`
2 parents 2f16919 + 53b2dae commit f1aa20d

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

lib/github.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ async function *listRepos(org) {
156156
labels.push(...res.repository.labels.nodes);
157157
pageInfo = res.repository.labels.pageInfo;
158158
}
159+
labels.sort((l1, l2) => l1.name.localeCompare(l2.name));
159160
repo.labels = labels;
160161
yield repo;
161162
}

test/github.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,51 @@ describe('github', () => {
105105
}]);
106106
});
107107

108+
it('labels are sorted', async () => {
109+
const graphql = sinon.stub();
110+
graphql.resolves({
111+
organization: {
112+
repositories: {
113+
nodes: [
114+
{
115+
owner: {login: 'WICG'},
116+
name: 'speech-api',
117+
labels: {
118+
nodes: [{
119+
name: 'a',
120+
color: 'aaaaaa',
121+
}, {
122+
name: 'c',
123+
color: 'cccccc',
124+
}, {
125+
name: 'b',
126+
color: 'bbbbbb',
127+
}],
128+
pageInfo: {hasNextPage: false}
129+
}
130+
}
131+
],
132+
pageInfo: {hasNextPage: false}
133+
}
134+
}
135+
});
136+
const github = proxyquire('../lib/github.js', {
137+
'./graphql.js': graphql
138+
});
139+
const repo = (await github.listRepos('WICG').next()).value;
140+
assert(graphql.calledOnce);
141+
assert.deepStrictEqual(repo.labels, [{
142+
name: 'a',
143+
color: 'aaaaaa',
144+
}, {
145+
name: 'b',
146+
color: 'bbbbbb',
147+
}, {
148+
name: 'c',
149+
color: 'cccccc',
150+
}]);
151+
});
152+
108153
it('paginated repos', async () => {
109154
const graphql = sinon.stub();
110155
graphql.onCall(0).resolves({

0 commit comments

Comments
 (0)