Skip to content

Commit

Permalink
v3.2.0: Add the include option
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelmhtr committed Dec 29, 2024
1 parent 16c7b08 commit 0823109
Show file tree
Hide file tree
Showing 20 changed files with 141 additions and 110 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog
All notable changes to this project will be documented in this file.

## [3.2.0] - 2024-12-28
### Added
- The option `include` to include only specific users in the stats.

## [3.1.0] - 2024-12-22
### Added
- Adds new available stats: `reviewedAdditions`, `reviewedDeletions`, `reviewedLines`, `totalObservations`, `medianObservations`, `revisionSuccessRate`, `additions`, `deletions` and `lines`.
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ The possible inputs for this action are:
| `disableLinks` | If `true`, removes the links to the detailed charts. Possible values: `true` or `false`. | `false` |
| `sortBy` | The column used to sort the data. Possible values: `totalReviews`, `timeToReview`, `totalComments`, `commentsPerReview`, `openedPullRequests`. | `totalReviews` |
| `publishAs` | Where to publish the results. Possible values: `COMMENT`, `DESCRIPTION`, or `NONE`. | `COMMENT` |
| `exclude` | A comma-separated list of usernames (case-insensitive) to be excluded from the results (e.g. `username1,username2`), or a regular expression enclosed between slashes (e.g. `/^bot/i` will exclude all usernames that begin with "bot"). | `null` |
| `exclude` | A comma-separated list of usernames (case-insensitive) to be excluded from the results (e.g. `username1,username2`), or a regular expression enclosed between slashes (e.g. `/^bot/i` will exclude all usernames that begin with "bot"). | `null` |
| `include` | A comma-separated list of usernames (case-insensitive) to be the only ones included in the results (e.g. `username1,username2`), or a regular expression enclosed between slashes (e.g. `/^bot/i` will include only usernames that begin with "bot"). | `null` |
| `telemetry` | Indicates if the action is allowed to send monitoring data to the developer. This data is [minimal](/src/services/telemetry/sendStart.js) and helps improve this action. **This option is a premium feature reserved for [sponsors](#premium-features-).** | `true` |
| `slackWebhook` | A Slack webhook URL to post resulting stats. **This option is a premium feature reserved for [sponsors](#premium-features-).** See [full documentation here](/docs/slack.md). | `null` |
| `slackChannel` | The Slack channel where stats will be posted. Include the `#` character (e.g. `#mychannel`). Required when a `slackWebhook` is configured. | `null` |
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ inputs:
exclude:
description: 'A list or regular expression to exclude users from the stats'
required: false
include:
description: 'A list or regular expression to specify the users that will be included in the stats'
required: false
disableLinks:
description: 'Prevents from adding any external links in the stats'
required: false
Expand Down
53 changes: 29 additions & 24 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42160,6 +42160,7 @@ const run = async ({ inputs, octokit }) => {
core,
pulls,
excludeStr: inputs.excludeStr,
includeStr: inputs.includeStr,
periodLength: inputs.periodLength,
});
core.debug(`Analyzed entries: ${entries.length}`);
Expand Down Expand Up @@ -43076,9 +43077,10 @@ module.exports = async ({
core,
pulls,
excludeStr,
includeStr,
periodLength,
}) => {
const users = await getUsers(pulls, { excludeStr });
const users = await getUsers(pulls, { excludeStr, includeStr });
core.info(`Found ${users.length} collaborators to analyze`);
core.debug(JSON.stringify(users, null, 2));

Expand Down Expand Up @@ -43300,19 +43302,6 @@ module.exports = (pulls) => {
};


/***/ }),

/***/ 6691:
/***/ ((module) => {

module.exports = (exclude, username) => {
if (!username) return false;
if (exclude.test) return !exclude.test(username);
if (exclude.includes) return !exclude.includes(username);
return true;
};


/***/ }),

