Skip to content
This repository has been archived by the owner on Aug 16, 2023. It is now read-only.

feat(filter): filter repositories by IGNORE_REPOSITORIES and GITHUB_ORGANIZATIONS #135

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
2 changes: 2 additions & 0 deletions .jest/setEnvVars.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand All @@ -49,4 +55,6 @@ module.exports = {
githubToken,
ignoreSelfOwnedEvents,
minimumNumberOfContributions,
repositoriesToFilterOut,
organizationsToFilterOut,
};
27 changes: 24 additions & 3 deletions starfish.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const {
githubToken,
ignoreSelfOwnedEvents,
minimumNumberOfContributions,
repositoriesToFilterOut,
organizationsToFilterOut,
} = require('./globals');
const { createLuxonDateTimeFromIso } = require('./dateTimes');
const fetch = require('node-fetch');
Expand Down Expand Up @@ -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) {
Expand Down