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

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');
}