Skip to content

Commit b069f4c

Browse files
authored
v2.15.0: Support for alternative Github env (Enterprise)
* ghes-friendly mods * export functions to get github api and server urls support GITHUB_SERVER_URL with tests * update package version, changelog * lint fixes * build output
1 parent 5d06691 commit b069f4c

11 files changed

Lines changed: 89 additions & 14 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4+
## [2.15.0] - 2024-04-27
5+
### Added
6+
- Support for hosted GitHub variants with non-standard domains (e.g., GitHub Enterprise)
7+
48
## [2.14.0] - 2024-03-03
59
### Added
610
- Announcing the web version development.

dist/index.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41197,10 +41197,13 @@ const getSlackLimits = () => ({
4119741197
blocks: 50,
4119841198
});
4119941199
const getTeamsBytesLimit = () => 27_000;
41200-
41200+
const getGithubApiUrl = () => process.env.GITHUB_API_URL || 'https://api.github.com';
41201+
const getGithubServerUrl = () => process.env.GITHUB_SERVER_URL || 'https://github.com';
4120141202
module.exports = {
4120241203
getSlackLimits,
4120341204
getTeamsBytesLimit,
41205+
getGithubApiUrl,
41206+
getGithubServerUrl,
4120441207
};
4120541208

4120641209

