2.5.0 • Published 7 months ago

volunteer-contributions-fetch v2.5.0

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

volunteer-contributions-fetch

This library fetches contributions from several different sources and saves them in a JSON file. This can be used to track your own volunteer contributions. An example of this can be found on Michael's website.

Sources

Supported Sources

Currently the following sources are supported. Feel free to contribute a PR if you'd like to support another source!

  • GitHub
    • Issues created
    • Comments on issues
    • PRs
    • PR Reviews
  • Bugzilla
    • Bug reported
    • Bug commented on
  • MediaWiki
    • Page edited
  • Discourse
    • Topic created
    • Post created
  • Mozilla Community Portal
    • Participated in event
    • Participated in campaign

Each of the sources can be enabled separately. See the configuration section below.

Planned Sources

The following sources are planned:

  • Phabricator
    • Revision created
    • Revision updated

Possible future sources

The following sources would be interesting for (at least) Mozilla contributors, however they do not expose an activity API endpoint to easily gather information for a certain user.

  • support.mozilla.org
  • Pontoon

Usage

First install the package from npm:

npm install volunteer-contribution-fetch

Then you can create a file in your project which runs the fetch operation and provides the necessary config:

const { fetchAll } = require('volunteer-contributions-fetch');

const config = {}; // See below for documentation and a sample config

fetchAll(config);

Usage without output file

This can also be used without having to rely on an outputFile. For this case the fetchAll function returns all contributions. Additionally you can also pass existing contributions to the function and these will be considered as well. The return value and the parameter of the function works the same as having an outputFile.

const { fetchAll } = require('volunteer-contributions-fetch');

const config = {}; // See below for documentation and a sample config
const existingContributions = [{ ... }];

const results = fetchAll(config, existingContributions);
// results is now all existing contributions plus any newly fetched contribution

Note that passing existing contributions this way will be ignored if a outputFile is used.

Configuration

You can configure the different providers with a config you pass into the fetchAll function call. These config parameters are outlined below. The config gets validated and you might get an error if you haven't specified all necessary properties.

Additionally to the configuration file, we also require some environment variables to be set:

  • GITHUB_TOKEN with a GitHub token, if the GitHub source is enabled

While these tokens could potentially also be included the config, we want to make it hard to mistakenly publish secrets within code.

Configuration documentation

This section documents all the possible configuration values. For examples see the sample configuration below.

General

FieldData TypeRequiredDefaultDescription
outputFilestringNo-Path to contributions output file. Contributions are read from this file and new contributions will be added here.
bugzillaObjectNo-Bugzilla configuration options (see below)
communityPortalObjectNo-Community Portal configuration options (see below)
discourseObjectNo-Discourse configuration options (see below)
githubObjectNo-GitHub configuration options (see below)
mediaWikiObjectNo-MediaWiki configuration options (see below)

Bugzilla

