Skip to content

Commit

Permalink
fix: automatically detect if using GitHub enterprise (#1356)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasrockhu-codecov authored Apr 5, 2024
1 parent 7afa10e commit 55e8381
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 14 deletions.
23 changes: 17 additions & 6 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');
Expand All @@ -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}`);
}
Expand Down Expand Up @@ -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');
Expand All @@ -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}`);
}
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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');
}
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

32 changes: 31 additions & 1 deletion src/buildExec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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');
});
23 changes: 17 additions & 6 deletions src/buildExec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');
Expand Down Expand Up @@ -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}`);
Expand Down Expand Up @@ -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');
Expand All @@ -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}`);
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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');
}
Expand Down

0 comments on commit 55e8381

Please # to comment.