diff --git a/CHANGELOG.md b/CHANGELOG.md index ad79b9a..7aa2db1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/dist/index.js b/dist/index.js index 40f7fa9..44db1d2 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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: @@ -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( @@ -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; }); @@ -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, }; @@ -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"}; /***/ }), @@ -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; } @@ -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); }; @@ -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')); }; diff --git a/package.json b/package.json index 4534d71..2753804 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/fetchers/__tests__/fetchSponsorships.test.js b/src/fetchers/__tests__/fetchSponsorships.test.js index 8ff7d18..6a09b91 100644 --- a/src/fetchers/__tests__/fetchSponsorships.test.js +++ b/src/fetchers/__tests__/fetchSponsorships.test.js @@ -6,7 +6,8 @@ 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(() => { @@ -14,10 +15,19 @@ describe('Fetchers | .fetchSponsorships', () => { }); 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: {} }); + }); }); diff --git a/src/fetchers/fetchSponsorships.js b/src/fetchers/fetchSponsorships.js index bd8303a..24d796c 100644 --- a/src/fetchers/fetchSponsorships.js +++ b/src/fetchers/fetchSponsorships.js @@ -1,4 +1,7 @@ +const core = require('@actions/core'); + const SPONSORED_ACCOUNT = 'manuelmhtr'; +const DEFAULT_RESPONSE = { user: {} }; const buildQuery = (logins) => { const fields = logins.map( @@ -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; }); diff --git a/src/i18n/locales/en-US/index.js b/src/i18n/locales/en-US/index.js index 24e7ae3..117a5f9 100644 --- a/src/i18n/locales/en-US/index.js +++ b/src/i18n/locales/en-US/index.js @@ -1,5 +1,7 @@ +const integrations = require('./integrations.json'); const table = require('./table.json'); module.exports = { + integrations, table, }; diff --git a/src/i18n/locales/en-US/integrations.json b/src/i18n/locales/en-US/integrations.json new file mode 100644 index 0000000..562f84f --- /dev/null +++ b/src/i18n/locales/en-US/integrations.json @@ -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}}" + } + } +} diff --git a/src/interactors/postSlackMessage/index.js b/src/interactors/postSlackMessage/index.js index 339104b..5a88965 100644 --- a/src/interactors/postSlackMessage/index.js +++ b/src/interactors/postSlackMessage/index.js @@ -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; } @@ -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); }; @@ -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')); };