Skip to content
Draft
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
67 changes: 33 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,85 +19,84 @@ This contribution counter is for 3 VCSs: GitHub, Bitbucket & GitLab and is a

### Installing

1. To install locally: `npm install contribution-counters --save`
2. To install globally: `npm install contribution-counters --global`
1. To install locally: `npm install contribution-counters --save`
2. To install globally: `npm install contribution-counters --global`

### Using module

1. Import the necessary counter like below:
1. Import the necessary counter like below:

`const { getGitHubCounts } = require("contribution-counters");`
`const { getGitHubContributions } = require("contribution-counters");`

2. Set up the configuration for the selected counter
2. Set up the configuration for the selected counter

The config is an object with the following properties (all available on all counters unless specified):

- `username`: Your username (string:required)
- `accessToken`: An access token for the user above (string:required)
- `minCommits`: The minimum number of commits a repo needs to count as a contribution (int:default=1)
- `includeCommits`: Whether to include count of your commits (bool:default=true)
- `includeProjects`: Whether to include count of repo/projects you've contributed to (bool:default=true)
- `includePullRequests`: Whether to include count of pull/merge request contributions (bool:default=false)
- `username`: Your username (string:required)
- `accessToken`: An access token for the user above (string:required)
- `minCommits`: The minimum number of commits a repo needs to count as a contribution (int:default=1)

The below two are only used if a commit doesn't have a real user attached (At least one is required for Bitbucket & GitLab & both optional for GitHub BUT advised to use both for all)

- `userEmailAddresses`: Array of email addresses which may be associated with your commits (array)
- `userNames`: Array of names which may be associated with your commits (array)
- `userEmailAddresses`: Array of email addresses which may be associated with your commits (array)
- `userNames`: Array of names which may be associated with your commits (array)

If you only want counts for after and/or before a particular date (inclusive) (or if you know the date you first and/or last contributed this can be used to minimise API requests)
If you only want contributions for after and/or before a particular date (inclusive) (or if you know the date you first and/or last contributed this can be used to minimise API requests)

- `fromDate`: Datetime string (ISO-8601 Date/timestamp (YYYY-MM-DDTHH:mm:ss.sssZ))
- `untilDate`: Datetime string (ISO-8601 Date/timestamp (YYYY-MM-DDTHH:mm:ss.sssZ))
- `fromDate`: Datetime string (ISO-8601 Date/timestamp (YYYY-MM-DDTHH:mm:ss.sssZ))
- `untilDate`: Datetime string (ISO-8601 Date/timestamp (YYYY-MM-DDTHH:mm:ss.sssZ))

To get repos of which you have a minimum access to

