Skip to content

Commit

Permalink
v2.4.3: Fixes bug on schedule event. External sponsors.
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelmhtr committed Aug 4, 2022
1 parent 326f3a7 commit 3dd7ada
Show file tree
Hide file tree
Showing 18 changed files with 155 additions and 44 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Changelog
All notable changes to this project will be documented in this file.

## [2.4.3] - 2022-08-03
### Added
- Support for external sponsors.
### Changed
- Improved description links.
### Fixed
- [#44](https://github.com/flowwer-dev/pull-request-stats/issues/44) Fixed problem reading repo when triggered by `schedule` event.

## [2.4.2] - 2022-06-21
### Fixed
- [#37](https://github.com/flowwer-dev/pull-request-stats/issues/37) Problem causing `token` parameter to be empty.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ Used by hundreds of successful teams:

This project is maintained by a single person, considering supporting the project by:

* Sharing your [feedback](https://forms.gle/W18tgBWp5YWt2qYEA).
* Sharing your [feedback](https://github.com/flowwer-dev/pull-request-stats/discussions/new).
* Joining the [community](https://discord.gg/SGYbZkac).
* Becoming a [sponsor](https://github.com/sponsors/manuelmhtr).

Expand Down
53 changes: 41 additions & 12 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1248,9 +1248,15 @@ const getRepoOwner = (repo) => {
return owner;
};

const getRepoName = (repo) => {
const [, name] = getRepoComponents(repo);
return name;
};

module.exports = {
getRepoComponents,
getRepoOwner,
getRepoName,
};


Expand Down Expand Up @@ -2222,33 +2228,40 @@ exports.checkBypass = checkBypass;
/***/ (function(module, __unusedexports, __webpack_require__) {

const { t } = __webpack_require__(781);
const { getRepoComponents } = __webpack_require__(109);

module.exports = ({
org,
repos,
buildGithubLink,
limit = 3,
}) => {
const buildLink = (path) => {
const [owner, name] = getRepoComponents(path);
const description = name || owner;
return buildGithubLink({ description, path });
};

const buildLimitedSources = (sources) => {
const firsts = sources.slice(0, limit - 1);
const othersCount = sources.length - firsts.length;
return t('table.sources.andOthers', {
firsts: firsts.map(buildGithubLink).join(t('table.sources.separator')),
firsts: firsts.map(buildLink).join(t('table.sources.separator')),
count: othersCount,
});
};

const buildFullList = (sources) => {
const last = sources.pop();
return t('table.sources.fullList', {
firsts: sources.map(buildGithubLink).join(t('table.sources.separator')),
last: buildGithubLink(last),
firsts: sources.map(buildLink).join(t('table.sources.separator')),
last: buildLink(last),
});
};

const getSources = () => {
if (org) return buildGithubLink(org);
if (repos.length === 1) return buildGithubLink(repos);
if (org) return buildLink(org);
if (repos.length === 1) return buildLink(repos[0]);
if (repos.length > limit) return buildLimitedSources(repos);
return buildFullList(repos);
};
Expand Down Expand Up @@ -5826,10 +5839,12 @@ const divide = __webpack_require__(318);
const durationToString = __webpack_require__(715);
const isNil = __webpack_require__(125);
const median = __webpack_require__(825);
const repos = __webpack_require__(109);
const subtractDaysToDate = __webpack_require__(689);
const sum = __webpack_require__(358);

module.exports = {
...repos,
average,
buildSources,
divide,
Expand Down Expand Up @@ -7016,6 +7031,7 @@ module.exports = ({ tracker, timeMs }) => {
const { fetchSponsorships } = __webpack_require__(162);
const getLogins = __webpack_require__(379);
const isSponsoring = __webpack_require__(477);
const isExternalSponsor = __webpack_require__(581);

module.exports = async ({
octokit,
Expand All @@ -7024,7 +7040,7 @@ module.exports = async ({
}) => {
const logins = getLogins({ org, repos });
const { user } = await fetchSponsorships({ octokit, logins });
return isSponsoring(user);
return isSponsoring(user) || isExternalSponsor(logins);
};


Expand Down Expand Up @@ -13209,6 +13225,21 @@ function omit(obj, ...keys) {
}
//# sourceMappingURL=agent.js.map

/***/ }),

/***/ 581:
/***/ (function(module) {

// A list of organizations which are sponsoring this project outside Github 💙
const externalSponsors = new Set([
'yotepresto-com',
'zenfi',
]);

module.exports = (logins) => [...(logins || [])]
.some((login) => externalSponsors.has(login));


/***/ }),

/***/ 587:
Expand Down Expand Up @@ -13567,7 +13598,7 @@ module.exports = require("net");
const { t } = __webpack_require__(781);
const { buildSources } = __webpack_require__(353);

const buildGithubLink = (object) => `[${object}](https://github.com/${object})`;
const buildGithubLink = ({ description, path }) => `[${description}](https://github.com/${path})`;

module.exports = ({
table,
Expand Down Expand Up @@ -14611,9 +14642,7 @@ const getRepositories = (currentRepo) => {
const getPrId = () => get(github, 'context.payload.pull_request.node_id');

const getParams = () => {
const { payload } = github.context || {};
const { repository } = payload || {};
const currentRepo = repository.full_name;
const currentRepo = process.env.GITHUB_REPOSITORY;
const githubToken = core.getInput('github-token');
const personalToken = core.getInput('token') || githubToken;

Expand Down Expand Up @@ -14828,7 +14857,7 @@ module.exports = function bind(fn, thisArg) {
/***/ 731:
/***/ (function(module) {

module.exports = {"name":"pull-request-stats","version":"2.4.2","description":"Github action to print relevant stats about Pull Request reviewers","main":"dist/index.js","scripts":{"build":"ncc build src/index.js","test":"yarn run build && jest"},"keywords":[],"author":"Manuel de la Torre","license":"MIT","jest":{"testEnvironment":"node","testMatch":["**/?(*.)+(spec|test).[jt]s?(x)"]},"dependencies":{"@actions/core":"^1.5.0","@actions/github":"^5.0.0","@sentry/react-native":"^3.4.2","axios":"^0.26.1","dotenv":"^16.0.1","graphql":"^16.5.0","graphql-anywhere":"^4.2.7","humanize-duration":"^3.27.0","i18n-js":"^3.9.2","jsurl":"^0.1.5","lodash":"^4.17.21","lodash.get":"^4.4.2","lottie-react-native":"^5.1.3","markdown-table":"^2.0.0","mixpanel":"^0.13.0"},"devDependencies":{"@zeit/ncc":"^0.22.3","eslint":"^7.32.0","eslint-config-airbnb-base":"^14.2.1","eslint-plugin-import":"^2.24.1","eslint-plugin-jest":"^24.4.0","jest":"^27.0.6"}};
module.exports = {"name":"pull-request-stats","version":"2.4.3","description":"Github action to print relevant stats about Pull Request reviewers","main":"dist/index.js","scripts":{"build":"ncc build src/index.js","test":"yarn run build && jest"},"keywords":[],"author":"Manuel de la Torre","license":"MIT","jest":{"testEnvironment":"node","testMatch":["**/?(*.)+(spec|test).[jt]s?(x)"]},"dependencies":{"@actions/core":"^1.5.0","@actions/github":"^5.0.0","@sentry/react-native":"^3.4.2","axios":"^0.26.1","dotenv":"^16.0.1","graphql":"^16.5.0","graphql-anywhere":"^4.2.7","humanize-duration":"^3.27.0","i18n-js":"^3.9.2","jsurl":"^0.1.5","lodash":"^4.17.21","lodash.get":"^4.4.2","lottie-react-native":"^5.1.3","markdown-table":"^2.0.0","mixpanel":"^0.13.0"},"devDependencies":{"@zeit/ncc":"^0.22.3","eslint":"^7.32.0","eslint-config-airbnb-base":"^14.2.1","eslint-plugin-import":"^2.24.1","eslint-plugin-jest":"^24.4.0","jest":"^27.0.6"}};

/***/ }),

Expand Down Expand Up @@ -18074,7 +18103,7 @@ const getPRText = (pullRequest) => {
return ` (<${url}|#${number}>)`;
};

const buildGithubLink = (object) => `<https://github.com/${object}|${object}>`;
const buildGithubLink = ({ description, path }) => `<https://github.com/${path}|${description}>`;

module.exports = ({
t,
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": "2.4.2",
"version": "2.4.3",
"description": "Github action to print relevant stats about Pull Request reviewers",
"main": "dist/index.js",
"scripts": {
Expand Down
4 changes: 1 addition & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ const getRepositories = (currentRepo) => {
const getPrId = () => get(github, 'context.payload.pull_request.node_id');

const getParams = () => {
const { payload } = github.context || {};
const { repository } = payload || {};
const currentRepo = repository.full_name;
const currentRepo = process.env.GITHUB_REPOSITORY;
const githubToken = core.getInput('github-token');
const personalToken = core.getInput('token') || githubToken;

Expand Down
11 changes: 7 additions & 4 deletions src/interactors/__tests__/buildComment.test.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
const buildComment = require('../buildComment');
const { getRepoName } = require('../../utils');

const TABLE_MOCK = 'TABLE';
const ORG = 'org';
const REPO1 = 'org/repo1';
const REPO2 = 'org/repo2';

const link = (path) => `[${path}](https://github.com/${path})`;
const linkOrg = (org) => `[${org}](https://github.com/${org})`;

const linkRepo = (repo) => `[${getRepoName(repo)}](https://github.com/${repo})`;

describe('Interactors | .buildComment', () => {
const title = '## Pull reviewers stats';

describe('when period length is 1', () => {
const periodLength = 1;
const message = `Stats of the last day for ${link(ORG)}:`;
const message = `Stats of the last day for ${linkOrg(ORG)}:`;

it('builds the message in singular', () => {
const expected = `${title}\n${message}\n${TABLE_MOCK}`;
Expand All @@ -23,7 +26,7 @@ describe('Interactors | .buildComment', () => {

describe('when period length is more than 1', () => {
const periodLength = 365;
const message = `Stats of the last 365 days for ${link(ORG)}:`;
const message = `Stats of the last 365 days for ${linkOrg(ORG)}:`;

it('builds the message in singular', () => {
const expected = `${title}\n${message}\n${TABLE_MOCK}`;
Expand All @@ -35,7 +38,7 @@ describe('Interactors | .buildComment', () => {
describe('when sending repos', () => {
const repos = [REPO1, REPO2];
const periodLength = 1;
const message = `Stats of the last day for ${link(REPO1)} and ${link(REPO2)}:`;
const message = `Stats of the last day for ${linkRepo(REPO1)} and ${linkRepo(REPO2)}:`;

it('builds the message in singular', () => {
const expected = `${title}\n${message}\n${TABLE_MOCK}`;
Expand Down
2 changes: 1 addition & 1 deletion src/interactors/buildComment.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { t } = require('../i18n');
const { buildSources } = require('../utils');

const buildGithubLink = (object) => `[${object}](https://github.com/${object})`;
const buildGithubLink = ({ description, path }) => `[${description}](https://github.com/${path})`;

module.exports = ({
table,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const isExternalSponsor = require('../isExternalSponsor');

describe('Interactors | checkSponsorship | .isExternalSponsor', () => {
it('returns false when sending nothing', () => {
const expected = false;
const response = isExternalSponsor();
expect(response).toEqual(expected);
});

it('returns false when no user is sponsor', () => {
const input = new Set(['noSponsor1', 'noSponsor2']);
const expected = false;
const response = isExternalSponsor(input);
expect(response).toEqual(expected);
});

it('returns true when al least one user is sponsor', () => {
const input = new Set(['noSponsor1', 'zenfi']);
const expected = true;
const response = isExternalSponsor(input);
expect(response).toEqual(expected);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('Interactors | checkSponsorship | .isSponsoring', () => {
expect(response).toEqual(expected);
});

it('returns false when al least one key is true', () => {
it('returns true when al least one key is true', () => {
const input = {
sponsor1: false,
sponsor2: true,
Expand Down
3 changes: 2 additions & 1 deletion src/interactors/checkSponsorship/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { fetchSponsorships } = require('../../fetchers');
const getLogins = require('./getLogins');
const isSponsoring = require('./isSponsoring');
const isExternalSponsor = require('./isExternalSponsor');

module.exports = async ({
octokit,
Expand All @@ -9,5 +10,5 @@ module.exports = async ({
}) => {
const logins = getLogins({ org, repos });
const { user } = await fetchSponsorships({ octokit, logins });
return isSponsoring(user);
return isSponsoring(user) || isExternalSponsor(logins);
};
8 changes: 8 additions & 0 deletions src/interactors/checkSponsorship/isExternalSponsor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// A list of organizations which are sponsoring this project outside Github 💙
const externalSponsors = new Set([
'yotepresto-com',
'zenfi',
]);

module.exports = (logins) => [...(logins || [])]
.some((login) => externalSponsors.has(login));
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { t } = require('../../../../i18n');
const { getRepoName } = require('../../../../utils');
const buildSubtitle = require('../buildSubtitle');

const ORG = 'org';
Expand All @@ -11,7 +12,9 @@ const pullRequest = {
url: 'https://github.com/manuelmhtr/pulls/13',
};

const link = (path) => `<https://github.com/${path}|${path}>`;
const linkOrg = (org) => `<https://github.com/${org}|${org}>`;

const linkRepo = (repo) => `<https://github.com/${repo}|${getRepoName(repo)}>`;

describe('Interactors | postSlackMessage | .buildSubtitle', () => {
const baseParams = {
Expand All @@ -24,7 +27,7 @@ describe('Interactors | postSlackMessage | .buildSubtitle', () => {
it('returns a subtitle with no pull request data', () => {
const response = buildSubtitle({ ...baseParams, pullRequest });
const prLink = `(<${pullRequest.url}|#${pullRequest.number}>)`;
const sources = link(ORG);
const sources = linkOrg(ORG);
expect(response).toEqual([
{
type: 'section',
Expand All @@ -43,7 +46,7 @@ describe('Interactors | postSlackMessage | .buildSubtitle', () => {
describe('when not sending a pull request', () => {
it('returns a subtitle with no pull request data', () => {
const response = buildSubtitle({ ...baseParams, pullRequest: null });
const sources = link(ORG);
const sources = linkOrg(ORG);
expect(response).toEqual([
{
type: 'section',
Expand All @@ -63,7 +66,7 @@ describe('Interactors | postSlackMessage | .buildSubtitle', () => {
it('returns a subtitle with no pull request data', () => {
const repos = [REPO1, REPO2];
const response = buildSubtitle({ ...baseParams, org: null, repos });
const sources = `${link(REPO1)} and ${link(REPO2)}`;
const sources = `${linkRepo(REPO1)} and ${linkRepo(REPO2)}`;
expect(response).toEqual([
{
type: 'section',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const getPRText = (pullRequest) => {
return ` (<${url}|#${number}>)`;
};

const buildGithubLink = (object) => `<https://github.com/${object}|${object}>`;
const buildGithubLink = ({ description, path }) => `<https://github.com/${path}|${description}>`;

module.exports = ({
t,
Expand Down
Loading

0 comments on commit 3dd7ada

Please sign in to comment.