Skip to content

Commit

Permalink
Pull Request Automation: Avoid automation tasks for forked repository (
Browse files Browse the repository at this point in the history
…#20021)

* Pull Request Automation: Avoid automation tasks for forked repository

* Fix doc block typo

Co-authored-by: Daniel Richards <[email protected]>
  • Loading branch information
aduth and talldan authored Feb 4, 2020
1 parent 1ded40d commit 02ce73f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
21 changes: 21 additions & 0 deletions packages/project-management-automation/lib/if-not-fork.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Higher-order function which executes and returns the result of the given
* handler only if the enhanced function is called with a payload indicating a
* pull request event which did not originate from a forked repository.
*
* @param {Function} handler Original task.
*
* @return {Function} Enhanced task.
*/
function ifNotFork( handler ) {
return ( payload, ...args ) => {
if (
payload.pull_request.head.repo.full_name ===
payload.pull_request.base.repo.full_name
) {
return handler( payload, ...args );
}
};
}

module.exports = ifNotFork;
5 changes: 3 additions & 2 deletions packages/project-management-automation/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@ const assignFixedIssues = require( './assign-fixed-issues' );
const addFirstTimeContributorLabel = require( './add-first-time-contributor-label' );
const addMilestone = require( './add-milestone' );
const debug = require( './debug' );
const ifNotFork = require( './if-not-fork' );

const automations = [
{
event: 'pull_request',
action: 'opened',
task: assignFixedIssues,
task: ifNotFork( assignFixedIssues ),
},
{
event: 'pull_request',
action: 'opened',
task: addFirstTimeContributorLabel,
task: ifNotFork( addFirstTimeContributorLabel ),
},
{
event: 'pull_request',
Expand Down

0 comments on commit 02ce73f

Please sign in to comment.