Skip to content

Commit

Permalink
Merge pull request #961 from intuit/first-time
Browse files Browse the repository at this point in the history
filter out bots in first-time contributor plugins
  • Loading branch information
hipstersmoothie committed Feb 18, 2020
2 parents 5703bfe + d76d0ba commit 0fc21b5
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 9 deletions.
3 changes: 3 additions & 0 deletions packages/core/src/__tests__/make-commit-from-msg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const makeCommitFromMsg = (
username?: string;
/** Packages effected by the commit */
packages?: string[];
/** The type of user */
type?: 'Bot' | 'User';
/** PR info for the commit */
pullRequest?: {
/** PR number attached to commit */
Expand All @@ -35,6 +37,7 @@ const makeCommitFromMsg = (
files: options.files || [],
authors: [
{
type: options.type,
name:
options.name !== undefined && options.name !== null
? options.name
Expand Down
16 changes: 9 additions & 7 deletions packages/core/src/log-parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export interface ICommitAuthor {
username?: string;
/** The commit this author created */
hash?: string;
/** The type of user */
type?: 'Bot' | 'User' | string;
}

export interface IPullRequest {
Expand All @@ -25,31 +27,31 @@ export interface ICommit {
/**
*
*/
hash: string;
hash: string;
/**
*
*/
authorName?: string;
authorName?: string;
/**
*
*/
authorEmail?: string;
authorEmail?: string;
/**
*
*/
subject: string;
subject: string;
/**
*
*/
rawBody?: string;
rawBody?: string;
/**
*
*/
labels?: string[];
labels?: string[];
/**
*
*/
files: string[];
files: string[];
}

export type IExtendedCommit = ICommit & {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Thank you, Jeff123 ([@Jeff123](https://github.com/Jeff123)), for all your work!"
]
`;

exports[`First Time Contributor Plugin should exclude bots 1`] = `Array []`;

exports[`First Time Contributor Plugin should include a username if it exists 1`] = `
Array [
":tada: This release contains work from new contributors! :tada:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,21 @@ describe('First Time Contributor Plugin', () => {

expect(await hooks.addToBody.promise([], commits)).toMatchSnapshot();
});

test('should exclude bots', async () => {
const hooks = setup();
const commits = [
makeCommitFromMsg('foo', {
username: 'jeff-the-snake',
name: 'jeff',
type: 'Bot'
})
];

graphql.mockReturnValue({
search: { issueCount: 1 }
});

expect(await hooks.addToBody.promise([], commits)).toMatchSnapshot();
});
});
5 changes: 3 additions & 2 deletions plugins/first-time-contributor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ export default class FirstTimeContributorPlugin implements IPlugin {
const newContributors = (
await Promise.all(
flatMap(commits, c => c.authors).map(async author => {
if (!author.username) {
if (!author.username || author.type === 'Bot') {
return;
}

// prettier-ignore
const prs = await auto.git?.graphql(`
{
search(first: 2, type: ISSUE, query: "user:${auto.git?.options.owner} repo:${auto.git?.options.repo} author:${author.username} state:closed") {
search(first: 2, type: ISSUE, query: "repo:${auto.git?.options.owner}/${auto.git?.options.repo} is:pr is:merged author:${author.username}") {
issueCount
}
}
Expand Down

0 comments on commit 0fc21b5

Please sign in to comment.