Skip to content

Commit

Permalink
Merge pull request #984 from ckeditor/ck/16872
Browse files Browse the repository at this point in the history
Aligned stale bot to recent changes in the GitHub GraphQL API
  • Loading branch information
pomek authored Aug 13, 2024
2 parents 4f7291f + f77e3a1 commit 666daf6
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 13 deletions.
7 changes: 6 additions & 1 deletion packages/ckeditor5-dev-stale-bot/lib/githubrepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,12 @@ module.exports = class GitHubRepository {
};

return this.sendRequest( await queries.getLabels, variables )
.then( data => data.repository.labels.nodes.map( label => label.id ) )
.then( data => {
return data.repository.labels.nodes
// Additional filtering is needed, because GitHub endpoint may return many more results than match the query.
.filter( label => labelNames.includes( label.name ) )
.map( label => label.id );
} )
.catch( error => {
this.logger.error( 'Unexpected error when executing "#getLabels()".', error );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ query GetLabels( $repositoryOwner: String!, $repositoryName: String!, $labelName
labels( query: $labelNames, first: 100 ) {
nodes {
id
name
}
}
}
Expand Down
46 changes: 34 additions & 12 deletions packages/ckeditor5-dev-stale-bot/tests/githubrepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -1893,6 +1893,16 @@ describe( 'dev-stale-bot/lib', () => {
} );

describe( '#getLabels()', () => {
let labels;

beforeEach( () => {
labels = [
{ id: 'LabelId1', name: 'type:bug' },
{ id: 'LabelId2', name: 'type:task' },
{ id: 'LabelId3', name: 'type:feature' }
];
} );

it( 'should be a function', () => {
expect( githubRepository.getLabels ).to.be.a( 'function' );
} );
Expand All @@ -1905,12 +1915,6 @@ describe( 'dev-stale-bot/lib', () => {
} );

it( 'should return labels', () => {
const labels = [
{ id: 'LabelId1' },
{ id: 'LabelId2' },
{ id: 'LabelId3' }
];

stubs.GraphQLClient.request.resolves( {
repository: {
labels: {
Expand All @@ -1928,13 +1932,31 @@ describe( 'dev-stale-bot/lib', () => {
} );
} );

it( 'should send one request for labels', () => {
const labels = [
{ id: 'LabelId1' },
{ id: 'LabelId2' },
{ id: 'LabelId3' }
];
it( 'should return only requested labels even if GitHub endpoint returned additional ones', () => {
stubs.GraphQLClient.request.resolves( {
repository: {
labels: {
nodes: [
...labels,
{ id: 'LabelId4', name: 'type:docs' },
{ id: 'LabelId5', name: 'type:debt' },
{ id: 'LabelId6', name: 'type:question' },
{ id: 'LabelId7', name: 'intro' }
]
}
}
} );

return githubRepository.getLabels( 'ckeditor/ckeditor5', [ 'type:bug', 'type:task', 'type:feature' ] ).then( result => {
expect( result ).to.be.an( 'array' );
expect( result ).to.have.length( 3 );
expect( result[ 0 ] ).to.equal( 'LabelId1' );
expect( result[ 1 ] ).to.equal( 'LabelId2' );
expect( result[ 2 ] ).to.equal( 'LabelId3' );
} );
} );

it( 'should send one request for labels', () => {
stubs.GraphQLClient.request.resolves( {
repository: {
labels: {
Expand Down

0 comments on commit 666daf6

Please sign in to comment.