/***/ 3317:
Expand All @@ -43338,22 +43327,25 @@ module.exports = (pulls) => {
/***/ 5304:
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {

const filterUser = __nccwpck_require__(6691);
const testFilter = __nccwpck_require__(756);
const findUsers = __nccwpck_require__(3317);
const parseExclude = __nccwpck_require__(1465);
const parseFilter = __nccwpck_require__(7265);

module.exports = (pulls, { excludeStr } = {}) => {
const exclude = parseExclude(excludeStr);
module.exports = (pulls, { excludeStr, includeStr } = {}) => {
const include = parseFilter(includeStr);
const exclude = parseFilter(excludeStr);
const users = findUsers(pulls);

return users
.filter(({ login }) => filterUser(exclude, login));
.filter(({ login }) => !!login)
.filter(({ login }) => !include || testFilter(include, login))
.filter(({ login }) => !exclude || !testFilter(exclude, login));
};


/***/ }),

/***/ 1465:
/***/ 7265:
/***/ ((module) => {

const REGEXP_PATTERN = /^\/.+\/[a-z]*$/;
Expand All @@ -43368,10 +43360,22 @@ const parseRegExp = (str) => {
return new RegExp(pattern, flags);
};

module.exports = (excludeStr) => {
if (!sanitize(excludeStr)) return [];
if (isRegExp(excludeStr)) return parseRegExp(excludeStr);
return excludeStr.split(',').map(sanitize);
module.exports = (filterStr) => {
if (!sanitize(filterStr)) return null;
if (isRegExp(filterStr)) return parseRegExp(filterStr);
return filterStr.split(',').map(sanitize);
};


/***/ }),

/***/ 756:
/***/ ((module) => {

module.exports = (filter, username) => {
if (filter.test) return filter.test(username);
if (filter.includes) return filter.includes(username);
return false;
};


Expand Down Expand Up @@ -44212,6 +44216,7 @@ module.exports = ({ core, github, currentRepo }) => {
disableLinks: core.getBooleanInput('disableLinks'),
limit: parseInt(core.getInput('limit'), 10),
excludeStr: core.getInput('exclude'),
includeStr: core.getInput('include'),
telemetry: core.getBooleanInput('telemetry'),
webhook: core.getInput('webhook'),
slack: {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pull-request-stats",
"version": "3.1.0",
"version": "3.2.0",
"description": "Github action to print relevant stats about Pull Request reviewers",
"main": "dist/index.js",
"type": "commonjs",
Expand Down
3 changes: 3 additions & 0 deletions src/__tests__/execute.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ describe('execute', () => {
displayCharts: 'displayCharts',
publishAs: 'publishAs',
pullRequestId: 'pullRequestId',
excludeStr: 'excludeStr',
includeStr: 'includeStr',
slack: 'slack',
teams: 'teams',
webhook: 'webhook',
Expand Down Expand Up @@ -100,6 +102,7 @@ describe('execute', () => {
core,
pulls,
excludeStr: inputs.excludeStr,
includeStr: inputs.includeStr,
periodLength: inputs.periodLength,
});
expect(publish).toBeCalledWith({
Expand Down
1 change: 1 addition & 0 deletions src/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const run = async ({ inputs, octokit }) => {
core,
pulls,
excludeStr: inputs.excludeStr,
includeStr: inputs.includeStr,
periodLength: inputs.periodLength,
});
core.debug(`Analyzed entries: ${entries.length}`);
Expand Down
6 changes: 5 additions & 1 deletion src/interactors/__tests__/getEntries.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe('Interactors | .getEntries', () => {
core,
pulls,
excludeStr: 'EXCLUDE',
includeStr: 'INCLUDE',
periodLength: 'PERIOD_LENGTH',
};

Expand All @@ -35,7 +36,10 @@ describe('Interactors | .getEntries', () => {
it('calls the correct interactors with the expected params', async () => {
const results = await getEntries(params);
expect(results).toBe(entries);
expect(getUsers).toBeCalledWith(pulls, { excludeStr: params.excludeStr });
expect(getUsers).toBeCalledWith(pulls, {
excludeStr: params.excludeStr,
includeStr: params.includeStr,
});
expect(getPullRequestStats).toBeCalledWith(pulls);
expect(getReviewStats).toBeCalledWith(pulls);
expect(mergeStats).toBeCalledWith({ users, pullRequestStats, reviewStats });
Expand Down
3 changes: 2 additions & 1 deletion src/interactors/getEntries.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ module.exports = async ({
core,
pulls,
excludeStr,
includeStr,
periodLength,
}) => {
const users = await getUsers(pulls, { excludeStr });
const users = await getUsers(pulls, { excludeStr, includeStr });
core.info(`Found ${users.length} collaborators to analyze`);
core.debug(JSON.stringify(users, null, 2));

Expand Down
39 changes: 0 additions & 39 deletions src/interactors/getUsers/__tests__/filterUser.test.js

This file was deleted.

13 changes: 13 additions & 0 deletions src/interactors/getUsers/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,17 @@ describe('Interactors | getUsers', () => {
expect(result.length).toEqual(2);
expect(getLogins(result)).not.toContain('manuelmhtr');
});

it('includes reviewers when the option is passed', () => {
const result = getUsers(input, { includeStr: 'manuelmhtr' });
expect(result.length).toEqual(1);
expect(getLogins(result)).toContain('manuelmhtr');
});

it('removes the empty usernames', () => {
const emptyAuthor = { id: '1', login: '' };
const emptyInput = { author: emptyAuthor, reviews: [] };
const result = getUsers([emptyInput]);
expect(result.length).toEqual(0);
});
});
28 changes: 0 additions & 28 deletions src/interactors/getUsers/__tests__/parseExclude.test.js

This file was deleted.

28 changes: 28 additions & 0 deletions src/interactors/getUsers/__tests__/parseFilter.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const parseFilter = require('../parseFilter');

describe('Interactors | getUsers | .parseFilter', () => {
it('returns null when the input does not contain usernames or regexp', () => {
expect(parseFilter()).toEqual(null);
expect(parseFilter(null)).toEqual(null);
expect(parseFilter('')).toEqual(null);
expect(parseFilter('@')).toEqual(null);
expect(parseFilter('/@/%^')).toEqual(null);
});

it('splits usernames into an array', () => {
expect(parseFilter('user1,user2')).toEqual(['user1', 'user2']);
});

it('removes spaces and converts usernames to lowercase', () => {
expect(parseFilter('User1, USER2')).toEqual(['user1', 'user2']);
});

it('removes invalid characters from usernames', () => {
expect(parseFilter('@user1, @user%2ñ, keep-dashes-ok')).toEqual(['user1', 'user2', 'keep-dashes-ok']);
});

it('parses regexp strings', () => {
expect(parseFilter('/user[0-9]/')).toEqual(/user[0-9]/);
expect(parseFilter('/^bot-.*/ig')).toEqual(/^bot-.*/ig);
});
});
30 changes: 30 additions & 0 deletions src/interactors/getUsers/__tests__/testFilter.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const testFilter = require('../testFilter');

describe('Interactors | getUsers | .testFilter', () => {
const reviewers = [
'manuelmhtr',
'jartmez',
'bot1',
'bot2',
];

it('filters out reviewers by a list of usernames', () => {
const filter = ['manuelmhtr', 'jartmez'];
const results = reviewers.filter((reviewer) => testFilter(filter, reviewer));
expect(results.length).toEqual(2);
expect(results).toEqual([
'manuelmhtr',
'jartmez',
]);
});

it('filters out reviewers by a regular expression', () => {
const filter = /bot/;
const results = reviewers.filter((reviewer) => testFilter(filter, reviewer));
expect(results.length).toEqual(2);
expect(results).toEqual([
'bot1',
'bot2',
]);
});
});
6 changes: 0 additions & 6 deletions src/interactors/getUsers/filterUser.js

This file was deleted.

13 changes: 8 additions & 5 deletions src/interactors/getUsers/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
const filterUser = require('./filterUser');
const testFilter = require('./testFilter');
const findUsers = require('./findUsers');
const parseExclude = require('./parseExclude');
const parseFilter = require('./parseFilter');

module.exports = (pulls, { excludeStr } = {}) => {
const exclude = parseExclude(excludeStr);
module.exports = (pulls, { excludeStr, includeStr } = {}) => {
const include = parseFilter(includeStr);
const exclude = parseFilter(excludeStr);
const users = findUsers(pulls);

return users
.filter(({ login }) => filterUser(exclude, login));
.filter(({ login }) => !!login)
.filter(({ login }) => !include || testFilter(include, login))
.filter(({ login }) => !exclude || !testFilter(exclude, login));
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const parseRegExp = (str) => {
return new RegExp(pattern, flags);
};

module.exports = (excludeStr) => {
if (!sanitize(excludeStr)) return [];
if (isRegExp(excludeStr)) return parseRegExp(excludeStr);
return excludeStr.split(',').map(sanitize);
module.exports = (filterStr) => {
if (!sanitize(filterStr)) return null;
if (isRegExp(filterStr)) return parseRegExp(filterStr);
return filterStr.split(',').map(sanitize);
};
5 changes: 5 additions & 0 deletions src/interactors/getUsers/testFilter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = (filter, username) => {
if (filter.test) return filter.test(username);
if (filter.includes) return filter.includes(username);
return false;
};
Loading

0 comments on commit 0823109

Please sign in to comment.