Skip to content

Commit

Permalink
Project management automation: Fix 'add first time contributor label' (
Browse files Browse the repository at this point in the history
…#17156)

GitHub returns the search result count as `data.total_count`, not
`total_count`.
  • Loading branch information
noisysocks authored and gziolo committed Aug 29, 2019
1 parent 34e9963 commit c65dbb3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Expand Up @@ -17,12 +17,12 @@ async function addFirstTimeContributorLabel( payload, octokit ) {

debug( `add-first-time-contributor-label: Searching for commits in ${ owner }/${ repo } by @${ author }` );

const { total_count: totalCount } = await octokit.search.commits( {
const { data: { total_count: totalCount } } = await octokit.search.commits( {
q: `repo:${ owner }/${ repo }+author:${ author }`,
} );

if ( totalCount !== 0 ) {
debug( 'add-first-time-contributor-label: Commits found. Aborting' );
debug( `add-first-time-contributor-label: ${ totalCount } commits found. Aborting` );
return;
}

Expand Down
Expand Up @@ -22,7 +22,11 @@ describe( 'addFirstTimeContributorLabel', () => {
it( 'does nothing if the user has commits', async () => {
const octokit = {
search: {
commits: jest.fn( () => Promise.resolve( { total_count: 100 } ) ),
commits: jest.fn( () => Promise.resolve( {
data: {
total_count: 100,
},
} ) ),
},
issues: {
addLabels: jest.fn(),
Expand All @@ -40,7 +44,11 @@ describe( 'addFirstTimeContributorLabel', () => {
it( 'adds the label if the user does not have commits', async () => {
const octokit = {
search: {
commits: jest.fn( () => Promise.resolve( { total_count: 0 } ) ),
commits: jest.fn( () => Promise.resolve( {
data: {
total_count: 0,
},
} ) ),
},
issues: {
addLabels: jest.fn(),
Expand Down

0 comments on commit c65dbb3

Please sign in to comment.