Skip to content

Commit

Permalink
v2.4.6: Prevent sponsorship query error on Github Enterprise.
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelmhtr committed Sep 2, 2022
1 parent ac5c6eb commit 362ff2f
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 17 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.

## [2.4.6] - 2022-09-01
### Fixed
- [#48](https://github.com/flowwer-dev/pull-request-stats/issues/48) Prevent sponsorship query error on Github Enterprise environments.

## [2.4.5] - 2022-08-27
### Fixed
- [#38](https://github.com/flowwer-dev/pull-request-stats/issues/38#issuecomment-1171087421) Split Slack message to prevent hitting characters limit.
Expand Down
31 changes: 23 additions & 8 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,13 @@ module.exports = (reviews) => {
};


/***/ }),

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

module.exports = {"slack":{"logs":{"notConfigured":"Slack integration is disabled. No webhook or channel configured.","posting":"Post a Slack message with params: {{params}}","success":"Successfully posted to slack"},"errors":{"notSponsor":"Slack integration is a premium feature, available to sponsors.\n(If you are already an sponsor, please make sure it configured as public).","requestFailed":"Error posting Slack message: {{error}}"}}};

/***/ }),

/***/ 65:
Expand Down Expand Up @@ -1077,9 +1084,12 @@ exports.issueCommand = issueCommand;
/***/ }),

