Skip to content

Commit

Permalink
feat: pass tokenless value as branch override
Browse files Browse the repository at this point in the history
instead of only passing the tokenless branch value as an environment
variable we want to pass it as the branch value to the CLI
  • Loading branch information
joseph-sentry committed Jul 15, 2024
1 parent 9e14515 commit a3454c1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 20 deletions.
18 changes: 11 additions & 7 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32351,12 +32351,13 @@ const isPullRequestFromFork = () => {
return (baseLabel.split(':')[0] !== headLabel.split(':')[0]);
};
const getToken = () => buildExec_awaiter(void 0, void 0, void 0, function* () {
if (isPullRequestFromFork()) {
var _a;
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 [false, (_a = context.payload.pull_request) === null || _a === void 0 ? void 0 : _a.head.label];
}
let token = core.getInput('token');
let url = core.getInput('url');
const useOIDC = isTrue(core.getInput('use_oidc'));
if (useOIDC) {
Expand All @@ -32365,22 +32366,25 @@ const getToken = () => buildExec_awaiter(void 0, void 0, void 0, function* () {
}
try {
token = yield core.getIDToken(url);
return token;
return [true, token];
}
catch (err) {
setFailure(`Codecov: Failed to get OIDC token with url: ${url}. ${err.message}`, true);
}
}
return token;
return [true, token];
});
const buildCommitExec = () => buildExec_awaiter(void 0, void 0, void 0, function* () {
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();
const [tokenAvailable, token] = yield getToken();
if (!tokenAvailable) {
overrideBranch = token;
}
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
21 changes: 12 additions & 9 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<[boolean, string]> => {
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 [false, context.payload.pull_request?.head.label];
}
let url = core.getInput('url');
const useOIDC = isTrue(core.getInput('use_oidc'));
Expand All @@ -60,15 +60,15 @@ const getToken = async (): Promise<string> => {
}
try {
token = await core.getIDToken(url);
return token;
return [true, token];
} catch (err) {
setFailure(
`Codecov: Failed to get OIDC token with url: ${url}. ${err.message}`,
true,
);
}
}
return token;
return [true, token];
};

const buildCommitExec = async (): Promise<{
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();
const [tokenAvailable, token] = await getToken();
if (!tokenAvailable) {
overrideBranch = token;
}
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

0 comments on commit a3454c1

Please sign in to comment.