Skip to content

Commit 55e8381

Browse files
fix: automatically detect if using GitHub enterprise (#1356)
1 parent 7afa10e commit 55e8381

File tree

4 files changed

+66
-14
lines changed

4 files changed

+66
-14
lines changed

dist/index.js

+17-6
Original file line numberDiff line numberDiff line change
@@ -32551,6 +32551,17 @@ const isTrue = (variable) => {
3255132551
lowercase === 'y' ||
3255232552
lowercase === 'yes');
3255332553
};
32554+
const getGitService = () => {
32555+
const overrideGitService = core.getInput('git_service');
32556+
const serverUrl = process.env.GITHUB_SERVER_URL;
32557+
if (overrideGitService) {
32558+
return overrideGitService;
32559+
}
32560+
else if (serverUrl !== undefined && serverUrl !== 'https://github.com') {
32561+
return 'github_enterprise';
32562+
}
32563+
return 'github';
32564+
};
3255432565
const getToken = () => buildExec_awaiter(void 0, void 0, void 0, function* () {
3255532566
let token = core.getInput('token');
3255632567
let url = core.getInput('url');
@@ -32571,7 +32582,7 @@ const getToken = () => buildExec_awaiter(void 0, void 0, void 0, function* () {
3257132582
});
3257232583
const buildCommitExec = () => buildExec_awaiter(void 0, void 0, void 0, function* () {
3257332584
const commitParent = core.getInput('commit_parent');
32574-
const gitService = core.getInput('git_service');
32585+
const gitService = getGitService();
3257532586
const overrideBranch = core.getInput('override_branch');
3257632587
const overrideCommit = core.getInput('override_commit');
3257732588
const overridePr = core.getInput('override_pr');
@@ -32596,7 +32607,7 @@ const buildCommitExec = () => buildExec_awaiter(void 0, void 0, void 0, function
3259632607
if (commitParent) {
3259732608
commitExecArgs.push('--parent-sha', `${commitParent}`);
3259832609
}
32599-
commitExecArgs.push('--git-service', `${gitService ? gitService : 'github'}`);
32610+
commitExecArgs.push('--git-service', `${gitService}`);
3260032611
if (overrideBranch) {
3260132612
commitExecArgs.push('-B', `${overrideBranch}`);
3260232613
}
@@ -32641,7 +32652,7 @@ const buildGeneralExec = () => {
3264132652
return { args, verbose };
3264232653
};
3264332654
const buildReportExec = () => buildExec_awaiter(void 0, void 0, void 0, function* () {
32644-
const gitService = core.getInput('git_service');
32655+
const gitService = getGitService();
3264532656
const overrideCommit = core.getInput('override_commit');
3264632657
const overridePr = core.getInput('override_pr');
3264732658
const slug = core.getInput('slug');
@@ -32662,7 +32673,7 @@ const buildReportExec = () => buildExec_awaiter(void 0, void 0, void 0, function
3266232673
if (token) {
3266332674
reportOptions.env.CODECOV_TOKEN = token;
3266432675
}
32665-
reportExecArgs.push('--git-service', `${gitService ? gitService : 'github'}`);
32676+
reportExecArgs.push('--git-service', `${gitService}`);
3266632677
if (overrideCommit) {
3266732678
reportExecArgs.push('-C', `${overrideCommit}`);
3266832679
}
@@ -32698,7 +32709,7 @@ const buildUploadExec = () => buildExec_awaiter(void 0, void 0, void 0, function
3269832709
const file = core.getInput('file');
3269932710
const files = core.getInput('files');
3270032711
const flags = core.getInput('flags');
32701-
const gitService = core.getInput('git_service');
32712+
const gitService = getGitService();
3270232713
const handleNoReportsFound = isTrue(core.getInput('handle_no_reports_found'));
3270332714
const jobCode = core.getInput('job_code');
3270432715
const name = core.getInput('name');
@@ -32771,7 +32782,7 @@ const buildUploadExec = () => buildExec_awaiter(void 0, void 0, void 0, function
3277132782
uploadExecArgs.push('-F', `${f}`);
3277232783
});
3277332784
}
32774-
uploadExecArgs.push('--git-service', `${gitService ? gitService : 'github'}`);
32785+
uploadExecArgs.push('--git-service', `${gitService}`);
3277532786
if (handleNoReportsFound) {
3277632787
uploadExecArgs.push('--handle-no-reports-found');
3277732788
}

dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/buildExec.test.ts

+31-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,19 @@ import {
77
buildUploadExec,
88
} from './buildExec';
99

10-
1110
const context = github.context;
1211

12+
let OLDOS = process.env.RUNNER_OS;
13+
14+
beforeEach(() => {
15+
jest.resetModules();
16+
OLDOS = process.env.RUNNER_OS;
17+
});
18+
19+
afterAll(() => {
20+
process.env.RUNNER_OS = OLDOS;
21+
});
22+
1323
test('general args', async () => {
1424
const envs = {
1525
codecov_yml_path: 'dev/codecov.yml',
@@ -271,3 +281,23 @@ test('commit args using context', async () => {
271281
expect(commitExecArgs).toEqual(expectedArgs);
272282
expect(commitCommand).toEqual('create-commit');
273283
});
284+
285+
test('commit args using github server url', async () => {
286+
const expectedArgs :string[] = [
287+
'--git-service',
288+
'github_enterprise',
289+
];
290+
291+
process.env.GITHUB_SERVER_URL = 'https://example.com';
292+
293+
const {commitExecArgs, commitCommand} = await buildCommitExec();
294+
if (context.eventName == 'pull_request') {
295+
expectedArgs.push('-C', `${context.payload.pull_request.head.sha}`);
296+
}
297+
if (context.eventName == 'pull_request_target') {
298+
expectedArgs.push('-P', `${context.payload.number}`);
299+
}
300+
301+
expect(commitExecArgs).toEqual(expectedArgs);
302+
expect(commitCommand).toEqual('create-commit');
303+
});

src/buildExec.ts

+17-6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ const isTrue = (variable) => {
1818
);
1919
};
2020

21+
const getGitService = () => {
22+
const overrideGitService = core.getInput('git_service');
23+
const serverUrl = process.env.GITHUB_SERVER_URL;
24+
if (overrideGitService) {
25+
return overrideGitService;
26+
} else if (serverUrl !== undefined && serverUrl !== 'https://github.com') {
27+
return 'github_enterprise';
28+
}
29+
return 'github';
30+
};
31+
2132
const getToken = async () => {
2233
let token = core.getInput('token');
2334
let url = core.getInput('url');
@@ -42,7 +53,7 @@ const getToken = async () => {
4253

4354
const buildCommitExec = async () => {
4455
const commitParent = core.getInput('commit_parent');
45-
const gitService = core.getInput('git_service');
56+
const gitService = getGitService();
4657
const overrideBranch = core.getInput('override_branch');
4758
const overrideCommit = core.getInput('override_commit');
4859
const overridePr = core.getInput('override_pr');
@@ -71,7 +82,7 @@ const buildCommitExec = async () => {
7182
if (commitParent) {
7283
commitExecArgs.push('--parent-sha', `${commitParent}`);
7384
}
74-
commitExecArgs.push('--git-service', `${gitService ? gitService : 'github'}`);
85+
commitExecArgs.push('--git-service', `${gitService}`);
7586

7687
if (overrideBranch) {
7788
commitExecArgs.push('-B', `${overrideBranch}`);
@@ -124,7 +135,7 @@ const buildGeneralExec = () => {
124135
};
125136

126137
const buildReportExec = async () => {
127-
const gitService = core.getInput('git_service');
138+
const gitService = getGitService();
128139
const overrideCommit = core.getInput('override_commit');
129140
const overridePr = core.getInput('override_pr');
130141
const slug = core.getInput('slug');
@@ -150,7 +161,7 @@ const buildReportExec = async () => {
150161
if (token) {
151162
reportOptions.env.CODECOV_TOKEN = token;
152163
}
153-
reportExecArgs.push('--git-service', `${gitService ? gitService : 'github'}`);
164+
reportExecArgs.push('--git-service', `${gitService}`);
154165

155166
if (overrideCommit) {
156167
reportExecArgs.push('-C', `${overrideCommit}`);
@@ -191,7 +202,7 @@ const buildUploadExec = async () => {
191202
const file = core.getInput('file');
192203
const files = core.getInput('files');
193204
const flags = core.getInput('flags');
194-
const gitService = core.getInput('git_service');
205+
const gitService = getGitService();
195206
const handleNoReportsFound = isTrue(core.getInput('handle_no_reports_found'));
196207
const jobCode = core.getInput('job_code');
197208
const name = core.getInput('name');
@@ -268,7 +279,7 @@ const buildUploadExec = async () => {
268279
uploadExecArgs.push('-F', `${f}`);
269280
});
270281
}
271-
uploadExecArgs.push('--git-service', `${gitService ? gitService : 'github'}`);
282+
uploadExecArgs.push('--git-service', `${gitService}`);
272283
if (handleNoReportsFound) {
273284
uploadExecArgs.push('--handle-no-reports-found');
274285
}

0 commit comments

Comments
 (0)