/***/ 104:
/***/ (function(module) {
/***/ (function(module, __unusedexports, __webpack_require__) {

const core = __webpack_require__(470);

const SPONSORED_ACCOUNT = 'manuelmhtr';
const DEFAULT_RESPONSE = { user: {} };

const buildQuery = (logins) => {
const fields = logins.map(
Expand All @@ -1102,7 +1112,8 @@ module.exports = ({
.graphql(buildQuery(logins))
.catch((error) => {
const msg = `Error fetching sponsorships with logins: "${JSON.stringify(logins)}"`;
throw new Error(`${msg}. Error: ${error}`);
core.debug(new Error(`${msg}. Error: ${error}`));
return DEFAULT_RESPONSE;
});


Expand Down Expand Up @@ -10237,9 +10248,11 @@ exports.FetchError = FetchError;
/***/ 455:
/***/ (function(module, __unusedexports, __webpack_require__) {

const integrations = __webpack_require__(61);
const table = __webpack_require__(680);

module.exports = {
integrations,
table,
};

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

module.exports = {"name":"pull-request-stats","version":"2.4.5","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"},"funding":"https://github.com/sponsors/manuelmhtr"};
module.exports = {"name":"pull-request-stats","version":"2.4.6","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"},"funding":"https://github.com/sponsors/manuelmhtr"};

/***/ }),

Expand Down Expand Up @@ -18319,12 +18332,12 @@ module.exports = async ({
const { webhook, channel } = slack || {};

if (!webhook || !channel) {
core.debug('Slack integration is disabled. No webhook or channel configured.');
core.debug(t('integrations.slack.logs.notConfigured'));
return;
}

if (!isSponsor) {
core.error('Slack integration is a premium feature, available to sponsors.');
core.error(t('integrations.slack.errors.notSponsor'));
return;
}

Expand All @@ -18336,7 +18349,9 @@ module.exports = async ({
iconUrl: t('table.icon'),
username: t('table.title'),
};
core.debug(`Post a Slack message with params: ${JSON.stringify(params, null, 2)}`);
core.debug(t('integrations.slack.logs.posting', {
params: JSON.stringify(params, null, 2),
}));
return postToSlack(params);
};

Expand All @@ -18354,12 +18369,12 @@ module.exports = async ({
await chunks.reduce(async (promise, message) => {
await promise;
return send(message).catch((error) => {
core.error(`Error posting Slack message: ${error}`);
core.error(t('integrations.slack.errors.requestFailed', { error }));
throw error;
});
}, Promise.resolve());

core.debug('Successfully posted to slack');
core.debug(t('integrations.slack.logs.success'));
};


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.5",
"version": "2.4.6",
"description": "Github action to print relevant stats about Pull Request reviewers",
"main": "dist/index.js",
"scripts": {
Expand Down
14 changes: 12 additions & 2 deletions src/fetchers/__tests__/fetchSponsorships.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,28 @@ const logins = [
];

describe('Fetchers | .fetchSponsorships', () => {
const graphql = jest.fn(() => Promise.resolve());
const data = { user: { login1: true, login2: false } };
const graphql = jest.fn(() => Promise.resolve(data));
const octokit = { graphql };

beforeEach(() => {
graphql.mockClear();
});

it('builds the query and fetches data from Github API', async () => {
await fetchSponsorships({ octokit, logins });
const response = await fetchSponsorships({ octokit, logins });
expect(response).toEqual(data);
expect(graphql).toHaveBeenCalledTimes(1);
expect(graphql).toHaveBeenCalledWith(
expect.stringContaining(`isSponsoredBy(accountLogin: "${logins[0]}")`),
);
});

it('returns an empty response when request fails', async () => {
const error = new Error("Field 'isSponsoredBy' doesn't exist on type 'User'");
graphql.mockImplementation(() => Promise.reject(error));
const response = await fetchSponsorships({ octokit, logins });
expect(graphql).toHaveBeenCalledTimes(1);
expect(response).toEqual({ user: {} });
});
});
6 changes: 5 additions & 1 deletion src/fetchers/fetchSponsorships.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const core = require('@actions/core');

const SPONSORED_ACCOUNT = 'manuelmhtr';
const DEFAULT_RESPONSE = { user: {} };

const buildQuery = (logins) => {
const fields = logins.map(
Expand All @@ -21,5 +24,6 @@ module.exports = ({
.graphql(buildQuery(logins))
.catch((error) => {
const msg = `Error fetching sponsorships with logins: "${JSON.stringify(logins)}"`;
throw new Error(`${msg}. Error: ${error}`);
core.debug(new Error(`${msg}. Error: ${error}`));
return DEFAULT_RESPONSE;
});
2 changes: 2 additions & 0 deletions src/i18n/locales/en-US/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const integrations = require('./integrations.json');
const table = require('./table.json');

module.exports = {
integrations,
table,
};
13 changes: 13 additions & 0 deletions src/i18n/locales/en-US/integrations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"slack": {
"logs": {
"notConfigured": "Slack integration is disabled. No webhook or channel configured.",
"posting": "Post a Slack message with params: {{params}}",
"success": "Successfully posted to slack"
},
"errors": {
"notSponsor": "Slack integration is a premium feature, available to sponsors.\n(If you are already an sponsor, please make sure it configured as public).",
"requestFailed": "Error posting Slack message: {{error}}"
}
}
}
12 changes: 7 additions & 5 deletions src/interactors/postSlackMessage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ module.exports = async ({
const { webhook, channel } = slack || {};

if (!webhook || !channel) {
core.debug('Slack integration is disabled. No webhook or channel configured.');
core.debug(t('integrations.slack.logs.notConfigured'));
return;
}

if (!isSponsor) {
core.error('Slack integration is a premium feature, available to sponsors.');
core.error(t('integrations.slack.errors.notSponsor'));
return;
}

Expand All @@ -35,7 +35,9 @@ module.exports = async ({
iconUrl: t('table.icon'),
username: t('table.title'),
};
core.debug(`Post a Slack message with params: ${JSON.stringify(params, null, 2)}`);
core.debug(t('integrations.slack.logs.posting', {
params: JSON.stringify(params, null, 2),
}));
return postToSlack(params);
};

Expand All @@ -53,10 +55,10 @@ module.exports = async ({
await chunks.reduce(async (promise, message) => {
await promise;
return send(message).catch((error) => {
core.error(`Error posting Slack message: ${error}`);
core.error(t('integrations.slack.errors.requestFailed', { error }));
throw error;
});
}, Promise.resolve());

core.debug('Successfully posted to slack');
core.debug(t('integrations.slack.logs.success'));
};

0 comments on commit 362ff2f

Please sign in to comment.