Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filter out bots in first-time contributor plugins #961

Merged
merged 1 commit into from
Feb 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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