fix: automatically detect if using GitHub enterprise (#1356)

This commit is contained in:
Tom Hu
2024-04-05 11:12:44 -07:00
committed by GitHub
parent 7afa10ed9b
commit 55e8381a3e
4 changed files with 66 additions and 14 deletions

23
dist/index.js vendored
View File

@@ -32551,6 +32551,17 @@ const isTrue = (variable) => {
lowercase === 'y' ||
lowercase === 'yes');
};
const getGitService = () => {
const overrideGitService = core.getInput('git_service');
const serverUrl = process.env.GITHUB_SERVER_URL;
if (overrideGitService) {
return overrideGitService;
}
else if (serverUrl !== undefined && serverUrl !== 'https://github.com') {
return 'github_enterprise';
}
return 'github';
};
const getToken = () => buildExec_awaiter(void 0, void 0, void 0, function* () {
let token = core.getInput('token');
let url = core.getInput('url');
@@ -32571,7 +32582,7 @@ const getToken = () => buildExec_awaiter(void 0, void 0, void 0, function* () {
});
const buildCommitExec = () => buildExec_awaiter(void 0, void 0, void 0, function* () {
const commitParent = core.getInput('commit_parent');
const gitService = core.getInput('git_service');
const gitService = getGitService();
const overrideBranch = core.getInput('override_branch');
const overrideCommit = core.getInput('override_commit');
const overridePr = core.getInput('override_pr');
@@ -32596,7 +32607,7 @@ const buildCommitExec = () => buildExec_awaiter(void 0, void 0, void 0, function
if (commitParent) {
commitExecArgs.push('--parent-sha', `${commitParent}`);
}
commitExecArgs.push('--git-service', `${gitService ? gitService : 'github'}`);
commitExecArgs.push('--git-service', `${gitService}`);
if (overrideBranch) {
commitExecArgs.push('-B', `${overrideBranch}`);
}
@@ -32641,7 +32652,7 @@ const buildGeneralExec = () => {
return { args, verbose };
};
const buildReportExec = () => buildExec_awaiter(void 0, void 0, void 0, function* () {
const gitService = core.getInput('git_service');
const gitService = getGitService();
const overrideCommit = core.getInput('override_commit');
const overridePr = core.getInput('override_pr');
const slug = core.getInput('slug');
@@ -32662,7 +32673,7 @@ const buildReportExec = () => buildExec_awaiter(void 0, void 0, void 0, function
if (token) {
reportOptions.env.CODECOV_TOKEN = token;
}
reportExecArgs.push('--git-service', `${gitService ? gitService : 'github'}`);
reportExecArgs.push('--git-service', `${gitService}`);
if (overrideCommit) {
reportExecArgs.push('-C', `${overrideCommit}`);
}
@@ -32698,7 +32709,7 @@ const buildUploadExec = () => buildExec_awaiter(void 0, void 0, void 0, function
const file = core.getInput('file');
const files = core.getInput('files');
const flags = core.getInput('flags');
const gitService = core.getInput('git_service');
const gitService = getGitService();
const handleNoReportsFound = isTrue(core.getInput('handle_no_reports_found'));
const jobCode = core.getInput('job_code');
const name = core.getInput('name');
@@ -32771,7 +32782,7 @@ const buildUploadExec = () => buildExec_awaiter(void 0, void 0, void 0, function
uploadExecArgs.push('-F', `${f}`);
});
}
uploadExecArgs.push('--git-service', `${gitService ? gitService : 'github'}`);
uploadExecArgs.push('--git-service', `${gitService}`);
if (handleNoReportsFound) {
uploadExecArgs.push('--handle-no-reports-found');
}

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@@ -7,9 +7,19 @@ import {
buildUploadExec,
} from './buildExec';
const context = github.context;
let OLDOS = process.env.RUNNER_OS;
beforeEach(() => {
jest.resetModules();
OLDOS = process.env.RUNNER_OS;
});
afterAll(() => {
process.env.RUNNER_OS = OLDOS;
});
test('general args', async () => {
const envs = {
codecov_yml_path: 'dev/codecov.yml',
@@ -271,3 +281,23 @@ test('commit args using context', async () => {
expect(commitExecArgs).toEqual(expectedArgs);
expect(commitCommand).toEqual('create-commit');
});
test('commit args using github server url', async () => {
const expectedArgs :string[] = [
'--git-service',
'github_enterprise',
];
process.env.GITHUB_SERVER_URL = 'https://example.com';
const {commitExecArgs, commitCommand} = await buildCommitExec();
if (context.eventName == 'pull_request') {
expectedArgs.push('-C', `${context.payload.pull_request.head.sha}`);
}
if (context.eventName == 'pull_request_target') {
expectedArgs.push('-P', `${context.payload.number}`);
}
expect(commitExecArgs).toEqual(expectedArgs);
expect(commitCommand).toEqual('create-commit');
});

View File

@@ -18,6 +18,17 @@ const isTrue = (variable) => {
);
};
const getGitService = () => {
const overrideGitService = core.getInput('git_service');
const serverUrl = process.env.GITHUB_SERVER_URL;
if (overrideGitService) {
return overrideGitService;
} else if (serverUrl !== undefined && serverUrl !== 'https://github.com') {
return 'github_enterprise';
}
return 'github';
};
const getToken = async () => {
let token = core.getInput('token');
let url = core.getInput('url');
@@ -42,7 +53,7 @@ const getToken = async () => {
const buildCommitExec = async () => {
const commitParent = core.getInput('commit_parent');
const gitService = core.getInput('git_service');
const gitService = getGitService();
const overrideBranch = core.getInput('override_branch');
const overrideCommit = core.getInput('override_commit');
const overridePr = core.getInput('override_pr');
@@ -71,7 +82,7 @@ const buildCommitExec = async () => {
if (commitParent) {
commitExecArgs.push('--parent-sha', `${commitParent}`);
}
commitExecArgs.push('--git-service', `${gitService ? gitService : 'github'}`);
commitExecArgs.push('--git-service', `${gitService}`);
if (overrideBranch) {
commitExecArgs.push('-B', `${overrideBranch}`);
@@ -124,7 +135,7 @@ const buildGeneralExec = () => {
};
const buildReportExec = async () => {
const gitService = core.getInput('git_service');
const gitService = getGitService();
const overrideCommit = core.getInput('override_commit');
const overridePr = core.getInput('override_pr');
const slug = core.getInput('slug');
@@ -150,7 +161,7 @@ const buildReportExec = async () => {
if (token) {
reportOptions.env.CODECOV_TOKEN = token;
}
reportExecArgs.push('--git-service', `${gitService ? gitService : 'github'}`);
reportExecArgs.push('--git-service', `${gitService}`);
if (overrideCommit) {
reportExecArgs.push('-C', `${overrideCommit}`);
@@ -191,7 +202,7 @@ const buildUploadExec = async () => {
const file = core.getInput('file');
const files = core.getInput('files');
const flags = core.getInput('flags');
const gitService = core.getInput('git_service');
const gitService = getGitService();
const handleNoReportsFound = isTrue(core.getInput('handle_no_reports_found'));
const jobCode = core.getInput('job_code');
const name = core.getInput('name');
@@ -268,7 +279,7 @@ const buildUploadExec = async () => {
uploadExecArgs.push('-F', `${f}`);
});
}
uploadExecArgs.push('--git-service', `${gitService ? gitService : 'github'}`);
uploadExecArgs.push('--git-service', `${gitService}`);
if (handleNoReportsFound) {
uploadExecArgs.push('--handle-no-reports-found');
}