diff --git a/.env.template b/.env.template index 9050c65..a8f6399 100644 --- a/.env.template +++ b/.env.template @@ -8,3 +8,5 @@ GITHUB_IMPORTANT_EVENTS = "CommitCommentEvent,IssueCommentEvent,IssuesEvent,Pull // You can edit this list of important event types if these are not the event types you care about. // Make sure the list is comma-separated with no spaces // Event types can be found here https://developer.github.com/v3/activity/events/types/ +IGNORE_REPOSITORIES = "" +IGNORE_ORGANIZATIONS = "" diff --git a/.jest/setEnvVars.js b/.jest/setEnvVars.js index 819621f..ae3199e 100644 --- a/.jest/setEnvVars.js +++ b/.jest/setEnvVars.js @@ -6,3 +6,5 @@ process.env.IGNORE_SELFOWNED_EVENTS = 'false'; process.env.MINIMUM_NUMBER_OF_CONTRIBUTIONS = 2; process.env.GITHUB_IMPORTANT_EVENTS = 'CommitCommentEvent,IssueCommentEvent,IssuesEvent,PullRequestEvent,PullRequestReviewEvent,PullRequestReviewCommentEvent'; +process.env.IGNORE_ORGANIZATIONS = 'indeedeng'; +process.env.IGNORE_REPOSITORIES = ''; diff --git a/README.md b/README.md index 144f4a6..052393f 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,12 @@ Log in to GitHub and [register a new personal access token](https://github.com/s - We do not look for PushEvents because those are usually used for personal projects, not actual open source contributions. - Starfish allows you to filter events based on the specific action taken. For example, you might want to count when a pull request is opened, but not when it is closed. To do that, the list of important events can include basic types (like "PullRequestEvent") or a specific action of a type (like "PullRequestEvent.closed"). You can list multiple actions for the same event type. Visit [GitHub event types](https://docs.github.com/en/free-pro-team@latest/developers/webhooks-and-events/github-event-types#event-object-common-properties) for more information. +- `IGNORE_REPOSITORIES` contains repository names to be ignored to check. Names must be separated by a comma. + - One repository to ignore: `IGNORE_REPOSITORIES="indeedeng/starfish"` + - Many repositories to ignore: `IGNORE_REPOSITORIES="indeedeng/starfish,indeedeng/proctor"` +- `IGNORE_ORGANIZATIONS` contains organization login to be filter the events. Logins must be separated by a comma. + - One organization to consider: `IGNORE_ORGANIZATIONS = "indeedeng"` + - Many organizations to consider: `IGNORE_ORGANIZATIONS = "indeedeng,github"` ### Time zones diff --git a/globals.js b/globals.js index ad8e4ed..c262d6f 100644 --- a/globals.js +++ b/globals.js @@ -30,6 +30,12 @@ const githubImportantEvents = getOrThrowIfMissingOrEmpty('GITHUB_IMPORTANT_EVENT const timeZone = process.env.TIMEZONE; const dateTimes = getDateTimesFromArgv(timeZone); const csvFilename = process.argv[4]; +const repositoriesToFilterOut = (process.env.IGNORE_REPOSITORIES || '') + .split(',') + .map((repo) => repo.trim()); +const organizationsToFilterOut = (process.env.IGNORE_ORGANIZATIONS || '') + .split(',') + .map((repo) => repo.trim()); const ignoreSelfOwnedEvents = (process.env.IGNORE_SELFOWNED_EVENTS || 'false').toLowerCase(); console.info(`Configuration set to ignore self-owned events? ${ignoreSelfOwnedEvents}`); @@ -49,4 +55,6 @@ module.exports = { githubToken, ignoreSelfOwnedEvents, minimumNumberOfContributions, + repositoriesToFilterOut, + organizationsToFilterOut, }; diff --git a/starfish.js b/starfish.js index c11218a..e3ca738 100644 --- a/starfish.js +++ b/starfish.js @@ -5,6 +5,8 @@ const { githubToken, ignoreSelfOwnedEvents, minimumNumberOfContributions, + repositoriesToFilterOut, + organizationsToFilterOut, } = require('./globals'); const { createLuxonDateTimeFromIso } = require('./dateTimes'); const fetch = require('node-fetch'); @@ -123,14 +125,33 @@ function isContributionInTimeRange(createdAt, startMoment, endMoment) { ); } -function didTheyQualify(idObject, dateTimes) { +function filterResponseFor(orgFromThisContribution) { + if (organizationsToFilterOut.length && organizationsToFilterOut[0] !== '') { + return organizationsToFilterOut.indexOf(orgFromThisContribution) === -1; + } + + return true; +} + +function isValidContribution(contribution, dateTimes) { const startMoment = dateTimes[0]; const endMoment = dateTimes[1]; + const createdAtString = contribution.created_at; + const repository = contribution.repo.name; + const organization = contribution.org.login; + + return ( + isContributionInTimeRange(createdAtString, startMoment, endMoment) && + filterResponseFor(organization) && + repositoriesToFilterOut.indexOf(repository) === -1 + ); +} + +function didTheyQualify(idObject, dateTimes) { let numberOfQualifyingContributions = 0; for (let i = 0; i < idObject.contributions.length; i++) { - const createdAtString = idObject.contributions[i].created_at; - if (isContributionInTimeRange(createdAtString, startMoment, endMoment)) { + if (isValidContribution(idObject.contributions[i], dateTimes)) { numberOfQualifyingContributions++; } if (numberOfQualifyingContributions >= minimumNumberOfContributions) {