FieldData TypeRequiredDefaultDescription
enabledbooleanYes-Indicates whether this data source is enabled. Alternatively you can also leave off the mediaWiki object entirely.
baseUrlstringYes-API base url without trailing slash (for example: https://bugzilla.mozilla.org)
usernamestringYes-Username on MediaWiki
stopDatestringYes-new Date() parseable string containing a date of possibly earliest contribution to track
typesObjectNo-Object containing the different labels below
types.createdTypestringNoCreated a Bug ReportLabel for entries related to having report a bug/enhancement.
types.commentedTypestringNoCommented on a Bug ReportLabel for entries related to having commented on a bug/enhancement.

Community Portal

FieldData TypeRequiredDefaultDescription
enabledbooleanYes-Indicates whether this data source is enabled. Alternatively you can also leave off the communityPortal object entirely.
baseUrlstringYes-Community Portal base url without trailing slash
usernamestringYes-Username on the Community Portal
participationTypestringNoParticipated in an eventLabel for entries related to having participated in an event.
campaignTypestringNoParticipated in a campaignLabel for entries related to having participated in a campaign

Discourse

FieldData TypeRequiredDefaultDescription
enabledbooleanYes-Indicates whether this data source is enabled. Alternatively you can also leave off the discourse object entirely.
baseUrlstringYes-API base url without trailing slash
usernamestringYes-Username on Discourse
topicTypestringNoCreated Discourse TopicLabel for entries related to having created a new topic.
postTypestringNoPosted on Discourse TopicLabel for entries related to having posted on an existing topic.
keepDeletedPostbooleanNofalseIf a post gets deleted and can't be queried anymore, setting this to true will not delete it from the previous contributions.

GitHub

FieldData TypeRequiredDefaultDescription
enabledbooleanYes-Indicates whether this data source is enabled. Alternatively you can also leave off the github object entirely.
allowPrivatebooleanNofalseWill throw if you pass a GITHUB_TOKEN with possible private repo scope. In most cases you will not want to have a token with private scope. Please think twice before enabling this config. When using fine-grained tokens, you need to set this to true manually as we can't detect the scopes. In that case, we can't guarantee anything!
commentsEnabledbooleanNotrueIndicates whether fetching comments is enabled.
commitsEnabledbooleanNotrueIndicates whether fetching commits is enabled.
issuesEnabledbooleanNotrueIndicates whether fetching issues is enabled.
reviewsEnabledbooleanNotrueIndicates whether fetching reviews is enabled.
usernamestringYes-Username on GitHub
stopDatestringYes-new Date() parseable string containing a date of possibly earliest contribution to track
filterstringYes-Regex to apply to each entry to filter for organization/repo names. For example: ^mozilla to only include orgs and repos that start with "mozilla".
typesObjectNo-Object containing the different labels below
types.commitstringNoGitHub CommitLabel for entries related to GitHub commits
types.privateCommitstringNoCommit in private repositoryLabel for entries related to private GitHub commits
types.createdPRstringNoCreated PRLabel for entries related to opening GitHub PRs
types.createdIssuestringNoCreated Issue ReportLabel for entries related to creating GitHub issues
types.commentedstringNoCommented on an IssueLabel for entries related to commenting on an issue
types.commentedPRstringNoCommented on a Pull RequestLabel for entries related to commenting on a GitHub PR (review)
types.approvedPRstringNoApproved a Pull RequestLabel for entries related to approving a GitHub PR
types.changesRequestedPRstringNoRequested changes on a Pull RequestLabel for entries related to requesting changes on a GitHub PR
types.reviewedPRstringNoReviewed a Pull RequestLabel for entries related to reviewing a GitHub PR (fallback)
delayMsPerRequestnumberNo2000Delay between each request to GitHub. You might hit rate limiting if you set this lower than default.

MediaWiki

FieldData TypeRequiredDefaultDescription
enabledbooleanYes-Indicates whether this data source is enabled. Alternatively you can also leave off the mediaWiki object entirely.
baseUrlstringYes-API base url without trailing slash
usernamestringYes-Username on MediaWiki
editTypestringNoWiki EditLabel for entries related to having edited an article.
stopDatestringYes-new Date() parseable string containing a date of possibly earliest contribution to track

Sample configuration

const config = {
  outputFile: `${__dirname}/_data/contributions.json`,
  bugzilla: {
    enabled: true,
    baseUrl: 'https://bugzilla.mozilla.org',
    username: 'me@michaelkohler.info',
    stopDate: '2008-01-01',
  },
  communityPortal: {
    enabled: true,
    baseUrl: 'https://community.mozilla.org/people',
    username: 'mkohler',
    participationType: 'Participated in an event',
    campaignType: 'Participated in a campaign',
  },
  discourse: {
    enabled: true,
    baseUrl: 'https://discourse.mozilla.org',
    username: 'mkohler',
    topicType: 'Created Discourse Topic',
    postType: 'Posted on Discourse Topic',
    keepDeletedPost: true,
  },
  mediaWiki: {
    enabled: true,
    baseUrl: 'https://wiki.mozilla.org/api.php?action=feedcontributions',
    username: 'michaelkohler',
    editType: 'Wiki Edit',
    stopDate: '2012-05-01',
  },
  github: {
    enabled: true,
    username: 'MichaelKohler',
    stopDate: '2008-01-01',
    filter: 'mozilla|common-voice|reps',
    types: {
      commit: 'GitHub Commit',
      privateCommit: 'Commit in private repository',
      createdPR: 'Created PR',
      createdIssue: 'Created Issue Report',
      commentedPR: 'Commented on a Pull Request',
      approvedPR: 'Approved a Pull Request',
      changesRequestedPR: 'Requested changes on a Pull Request',
      reviewedPR: 'Reviewed a Pull Request',
    },
  },
};

Developing

Any issues or PRs are welcome! Before doing major changes, please create an issue elaborating on the approach.

Setup

npm ci

Tests

npm run eslint
npm test

Testing changes

You can also add a temporary file with a test config as well as the call to fetchAll if you would like to test changes within this project. A sample config can be found in the configuration section above. Please make sure to not include that config file when committing!

Deployments

Please use Angular Commit Message Conventions when contributing to this project, as depending on the commit message the GitHub Action will directly publish a new version of the package.

2.5.0

7 months ago

2.4.0

9 months ago

2.3.8

1 year ago

2.3.7

1 year ago

2.3.6

1 year ago

2.3.5

1 year ago

2.3.4

1 year ago

2.3.3

1 year ago

2.3.2

2 years ago

2.3.1

2 years ago

2.3.0

2 years ago

2.2.0

2 years ago

2.1.2

2 years ago

2.1.1

2 years ago

2.1.0

2 years ago

2.0.0

2 years ago

1.0.1

2 years ago