@@ -41244,6 +41247,7 @@ const github = __nccwpck_require__(5438);
4124441247
const { subtractDaysToDate } = __nccwpck_require__(9988);
4124541248
const { Telemetry } = __nccwpck_require__(4786);
4124641249
const { fetchPullRequestById } = __nccwpck_require__(8001);
41250+
const { getGithubApiUrl } = __nccwpck_require__(1855);
4124741251
const {
4124841252
getPulls,
4124941253
buildTable,
@@ -41286,7 +41290,7 @@ const run = async (params) => {
4128641290
const pulls = await getPulls({
4128741291
org,
4128841292
repos,
41289-
octokit: github.getOctokit(personalToken),
41293+
octokit: github.getOctokit(personalToken, { baseUrl: getGithubApiUrl() }),
4129041294
startDate: subtractDaysToDate(new Date(), periodLength),
4129141295
});
4129241296
core.info(`Found ${pulls.length} pull requests to analyze`);
@@ -41339,7 +41343,7 @@ module.exports = async (params) => {
4133941343
core.debug(`Params: ${JSON.stringify(params, null, 2)}`);
4134041344

4134141345
const { githubToken, org, repos } = params;
41342-
const octokit = github.getOctokit(githubToken);
41346+
const octokit = github.getOctokit(githubToken, { baseUrl: getGithubApiUrl() });
4134341347
const isSponsor = await checkSponsorship({ octokit, org, repos });
4134441348
const telemetry = new Telemetry({ core, isSponsor, telemetry: params.telemetry });
4134541349
if (isSponsor) core.info('Thanks for sponsoring this project! 💙');
@@ -41705,8 +41709,9 @@ module.exports = (pullRequest) => {
4170541709

4170641710
const { t } = __nccwpck_require__(6830);
4170741711
const { buildSources } = __nccwpck_require__(9988);
41712+
const { getGithubServerUrl } = __nccwpck_require__(1855);
4170841713

41709-
const buildGithubLink = ({ description, path }) => `[${description}](https://github.com/${path})`;
41714+
const buildGithubLink = ({ description, path }) => `[${description}](${getGithubServerUrl()}/${path})`;
4171041715

4171141716
module.exports = ({
4171241717
table,
@@ -42321,14 +42326,15 @@ module.exports = ({
4232142326
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
4232242327

4232342328
const { buildSources } = __nccwpck_require__(9988);
42329+
const { getGithubServerUrl } = __nccwpck_require__(1855);
4232442330

4232542331
const getPRText = (pullRequest) => {
4232642332
const { url, number } = pullRequest || {};
4232742333
if (!url || !number) return '';
4232842334
return ` (<${url}|#${number}>)`;
4232942335
};
4233042336

42331-
const buildGithubLink = ({ description, path }) => `<https://github.com/${path}|${description}>`;
42337+
const buildGithubLink = ({ description, path }) => `<${getGithubServerUrl()}/${path}|${description}>`;
4233242338

4233342339
module.exports = ({
4233442340
t,
@@ -42656,14 +42662,15 @@ module.exports = ({
4265642662
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
4265742663

4265842664
const { buildSources } = __nccwpck_require__(9988);
42665+
const { getGithubServerUrl } = __nccwpck_require__(1855);
4265942666

4266042667
const getPRText = (pullRequest) => {
4266142668
const { url, number } = pullRequest || {};
4266242669
if (!url || !number) return '';
4266342670
return ` ([#${number}](${url}))`;
4266442671
};
4266542672

42666-
const buildGithubLink = ({ description, path }) => `[${description}](https://github.com/${path})`;
42673+
const buildGithubLink = ({ description, path }) => `[${description}](${getGithubServerUrl()}/${path})`;
4266742674

4266842675
module.exports = ({
4266942676
t,
@@ -48055,7 +48062,7 @@ module.exports = JSON.parse('{"name":"mixpanel","description":"A simple server-s
4805548062
/***/ ((module) => {
4805648063

4805748064
"use strict";
48058-
module.exports = JSON.parse('{"name":"pull-request-stats","version":"2.14.0","description":"Github action to print relevant stats about Pull Request reviewers","main":"dist/index.js","type":"commonjs","scripts":{"build":"eslint src && ncc build src/index.js -o dist -a","test":"jest","lint":"eslint ./"},"keywords":[],"author":"Manuel de la Torre","license":"MIT","jest":{"testEnvironment":"node","testMatch":["**/?(*.)+(spec|test).[jt]s?(x)"]},"dependencies":{"@actions/core":"^1.10.1","@actions/github":"^6.0.0","axios":"^1.6.7","humanize-duration":"^3.31.0","i18n-js":"^3.9.2","jsurl":"^0.1.5","lodash.get":"^4.4.2","markdown-table":"^2.0.0","mixpanel":"^0.18.0"},"devDependencies":{"@vercel/ncc":"^0.38.1","eslint":"^8.56.0","eslint-config-airbnb-base":"^15.0.0","eslint-plugin-import":"^2.29.1","eslint-plugin-jest":"^27.6.3","jest":"^29.7.0"},"funding":"https://github.com/sponsors/manuelmhtr","packageManager":"yarn@4.1.0"}');
48065+
module.exports = JSON.parse('{"name":"pull-request-stats","version":"2.15.0","description":"Github action to print relevant stats about Pull Request reviewers","main":"dist/index.js","type":"commonjs","scripts":{"build":"eslint src && ncc build src/index.js -o dist -a","test":"jest","lint":"eslint ./"},"keywords":[],"author":"Manuel de la Torre","license":"MIT","jest":{"testEnvironment":"node","testMatch":["**/?(*.)+(spec|test).[jt]s?(x)"]},"dependencies":{"@actions/core":"^1.10.1","@actions/github":"^6.0.0","axios":"^1.6.7","humanize-duration":"^3.31.0","i18n-js":"^3.9.2","jsurl":"^0.1.5","lodash.get":"^4.4.2","markdown-table":"^2.0.0","mixpanel":"^0.18.0"},"devDependencies":{"@vercel/ncc":"^0.38.1","eslint":"^8.56.0","eslint-config-airbnb-base":"^15.0.0","eslint-plugin-import":"^2.29.1","eslint-plugin-jest":"^27.6.3","jest":"^29.7.0"},"funding":"https://github.com/sponsors/manuelmhtr","packageManager":"yarn@4.1.0"}');
4805948066

4806048067
/***/ }),
4806148068

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pull-request-stats",
3-
"version": "2.14.0",
3+
"version": "2.15.0",
44
"description": "Github action to print relevant stats about Pull Request reviewers",
55
"main": "dist/index.js",
66
"type": "commonjs",

src/config/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ const getSlackLimits = () => ({
33
blocks: 50,
44
});
55
const getTeamsBytesLimit = () => 27_000;
6-
6+
const getGithubApiUrl = () => process.env.GITHUB_API_URL || 'https://api.github.com';
7+
const getGithubServerUrl = () => process.env.GITHUB_SERVER_URL || 'https://github.com';
78
module.exports = {
89
getSlackLimits,
910
getTeamsBytesLimit,
11+
getGithubApiUrl,
12+
getGithubServerUrl,
1013
};

src/execute.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const github = require('@actions/github');
33
const { subtractDaysToDate } = require('./utils');
44
const { Telemetry } = require('./services');
55
const { fetchPullRequestById } = require('./fetchers');
6+
const { getGithubApiUrl } = require('./config');
67
const {
78
getPulls,
89
buildTable,
@@ -45,7 +46,7 @@ const run = async (params) => {
4546
const pulls = await getPulls({
4647
org,
4748
repos,
48-
octokit: github.getOctokit(personalToken),
49+
octokit: github.getOctokit(personalToken, { baseUrl: getGithubApiUrl() }),
4950
startDate: subtractDaysToDate(new Date(), periodLength),
5051
});
5152
core.info(`Found ${pulls.length} pull requests to analyze`);
@@ -98,7 +99,7 @@ module.exports = async (params) => {
9899
core.debug(`Params: ${JSON.stringify(params, null, 2)}`);
99100

100101
const { githubToken, org, repos } = params;
101-
const octokit = github.getOctokit(githubToken);
102+
const octokit = github.getOctokit(githubToken, { baseUrl: getGithubApiUrl() });
102103
const isSponsor = await checkSponsorship({ octokit, org, repos });
103104
const telemetry = new Telemetry({ core, isSponsor, telemetry: params.telemetry });
104105
if (isSponsor) core.info('Thanks for sponsoring this project! 💙');

src/interactors/__tests__/buildComment.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@ const linkRepo = (repo) => `[${getRepoName(repo)}](https://github.com/${repo})`;
1515
describe('Interactors | .buildComment', () => {
1616
const title = '## Pull reviewers stats';
1717

18+
describe('when GITHUB_SERVER_URL is present', () => {
19+
const periodLength = 1;
20+
const message = `Stats of the last day for [${ORG}](https://github.example.io/${ORG}):`;
21+
22+
it('builds an environment-specific comment using this URL', () => {
23+
process.env.GITHUB_SERVER_URL = 'https://github.example.io';
24+
const expected = `${title}\n${message}\n${TABLE_MOCK}\n${FOOTER}`;
25+
const response = buildComment({ periodLength, table: TABLE_MOCK, org: ORG });
26+
delete process.env.GITHUB_SERVER_URL;
27+
expect(response).toEqual(expected);
28+
});
29+
});
30+
1831
describe('when period length is 1', () => {
1932
const periodLength = 1;
2033
const message = `Stats of the last day for ${linkOrg(ORG)}:`;

src/interactors/buildComment.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
const { t } = require('../i18n');
22
const { buildSources } = require('../utils');
3+
const { getGithubServerUrl } = require('../config');
34

4-
const buildGithubLink = ({ description, path }) => `[${description}](https://github.com/${path})`;
5+
const buildGithubLink = ({ description, path }) => `[${description}](${getGithubServerUrl()}/${path})`;
56

67
module.exports = ({
78
table,

src/interactors/postSlackMessage/buildMessage/__tests__/buildSubtitle.test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,33 @@ describe('Interactors | postSlackMessage | .buildSubtitle', () => {
2323
org: ORG,
2424
};
2525

26+
describe('when GITHUB_SERVER_URL is present', () => {
27+
it('returns a subtitle with custom github server URL', () => {
28+
process.env.GITHUB_SERVER_URL = 'https://github.example.io';
29+
const pullRequestWithCustomDomain = {
30+
number: 13,
31+
url: 'https://github.example.io/manuelmhtr/pulls/13',
32+
};
33+
const linkOrgWithCustomDomain = (org) => `<https://github.example.io/${org}|${org}>`;
34+
const response = buildSubtitle({ ...baseParams, pullRequest: pullRequestWithCustomDomain });
35+
const prLinkWithCustomDomain = `(<${pullRequestWithCustomDomain.url}|#${pullRequestWithCustomDomain.number}>)`;
36+
const sources = linkOrgWithCustomDomain(ORG);
37+
delete process.env.GITHUB_SERVER_URL;
38+
expect(response).toEqual([
39+
{
40+
type: 'section',
41+
text: {
42+
type: 'mrkdwn',
43+
text: `${t('table.subtitle', { sources, count: periodLength })} ${prLinkWithCustomDomain}`,
44+
},
45+
},
46+
{
47+
type: 'divider',
48+
},
49+
]);
50+
});
51+
});
52+
2653
describe('when sending a pull request', () => {
2754
it('returns a subtitle with no pull request data', () => {
2855
const response = buildSubtitle({ ...baseParams, pullRequest });

src/interactors/postSlackMessage/buildMessage/buildSubtitle.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
const { buildSources } = require('../../../utils');
2+
const { getGithubServerUrl } = require('../../../config');
23

34
const getPRText = (pullRequest) => {
45
const { url, number } = pullRequest || {};
56
if (!url || !number) return '';
67
return ` (<${url}|#${number}>)`;
78
};
89

9-
const buildGithubLink = ({ description, path }) => `<https://github.com/${path}|${description}>`;
10+
const buildGithubLink = ({ description, path }) => `<${getGithubServerUrl()}/${path}|${description}>`;
1011

1112
module.exports = ({
1213
t,

src/interactors/postTeamsMessage/buildMessage/__tests__/buildSubtitle.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,23 @@ describe('Interactors | postTeamsMessage | .buildSubtitle', () => {
3636
org: ORG,
3737
};
3838

39+
describe('when GITHUB_SERVER_URL is present', () => {
40+
it('returns a subtitle with custom github server URL', () => {
41+
process.env.GITHUB_SERVER_URL = 'https://github.example.io';
42+
const pullRequestWithCustomDomain = {
43+
number: 13,
44+
url: 'https://github.example.io/manuelmhtr/pulls/13',
45+
};
46+
const linkOrgWithCustomDomain = (org) => `[${org}](https://github.example.io/${org})`;
47+
const response = buildSubtitle({ ...baseParams, pullRequest: pullRequestWithCustomDomain });
48+
const prLinkWithCustomDomain = `([#${pullRequestWithCustomDomain.number}](${pullRequestWithCustomDomain.url}))`;
49+
const sources = linkOrgWithCustomDomain(ORG);
50+
const text = `${t('table.subtitle', { sources, count: periodLength })} ${prLinkWithCustomDomain}`;
51+
delete process.env.GITHUB_SERVER_URL;
52+
expect(response).toEqual(wrapText(text));
53+
});
54+
});
55+
3956
describe('when sending a pull request', () => {
4057
it('returns a subtitle with no pull request data', () => {
4158
const response = buildSubtitle({ ...baseParams, pullRequest });

0 commit comments

Comments
 (0)