Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: pass tokenless value as branch override #1511

Merged
merged 11 commits into from
Aug 29, 2024
10 changes: 7 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32355,7 +32355,7 @@ const getToken = () => buildExec_awaiter(void 0, void 0, void 0, function* () {
if (!token && isPullRequestFromFork()) {
core.info('==> Fork detected, tokenless uploading used');
process.env['TOKENLESS'] = context.payload.pull_request.head.label;
return Promise.resolve('');
return null;
}
let url = core.getInput('url');
const useOIDC = isTrue(core.getInput('use_oidc'));
Expand All @@ -32365,7 +32365,7 @@ const getToken = () => buildExec_awaiter(void 0, void 0, void 0, function* () {
}
try {
token = yield core.getIDToken(url);
return token;
return Promise.resolve(token);
}
catch (err) {
setFailure(`Codecov: Failed to get OIDC token with url: ${url}. ${err.message}`, true);
Expand All @@ -32374,13 +32374,17 @@ const getToken = () => buildExec_awaiter(void 0, void 0, void 0, function* () {
return token;
});
const buildCommitExec = () => buildExec_awaiter(void 0, void 0, void 0, function* () {
var _a;
const commitParent = core.getInput('commit_parent');
const gitService = getGitService();
const overrideBranch = core.getInput('override_branch');
let overrideBranch = core.getInput('override_branch');
const overrideCommit = core.getInput('override_commit');
const overridePr = core.getInput('override_pr');
const slug = core.getInput('slug');
const token = yield getToken();
if (token == null) {
overrideBranch = (_a = context.payload.pull_request) === null || _a === void 0 ? void 0 : _a.head.label;
}
const failCi = isTrue(core.getInput('fail_ci_if_error'));
const workingDir = core.getInput('working-directory');
const commitCommand = 'create-commit';
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/buildExec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ test('report args using context', async () => {
for (const env of Object.keys(envs)) {
process.env['INPUT_' + env.toUpperCase()] = envs[env];
}
const expectedArgs : string[] = [
const expectedArgs: string[] = [
'--git-service',
'github',
];
Expand Down Expand Up @@ -271,7 +271,7 @@ test('commit args', async () => {
});

test('commit args using context', async () => {
const expectedArgs :string[] = [
const expectedArgs: string[] = [
'--git-service',
'github',
];
Expand All @@ -289,7 +289,7 @@ test('commit args using context', async () => {
});

test('commit args using github server url', async () => {
const expectedArgs :string[] = [
const expectedArgs: string[] = [
'--git-service',
'github_enterprise',
];
Expand Down
17 changes: 10 additions & 7 deletions src/buildExec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ const isPullRequestFromFork = (): boolean => {
return (baseLabel.split(':')[0] !== headLabel.split(':')[0]);
};

const getToken = async (): Promise<string> => {
const getToken = async (): Promise<string | null> => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a comment on what to expect from null is needed here. Also, you are returning a Promise to null here but further down you are returning null as is

let token = core.getInput('token');
if (!token && isPullRequestFromFork()) {
core.info('==> Fork detected, tokenless uploading used');
process.env['TOKENLESS'] = context.payload.pull_request.head.label;
return Promise.resolve('');
return null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please write a test for this case

}
let url = core.getInput('url');
const useOIDC = isTrue(core.getInput('use_oidc'));
Expand All @@ -60,7 +60,7 @@ const getToken = async (): Promise<string> => {
}
try {
token = await core.getIDToken(url);
return token;
return Promise.resolve(token);
} catch (err) {
setFailure(
`Codecov: Failed to get OIDC token with url: ${url}. ${err.message}`,
Expand All @@ -78,18 +78,21 @@ const buildCommitExec = async (): Promise<{
}> => {
const commitParent = core.getInput('commit_parent');
const gitService = getGitService();
const overrideBranch = core.getInput('override_branch');
let overrideBranch = core.getInput('override_branch');
const overrideCommit = core.getInput('override_commit');
const overridePr = core.getInput('override_pr');
const slug = core.getInput('slug');
const token = await getToken();
if (token == null) {
overrideBranch = context.payload.pull_request?.head.label;
matt-codecov marked this conversation as resolved.
Show resolved Hide resolved
}
const failCi = isTrue(core.getInput('fail_ci_if_error'));
const workingDir = core.getInput('working-directory');

const commitCommand = 'create-commit';
const commitExecArgs = [];

const commitOptions:any = {};
const commitOptions: any = {};
commitOptions.env = Object.assign(process.env, {
GITHUB_ACTION: process.env.GITHUB_ACTION,
GITHUB_RUN_ID: process.env.GITHUB_RUN_ID,
Expand Down Expand Up @@ -178,7 +181,7 @@ const buildReportExec = async (): Promise<{
const reportCommand = 'create-report';
const reportExecArgs = [];

const reportOptions:any = {};
const reportOptions: any = {};
reportOptions.env = Object.assign(process.env, {
GITHUB_ACTION: process.env.GITHUB_ACTION,
GITHUB_RUN_ID: process.env.GITHUB_RUN_ID,
Expand Down Expand Up @@ -268,7 +271,7 @@ const buildUploadExec = async (): Promise<{

const uploadExecArgs = [];
const uploadCommand = 'do-upload';
const uploadOptions:any = {};
const uploadOptions: any = {};
uploadOptions.env = Object.assign(process.env, {
GITHUB_ACTION: process.env.GITHUB_ACTION,
GITHUB_RUN_ID: process.env.GITHUB_RUN_ID,
Expand Down
Loading