From 8bb01b2dbbb399384a868e0f1a519b3b40fe9195 Mon Sep 17 00:00:00 2001 From: Jackson Machado Date: Tue, 4 Oct 2022 17:06:37 -0300 Subject: [PATCH 1/2] feat(filter): filter repositories by IGNORE_REPOSITORIES and GITHUB_ORGANIZATIONS --- .env.template | 2 ++ .jest/setEnvVars.js | 2 ++ README.md | 6 ++++++ globals.js | 8 ++++++++ starfish.js | 18 +++++++++++++++++- 5 files changed, 35 insertions(+), 1 deletion(-) diff --git a/.env.template b/.env.template index 9050c65..8b55128 100644 --- a/.env.template +++ b/.env.template @@ -5,6 +5,8 @@ CSV_COLUMN_NUMBER_FOR_ALTERNATE_ID = "" IGNORE_SELFOWNED_EVENTS = "" MINIMUM_NUMBER_OF_CONTRIBUTIONS = 1 GITHUB_IMPORTANT_EVENTS = "CommitCommentEvent,IssueCommentEvent,IssuesEvent,PullRequestEvent,PullRequestReviewEvent,PullRequestReviewCommentEvent" +IGNORE_REPOSITORIES = "" +GITHUB_ORGANIZATIONS = "" // 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/ diff --git a/.jest/setEnvVars.js b/.jest/setEnvVars.js index 819621f..1663933 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.GITHUB_ORGANIZATIONS = 'indeedeng'; +process.env.IGNORE_REPOSITORIES = ''; diff --git a/README.md b/README.md index 144f4a6..d33b79f 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"` +- `GITHUB_ORGANIZATIONS` contains organization login to be filter the events. Logins must be separated by a comma. + - One organization to consider: `GITHUB_ORGANIZATIONS = "indeedeng"` + - Many organizations to consider: `GITHUB_ORGANIZATIONS = "indeedeng,github"` ### Time zones diff --git a/globals.js b/globals.js index ad8e4ed..49d6700 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 githubIgnoreRepositories = (process.env.IGNORE_REPOSITORIES || '') + .split(',') + .map((repo) => repo.trim()); +const githubOrganizations = (process.env.GITHUB_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, + githubIgnoreRepositories, + githubOrganizations, }; diff --git a/starfish.js b/starfish.js index c11218a..940ed45 100644 --- a/starfish.js +++ b/starfish.js @@ -5,6 +5,8 @@ const { githubToken, ignoreSelfOwnedEvents, minimumNumberOfContributions, + githubIgnoreRepositories, + githubOrganizations, } = require('./globals'); const { createLuxonDateTimeFromIso } = require('./dateTimes'); const fetch = require('node-fetch'); @@ -123,6 +125,14 @@ function isContributionInTimeRange(createdAt, startMoment, endMoment) { ); } +function filterResponseFor(organization) { + if (githubOrganizations.length && githubOrganizations[0] !== '') { + return githubOrganizations.indexOf(organization) >= 0; + } + + return true; +} + function didTheyQualify(idObject, dateTimes) { const startMoment = dateTimes[0]; const endMoment = dateTimes[1]; @@ -130,7 +140,13 @@ function didTheyQualify(idObject, dateTimes) { for (let i = 0; i < idObject.contributions.length; i++) { const createdAtString = idObject.contributions[i].created_at; - if (isContributionInTimeRange(createdAtString, startMoment, endMoment)) { + const repository = idObject.contributions[i].repo.name; + const organization = idObject.contributions[i].org.login; + if ( + isContributionInTimeRange(createdAtString, startMoment, endMoment) && + filterResponseFor(organization) && + githubIgnoreRepositories.indexOf(repository) === -1 + ) { numberOfQualifyingContributions++; } if (numberOfQualifyingContributions >= minimumNumberOfContributions) { From c93dbbe6cc612daf8307ae0b3be7a47d84bf17e9 Mon Sep 17 00:00:00 2001 From: Jackson Machado Date: Sat, 29 Oct 2022 00:53:18 -0300 Subject: [PATCH 2/2] fix: change variable names and ignore repositories --- .env.template | 4 ++-- .jest/setEnvVars.js | 2 +- README.md | 6 +++--- globals.js | 8 ++++---- starfish.js | 33 +++++++++++++++++++-------------- 5 files changed, 29 insertions(+), 24 deletions(-) diff --git a/.env.template b/.env.template index 8b55128..a8f6399 100644 --- a/.env.template +++ b/.env.template @@ -5,8 +5,8 @@ CSV_COLUMN_NUMBER_FOR_ALTERNATE_ID = "" IGNORE_SELFOWNED_EVENTS = "" MINIMUM_NUMBER_OF_CONTRIBUTIONS = 1 GITHUB_IMPORTANT_EVENTS = "CommitCommentEvent,IssueCommentEvent,IssuesEvent,PullRequestEvent,PullRequestReviewEvent,PullRequestReviewCommentEvent" -IGNORE_REPOSITORIES = "" -GITHUB_ORGANIZATIONS = "" // 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 1663933..ae3199e 100644 --- a/.jest/setEnvVars.js +++ b/.jest/setEnvVars.js @@ -6,5 +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.GITHUB_ORGANIZATIONS = 'indeedeng'; +process.env.IGNORE_ORGANIZATIONS = 'indeedeng'; process.env.IGNORE_REPOSITORIES = ''; diff --git a/README.md b/README.md index d33b79f..052393f 100644 --- a/README.md +++ b/README.md @@ -86,9 +86,9 @@ Log in to GitHub and [register a new personal access token](https://github.com/s - `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"` -- `GITHUB_ORGANIZATIONS` contains organization login to be filter the events. Logins must be separated by a comma. - - One organization to consider: `GITHUB_ORGANIZATIONS = "indeedeng"` - - Many organizations to consider: `GITHUB_ORGANIZATIONS = "indeedeng,github"` +- `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 49d6700..c262d6f 100644 --- a/globals.js +++ b/globals.js @@ -30,10 +30,10 @@ const githubImportantEvents = getOrThrowIfMissingOrEmpty('GITHUB_IMPORTANT_EVENT const timeZone = process.env.TIMEZONE; const dateTimes = getDateTimesFromArgv(timeZone); const csvFilename = process.argv[4]; -const githubIgnoreRepositories = (process.env.IGNORE_REPOSITORIES || '') +const repositoriesToFilterOut = (process.env.IGNORE_REPOSITORIES || '') .split(',') .map((repo) => repo.trim()); -const githubOrganizations = (process.env.GITHUB_ORGANIZATIONS || '') +const organizationsToFilterOut = (process.env.IGNORE_ORGANIZATIONS || '') .split(',') .map((repo) => repo.trim()); @@ -55,6 +55,6 @@ module.exports = { githubToken, ignoreSelfOwnedEvents, minimumNumberOfContributions, - githubIgnoreRepositories, - githubOrganizations, + repositoriesToFilterOut, + organizationsToFilterOut, }; diff --git a/starfish.js b/starfish.js index 940ed45..e3ca738 100644 --- a/starfish.js +++ b/starfish.js @@ -5,8 +5,8 @@ const { githubToken, ignoreSelfOwnedEvents, minimumNumberOfContributions, - githubIgnoreRepositories, - githubOrganizations, + repositoriesToFilterOut, + organizationsToFilterOut, } = require('./globals'); const { createLuxonDateTimeFromIso } = require('./dateTimes'); const fetch = require('node-fetch'); @@ -125,28 +125,33 @@ function isContributionInTimeRange(createdAt, startMoment, endMoment) { ); } -function filterResponseFor(organization) { - if (githubOrganizations.length && githubOrganizations[0] !== '') { - return githubOrganizations.indexOf(organization) >= 0; +function filterResponseFor(orgFromThisContribution) { + if (organizationsToFilterOut.length && organizationsToFilterOut[0] !== '') { + return organizationsToFilterOut.indexOf(orgFromThisContribution) === -1; } return true; } -function didTheyQualify(idObject, dateTimes) { +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; - const repository = idObject.contributions[i].repo.name; - const organization = idObject.contributions[i].org.login; - if ( - isContributionInTimeRange(createdAtString, startMoment, endMoment) && - filterResponseFor(organization) && - githubIgnoreRepositories.indexOf(repository) === -1 - ) { + if (isValidContribution(idObject.contributions[i], dateTimes)) { numberOfQualifyingContributions++; } if (numberOfQualifyingContributions >= minimumNumberOfContributions) {