Skip to content

Commit 53b2dae

Browse files
committed
Sort labels in github.listRepos
For #67.
1 parent 3f0959f commit 53b2dae

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
@@ -115,6 +115,7 @@ async function *listRepos(org) {
115115
labels.push(...res.repository.labels.nodes);
116116
pageInfo = res.repository.labels.pageInfo;
117117
}
118+
labels.sort((l1, l2) => l1.name.localeCompare(l2.name));
118119
repo.labels = labels;
119120
yield repo;
120121
}

test/github.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,51 @@ describe('github', () => {
5252
}]);
5353
});
5454

55+
it('labels are sorted', async () => {
56+
const graphql = sinon.stub();
57+
graphql.resolves({
58+
organization: {
59+
repositories: {
60+
nodes: [
61+
{
62+
owner: {login: 'WICG'},
63+
name: 'speech-api',
64+
labels: {
65+
nodes: [{
66+
name: 'a',
67+
color: 'aaaaaa',
68+
}, {
69+
name: 'c',
70+
color: 'cccccc',
71+
}, {
72+
name: 'b',
73+
color: 'bbbbbb',
74+
}],
75+
pageInfo: {hasNextPage: false}
76+
}
77+
}
78+
],
79+
pageInfo: {hasNextPage: false}
80+
}
81+
}
82+
});
83+
const github = proxyquire('../lib/github.js', {
84+
'./graphql.js': graphql
85+
});
86+
const repo = (await github.listRepos('WICG').next()).value;
87+
assert(graphql.calledOnce);
88+
assert.deepStrictEqual(repo.labels, [{
89+
name: 'a',
90+
color: 'aaaaaa',
91+
}, {
92+
name: 'b',
93+
color: 'bbbbbb',
94+
}, {
95+
name: 'c',
96+
color: 'cccccc',
97+
}]);
98+
});
99+
55100
it('paginated repos', async () => {
56101
const graphql = sinon.stub();
57102
graphql.onCall(0).resolves({

0 commit comments

Comments
 (0)