- `minRepoAccessLevel`: Only for GitLab (int:default=30)\[10, 20, 30, 40, 50] (see [here](https://docs.gitlab.com/ee/api/members.html))
- `minRepoRole`: Only for Bitbucket (string:default=contributor)\[admin, contributor, member, owner] (see [here](https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D))
- `minRepoRole`: Only for GitHub (comma separated string:default=owner,collaborator,organization_member)\[owner, collaborator, organization_member] (see [here](https://developer.github.com/v3/repos/#parameters))
- `minRepoAccessLevel`: Only for GitLab (int:default=30)\[10, 20, 30, 40, 50] (see [here](https://docs.gitlab.com/ee/api/members.html))
- `minRepoRole`: Only for Bitbucket (string:default=contributor)\[admin, contributor, member, owner] (see [here](https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D))
- `minRepoRole`: Only for GitHub (comma separated string:default=owner,collaborator,organization_member)\[owner, collaborator, organization_member] (see [here](https://developer.github.com/v3/repos/#parameters))

If you have a self-hosted GitLab, you will need to use the `url` option

- `url`: The URL where your GitLab is located at (for example `https://gitlab.jahidulpabelislam.com/` or `https://jahidulpabelislam.com/gitlab/`)

3. Start the counter with the following:
3. Start the counter with the following:

```javascript
const counts = await getGitHubCounts(config);
```
```javascript
const contributions = await getGitHubContributions(config);
```

4. The returned result (`counts`) is an object with one or more properties (based on what you've requested):
4. The returned result (`contributions`) is an object with one or more properties (based on what you've requested):

- `commits` total number of your commits
- `projects` total number of projects you've contributed to
- `pullRequests` total number of pull/merge requests you've authored
- `totalCommits` total number of your commits
- `totalProjects` total number of projects you've contributed to
- `totalPullRequests` total number of pull/merge requests you've authored
- todo

`getGitHubCounts` in the above example can be replaced with `getBitbucketCounts` or `getGitLabCounts`.
`getGitHubContributions` in the above example can be replaced with `getBitbucketContributions` or `getGitLabContributions`.

### Creating access tokens

- [GitHub](https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line)
- [GitLab](https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html#creating-a-personal-access-token)
- [Bitbucket](https://confluence.atlassian.com/bitbucketserver/personal-access-tokens-939515499.html)
- [GitHub](https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line)
- [GitLab](https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html#creating-a-personal-access-token)
- [Bitbucket](https://confluence.atlassian.com/bitbucketserver/personal-access-tokens-939515499.html)

## Upgrading

### v1 to v2

In version 2, the only breaking change is that only functions can be imported/required, instead of Counter classes.

To upgrade you will need to import/require the 3 new functions: `getBitbucketCounts`, `getGitHubCounts` & `getGitLabCounts` instead of `Bitbucket`, `GitHub` & `GitLab`.
To upgrade you will need to import/require the 3 new functions: `getBitbucketContributions`, `getGitHubContributions` & `getGitLabContributions` instead of `Bitbucket`, `GitHub` & `GitLab`.
Where before you created an instance of a class (e.g. `GitHub`) and passed in an object of config, then called a function (`getCounters`) to get the counts.

Now the new functions will do both in one. So just call the new function and pass in the existing config object as the only parameter and then your counts will be returned.

## Support

If you found this module interesting or useful please spread the word about this module: share on your socials, star on GitHub, etc.
If you found this module interesting or useful please do spread the word of this module: share on your social's, star on GitHub, etc.

If you find any issues or have any feature requests, you can open an [issue](https://github.com/jahidulpabelislam/contribution-counters/issues) or email [me @ jahidulpabelislam.com](mailto:[email protected]) :smirk:.

## Authors

- [Jahidul Pabel Islam](https://jahidulpabelislam.com/) [<[email protected]>](mailto:[email protected])
- [Jahidul Pabel Islam](https://jahidulpabelislam.com/) [<[email protected]>](mailto:[email protected])

## Licence

Expand Down
20 changes: 10 additions & 10 deletions example.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
*/

const {
getBitbucketCounts,
getGitHubCounts,
getGitLabCounts,
getBitbucketContributions,
getGitHubContributions,
getGitLabContributions
} = require("contribution-counters");

// Luckily as my username and email addresses will be consistent throughout all 3 counters, use the same global variables
Expand All @@ -22,32 +22,32 @@ let totalCommits = 0;
let totalProjects = 0;

// A generic wrapper function as all 3 counters are called the same way
const getCounts = async function(counterFunction, extraConfig = {}) {
const getCounts = async function(functionName, extraConfig = {}) {
const allConfig = {
username: username,
userEmailAddresses: userEmailAddresses,
userNames: userNames,
...extraConfig,
};
const counts = await counterFunction(allConfig);
const contributions = await functionName(allConfig);

// Here just update the total counts
totalCommits += counts.commits;
totalProjects += counts.projects;
totalCommits += contributions.totalCommits;
totalProjects += contributions.totalProjects;
};

const run = async function() {
await getCounts(getBitbucketCounts, {
await getCounts(getBitbucketContributions, {
accessToken: "hidden",
fromDate: "2019-06-02T00:00:00Z",
});

await getCounts(getGitHubCounts, {
await getCounts(getGitHubContributions, {
accessToken: "hidden",
fromDate: "2019-06-02T00:00:00Z",
});

await getCounts(getGitLabCounts, {
await getCounts(getGitLabContributions, {
accessToken: "hidden",
fromDate: "2019-06-02T00:00:00Z",
});
Expand Down
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/**
* A Node.js module to get commits and repos counts from Bitbucket, GitHub & GitLab
* A Node.js module to get commits and repos counts/data from Bitbucket, GitHub & GitLab
*
* The main file where the all the public functions are exported
*
* @author Jahidul Pabel Islam <[email protected]>
* @copyright (c) 2010 - 2022 JPI
* @copyright (c) 2010 - 2024 JPI
* @license: GPL-3.0
*/

Expand All @@ -21,7 +21,7 @@ const exposer = function(counterClass) {
};

module.exports = {
getBitbucketCounts: exposer(BitbucketCounter),
getGitHubCounts: exposer(GitHubCounter),
getGitLabCounts: exposer(GitLabCounter),
getBitbucketContributions: exposer(BitbucketCounter),
getGitHubContributions: exposer(GitHubCounter),
getGitLabContributions: exposer(GitLabCounter),
};
Loading