Skip to content

Commit

Permalink
v2.0.1: Fix bug with non-user authors.
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelmhtr committed Apr 19, 2021
1 parent abdf52b commit 1bc7657
Show file tree
Hide file tree
Showing 12 changed files with 291 additions and 172 deletions.
23 changes: 14 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
# Changelog
All notable changes to this project will be documented in this file.

## [2.0.1] - 2021-04-19
### Changed
- Fixes bug related with bots authoring or reviewing pull requests (#3)
- Fixed bug on `href` property in avatars (adds ").

## [2.0.0] - 2021-04-03
### Added
- Adds the option `organization` to calculate the stats **across all the repos** in the organization.

### Changed
- Switched to Github's GraphAPI to minimize the number of requests and **calculate the stats faster**.
- The stats are printed at the bottom of the description of the pull request, rather than as a commit comment.
- When the title "Pull reviewers stats" is already present in the pull request the action is skipped.
- "Avg. time to first review" is renamed to "Median time to review", and is no longer the average but the median.
- "Total pull reviews" is renamed to "Total reviews".
- The default order is now by "Total reviews".
- The columns order depends on the "sort-by" option, to put the sorting column first.
- When the title `Pull reviewers stats` is already present in the pull request the action is skipped.
- `Avg. time to first review` is renamed to `Median time to review`, and is no longer the average but the median.
- `Total pull reviews` is renamed to `Total reviews`.
- The default order is now by `Total reviews`.
- The columns order depends on the `sort-by` option, to put the sorting column first.


## [1.1.0] - 2020-10-27
Expand All @@ -22,20 +27,20 @@ All notable changes to this project will be documented in this file.


## [1.0.3] - 2020-10-23
### Changes
### Changed
- Adds support for the `pull_request` event.


## [1.0.2] - 2020-07-20
### Changes
### Changed
- Adds Mixpanel to get some usage insights.


## [1.0.1] - 2020-07-13
### Changes
### Changed
- Bug fixing.


## [1.0.0] - 2020-07-13
### Changes
### Changed
- First launch, with ♥ from Guadalajara, Mexico.
31 changes: 19 additions & 12 deletions README.md

Large diffs are not rendered by default.

333 changes: 218 additions & 115 deletions dist/index.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/fetchers/fetchPullRequests.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ query($search: String!, $limit: Int!, $after: String) {
}
}
fragment ActorFragment on Actor {
fragment ActorFragment on User {
url
login
avatarUrl
databaseId
}
`;

Expand Down
8 changes: 4 additions & 4 deletions src/interactors/buildTable/__tests__/getTableData.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ const TITLES = {
totalComments: 'Total comments',
};

const AVATAR1 = '<a href=https://github.com/user1><img src="https://avatars.githubusercontent.com/u/1234" width="20"></a>';
const AVATAR2 = '<a href=https://github.com/user2><img src="https://avatars.githubusercontent.com/u/5678" width="20"></a>';
const AVATAR1_BIG = '<a href=https://github.com/user1><img src="https://avatars.githubusercontent.com/u/1234" width="32"></a>';
const AVATAR2_BIG = '<a href=https://github.com/user2><img src="https://avatars.githubusercontent.com/u/5678" width="32"></a>';
const AVATAR1 = '<a href="https://github.com/user1"><img src="https://avatars.githubusercontent.com/u/1234" width="20"></a>';
const AVATAR2 = '<a href="https://github.com/user2"><img src="https://avatars.githubusercontent.com/u/5678" width="20"></a>';
const AVATAR1_BIG = '<a href="https://github.com/user1"><img src="https://avatars.githubusercontent.com/u/1234" width="32"></a>';
const AVATAR2_BIG = '<a href="https://github.com/user2"><img src="https://avatars.githubusercontent.com/u/5678" width="32"></a>';

const SIMPLE_RESPONSE = [
TITLES,
Expand Down
48 changes: 24 additions & 24 deletions src/interactors/buildTable/__tests__/index.test.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
const reviewers = require('./mocks/reviewersWithStats.json');
const buildTable = require('../index');

const SIMPLE_RESPONSE = `| | User | Total reviews | Median time to review | Total comments |
| -------------------------------------------------------------------------------------------------------- | ----- | ------------- | --------------------- | -------------- |
| <a href=https://github.com/user1><img src="https://avatars.githubusercontent.com/u/1234" width="20"></a> | user1 | **4** | **34m** | 1 |
| <a href=https://github.com/user2><img src="https://avatars.githubusercontent.com/u/5678" width="20"></a> | user2 | 1 | 2h 21m | **5** |`;

const CHARTS_RESPONSE = `| | User | Total reviews | Median time to review | Total comments |
| -------------------------------------------------------------------------------------------------------- | ------------ | ------------------ | --------------------- | ------------------ |
| <a href=https://github.com/user1><img src="https://avatars.githubusercontent.com/u/1234" width="32"></a> | user1<br/>🥇 | **4**<br/>▀▀▀▀▀▀▀▀ | **34m**<br/>▀▀ | 1<br/>▀▀ |
| <a href=https://github.com/user2><img src="https://avatars.githubusercontent.com/u/5678" width="32"></a> | user2<br/>🥈 | 1<br/>▀▀ | 2h 21m<br/>▀▀▀▀▀▀▀▀ | **5**<br/>▀▀▀▀▀▀▀▀ |`;

const SORTED_RESPONSE = `| | User | Total reviews | Median time to review | Total comments |
| -------------------------------------------------------------------------------------------------------- | ----- | ------------- | --------------------- | -------------- |
| <a href=https://github.com/user2><img src="https://avatars.githubusercontent.com/u/5678" width="20"></a> | user2 | 1 | 2h 21m | **5** |
| <a href=https://github.com/user1><img src="https://avatars.githubusercontent.com/u/1234" width="20"></a> | user1 | **4** | **34m** | 1 |`;

const LINKS_RESPONSE = `| | User | Total reviews | Median time to review | Total comments |
| -------------------------------------------------------------------------------------------------------- | ----- | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------- |
| <a href=https://github.com/user1><img src="https://avatars.githubusercontent.com/u/1234" width="20"></a> | user1 | **4** | [**34m**](https://app.flowwer.dev/charts/review-time/~(u~(i~'1234~n~'user1)~r~(~(d~'qpvagu~t~'a3)~(d~'qpvn25~t~'3lu)~(d~'qprzn9~t~'84)~(d~'qqqtu5~t~'2vy)))) | 1 |
| <a href=https://github.com/user2><img src="https://avatars.githubusercontent.com/u/5678" width="20"></a> | user2 | 1 | [2h 21m](https://app.flowwer.dev/charts/review-time/~(u~(i~'5678~n~'user2)~r~(~(d~'qq0fbc~t~'6j5)))) | **5** |`;

const LINKS_AND_CHARTS_RESPONSE = `| | User | Total reviews | Median time to review | Total comments |
| -------------------------------------------------------------------------------------------------------- | ------------ | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ |
| <a href=https://github.com/user1><img src="https://avatars.githubusercontent.com/u/1234" width="32"></a> | user1<br/>🥇 | **4**<br/>▀▀▀▀▀▀▀▀ | [**34m**](https://app.flowwer.dev/charts/review-time/~(u~(i~'1234~n~'user1)~r~(~(d~'qpvagu~t~'a3)~(d~'qpvn25~t~'3lu)~(d~'qprzn9~t~'84)~(d~'qqqtu5~t~'2vy))))<br/>▀▀ | 1<br/>▀▀ |
| <a href=https://github.com/user2><img src="https://avatars.githubusercontent.com/u/5678" width="32"></a> | user2<br/>🥈 | 1<br/>▀▀ | [2h 21m](https://app.flowwer.dev/charts/review-time/~(u~(i~'5678~n~'user2)~r~(~(d~'qq0fbc~t~'6j5))))<br/>▀▀▀▀▀▀▀▀ | **5**<br/>▀▀▀▀▀▀▀▀ |`;
const SIMPLE_RESPONSE = `| | User | Total reviews | Median time to review | Total comments |
| ---------------------------------------------------------------------------------------------------------- | ----- | ------------- | --------------------- | -------------- |
| <a href="https://github.com/user1"><img src="https://avatars.githubusercontent.com/u/1234" width="20"></a> | user1 | **4** | **34m** | 1 |
| <a href="https://github.com/user2"><img src="https://avatars.githubusercontent.com/u/5678" width="20"></a> | user2 | 1 | 2h 21m | **5** |`;

const CHARTS_RESPONSE = `| | User | Total reviews | Median time to review | Total comments |
| ---------------------------------------------------------------------------------------------------------- | ------------ | ------------------ | --------------------- | ------------------ |
| <a href="https://github.com/user1"><img src="https://avatars.githubusercontent.com/u/1234" width="32"></a> | user1<br/>🥇 | **4**<br/>▀▀▀▀▀▀▀▀ | **34m**<br/>▀▀ | 1<br/>▀▀ |
| <a href="https://github.com/user2"><img src="https://avatars.githubusercontent.com/u/5678" width="32"></a> | user2<br/>🥈 | 1<br/>▀▀ | 2h 21m<br/>▀▀▀▀▀▀▀▀ | **5**<br/>▀▀▀▀▀▀▀▀ |`;

const SORTED_RESPONSE = `| | User | Total reviews | Median time to review | Total comments |
| ---------------------------------------------------------------------------------------------------------- | ----- | ------------- | --------------------- | -------------- |
| <a href="https://github.com/user2"><img src="https://avatars.githubusercontent.com/u/5678" width="20"></a> | user2 | 1 | 2h 21m | **5** |
| <a href="https://github.com/user1"><img src="https://avatars.githubusercontent.com/u/1234" width="20"></a> | user1 | **4** | **34m** | 1 |`;

const LINKS_RESPONSE = `| | User | Total reviews | Median time to review | Total comments |
| ---------------------------------------------------------------------------------------------------------- | ----- | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------- |
| <a href="https://github.com/user1"><img src="https://avatars.githubusercontent.com/u/1234" width="20"></a> | user1 | **4** | [**34m**](https://app.flowwer.dev/charts/review-time/~(u~(i~'1234~n~'user1)~r~(~(d~'qpvagu~t~'a3)~(d~'qpvn25~t~'3lu)~(d~'qprzn9~t~'84)~(d~'qqqtu5~t~'2vy)))) | 1 |
| <a href="https://github.com/user2"><img src="https://avatars.githubusercontent.com/u/5678" width="20"></a> | user2 | 1 | [2h 21m](https://app.flowwer.dev/charts/review-time/~(u~(i~'5678~n~'user2)~r~(~(d~'qq0fbc~t~'6j5)))) | **5** |`;

const LINKS_AND_CHARTS_RESPONSE = `| | User | Total reviews | Median time to review | Total comments |
| ---------------------------------------------------------------------------------------------------------- | ------------ | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ |
| <a href="https://github.com/user1"><img src="https://avatars.githubusercontent.com/u/1234" width="32"></a> | user1<br/>🥇 | **4**<br/>▀▀▀▀▀▀▀▀ | [**34m**](https://app.flowwer.dev/charts/review-time/~(u~(i~'1234~n~'user1)~r~(~(d~'qpvagu~t~'a3)~(d~'qpvn25~t~'3lu)~(d~'qprzn9~t~'84)~(d~'qqqtu5~t~'2vy))))<br/>▀▀ | 1<br/>▀▀ |
| <a href="https://github.com/user2"><img src="https://avatars.githubusercontent.com/u/5678" width="32"></a> | user2<br/>🥈 | 1<br/>▀▀ | [2h 21m](https://app.flowwer.dev/charts/review-time/~(u~(i~'5678~n~'user2)~r~(~(d~'qq0fbc~t~'6j5))))<br/>▀▀▀▀▀▀▀▀ | **5**<br/>▀▀▀▀▀▀▀▀ |`;

describe('Interactors | .buildTable', () => {
it('returns all available reviewers in a set of pull requests', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/interactors/buildTable/getTableData.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const getChartsData = ({ index, contributions, displayCharts }) => {

const bold = (value) => `**${value}**`;

const buildLink = (href, content) => `<a href=${href}>${content}</a>`;
const buildLink = (href, content) => `<a href="${href}">${content}</a>`;

const buildImage = (src, width) => `<img src="${src}" width="${width}">`;

Expand Down
3 changes: 3 additions & 0 deletions src/interactors/getReviewers/groupReviews.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
module.exports = (pulls) => {
const removeOwnPulls = ({ isOwnPull }) => !isOwnPull;

const removeWithEmptyId = ({ id }) => !!id;

const all = Object.values(pulls).reduce((acc, pull) => {
const reviews = pull.reviews
.filter(removeOwnPulls)
.filter(removeWithEmptyId)
.map((r) => ({ ...r, pullId: pull.id }));
return acc.concat(reviews);
}, []);
Expand Down
3 changes: 3 additions & 0 deletions src/parsers/__tests__/mocks/pullRequest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"id": 12345,
"publishedAt": "2021-02-12T23:54:38Z",
"author": {
"databaseId": "1031639",
"url": "https://github.com/manuelmhtr",
"login": "manuelmhtr",
"avatarUrl": "https://avatars.githubusercontent.com/u/1031639?u=30204017b73f7a1f08005cb8ead3f70b0410486c&v=4"
Expand All @@ -19,6 +20,7 @@
"totalCount": 1
},
"author": {
"databaseId": "1031639",
"url": "https://github.com/manuelmhtr",
"login": "manuelmhtr",
"avatarUrl": "https://avatars.githubusercontent.com/u/1031639?u=30204017b73f7a1f08005cb8ead3f70b0410486c&v=4"
Expand All @@ -33,6 +35,7 @@
"totalCount": 3
},
"author": {
"databaseId": "22161828",
"url": "https://github.com/Estebes10",
"login": "Estebes10",
"avatarUrl": "https://avatars.githubusercontent.com/u/22161828?v=4"
Expand Down
1 change: 1 addition & 0 deletions src/parsers/__tests__/mocks/review.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"totalCount": 1
},
"author": {
"databaseId": "1031639",
"url": "https://github.com/manuelmhtr",
"login": "manuelmhtr",
"avatarUrl": "https://avatars.githubusercontent.com/u/1031639?u=30204017b73f7a1f08005cb8ead3f70b0410486c&v=4"
Expand Down
1 change: 1 addition & 0 deletions src/parsers/__tests__/mocks/user.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"databaseId": "1031639",
"url": "https://github.com/manuelmhtr",
"login": "manuelmhtr",
"avatarUrl": "https://avatars.githubusercontent.com/u/1031639?u=30204017b73f7a1f08005cb8ead3f70b0410486c&v=4"
Expand Down
7 changes: 1 addition & 6 deletions src/parsers/parseUser.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
const ID_PREFIX = 'https://avatars.githubusercontent.com/u/';
const ID_REGEXP = /^[0-9]+/;

const extractId = (url) => url.replace(ID_PREFIX, '').match(ID_REGEXP)[0];

module.exports = (data = {}) => ({
id: extractId(data.avatarUrl),
id: data.databaseId,
url: data.url,
login: data.login,
avatarUrl: data.avatarUrl,
Expand Down

0 comments on commit 1bc7657

Please sign in to comment.