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

issue #78 #129

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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ Log in to GitHub and [register a new personal access token](https://github.com/s

### Next, Create a file named .env, copy the contents of the .env.template file into it, and add your values to the new file.

#### NOTE: We have provided default(hardcoded) environment variable values for easy onboarding inside the `globals.js` file where we handle our environment variables. The only thing you need to take care about is the `GITHUB_TOKEN`(access token) which is unique for every user in your .env file. This default implementation is provided for user convinience, rest you can modify the .env according to your needs.

- Paste the access token into `GITHUB_TOKEN`.
- `TIMEZONE` allows you to specify which timezone Starfish should use to decide on which day a contribution happened.
- The default is UTC, which works well for organizations with multiple locations. See the "Time zones" section for details.
Expand Down
14 changes: 2 additions & 12 deletions __tests__/starfish.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ describe('getOrThrowIfMissingOrEmpty', () => {
expect(() => getOrThrowIfMissingOrEmpty('configurationThatDoesNotExist')).toThrow(Error);
});
it('should return the value of a configuration that exists in the environment', () => {
expect(() => getOrThrowIfMissingOrEmpty('TIMEZONE')).not.toThrow(Error);
expect(getOrThrowIfMissingOrEmpty('TIMEZONE')).toEqual(process.env.TIMEZONE);
expect(() => getOrThrowIfMissingOrEmpty('GITHUB_TOKEN')).not.toThrow(Error);
expect(getOrThrowIfMissingOrEmpty('GITHUB_TOKEN')).toEqual(process.env.GITHUB_TOKEN);
});
});

Expand All @@ -164,16 +164,6 @@ describe('filterResponseForImportantEvents', () => {
});
});

describe('getOrThrowIfMissingOrEmpty', () => {
it('should throw an error if the configuration does not exist in the environment', () => {
expect(() => getOrThrowIfMissingOrEmpty('configurationThatDoesNotExist')).toThrow(Error);
});
it('should return the value of a configuration that exists in the environment', () => {
expect(() => getOrThrowIfMissingOrEmpty('TIMEZONE')).not.toThrow(Error);
expect(getOrThrowIfMissingOrEmpty('TIMEZONE')).toEqual(process.env.TIMEZONE);
});
});

describe('fetchPageOfDataAndFilter', () => {
const apiDomain = 'https://api.github.com';
const apiPath = '/users/octocat/events';
Expand Down
29 changes: 23 additions & 6 deletions globals.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
const { createLuxonDateTimeFromIso, createTimeZone } = require('./dateTimes');

const defaultEnvironmentVariables = {
TIMEZONE: '',
CSV_COLUMN_NUMBER_FOR_GITHUB_ID: '0',
CSV_COLUMN_NUMBER_FOR_ALTERNATE_ID: '0',
IGNORE_SELFOWNED_EVENTS: 'false',
MINIMUM_NUMBER_OF_CONTRIBUTIONS: 1,
GITHUB_IMPORTANT_EVENTS:
'CommitCommentEvent,IssueCommentEvent,IssuesEvent,PullRequestEvent,PullRequestReviewEvent,PullRequestReviewCommentEvent',
};

function getOrThrowIfMissingOrEmpty(configField) {
const value = process.env[configField];
if (!value) {
Expand All @@ -11,6 +21,13 @@ function getOrThrowIfMissingOrEmpty(configField) {
return value;
}

function getDefaultEnvironemntValues(configField) {
const environmentValue = process.env[configField];
const value = environmentValue ? environmentValue : defaultEnvironmentVariables[configField];

return value;
}

function getDateTimesFromArgv(timeZone) {
console.info(`Using time zone: ${createTimeZone(timeZone).name}`);
const startDate = process.argv[2];
Expand All @@ -23,15 +40,15 @@ function getDateTimesFromArgv(timeZone) {
}

const githubToken = Buffer.from(getOrThrowIfMissingOrEmpty('GITHUB_TOKEN')).toString('base64');
const githubIdColumnNumber = getOrThrowIfMissingOrEmpty('CSV_COLUMN_NUMBER_FOR_GITHUB_ID');
const alternateIdColumnNumber = getOrThrowIfMissingOrEmpty('CSV_COLUMN_NUMBER_FOR_ALTERNATE_ID');
const minimumNumberOfContributions = process.env.MINIMUM_NUMBER_OF_CONTRIBUTIONS || 1;
const githubImportantEvents = getOrThrowIfMissingOrEmpty('GITHUB_IMPORTANT_EVENTS').split(',');
const timeZone = process.env.TIMEZONE;
const githubIdColumnNumber = getDefaultEnvironemntValues('CSV_COLUMN_NUMBER_FOR_GITHUB_ID');
const alternateIdColumnNumber = getDefaultEnvironemntValues('CSV_COLUMN_NUMBER_FOR_ALTERNATE_ID');
const minimumNumberOfContributions = getDefaultEnvironemntValues('MINIMUM_NUMBER_OF_CONTRIBUTIONS');
const githubImportantEvents = getDefaultEnvironemntValues('GITHUB_IMPORTANT_EVENTS').split(',');
const timeZone = getDefaultEnvironemntValues('TIMEZONE');
const dateTimes = getDateTimesFromArgv(timeZone);
const csvFilename = process.argv[4];

const ignoreSelfOwnedEvents = (process.env.IGNORE_SELFOWNED_EVENTS || 'false').toLowerCase();
const ignoreSelfOwnedEvents = getDefaultEnvironemntValues('IGNORE_SELFOWNED_EVENTS').toLowerCase();
console.info(`Configuration set to ignore self-owned events? ${ignoreSelfOwnedEvents}`);
if (ignoreSelfOwnedEvents !== 'true' && ignoreSelfOwnedEvents !== 'false') {
console.error('IGNORE_SELFOWNED_EVENTS must be "true" or "false"');
Expand Down