Skip to content

Commit

Permalink
docs: Type Annotations (#1397)
Browse files Browse the repository at this point in the history
Add missing type annotations
  • Loading branch information
marcobiedermann committed Apr 30, 2024
1 parent a6fd87f commit e8bbe5f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 18 deletions.
8 changes: 4 additions & 4 deletions src/buildExec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ test('upload args using context', async () => {
];
const {uploadExecArgs, uploadCommand} = await buildUploadExec();
if (context.eventName == 'pull_request') {
expectedArgs.push('-C', `${context.payload.pull_request.head.sha}`);
expectedArgs.push('-C', `${context.payload.pull_request?.head.sha}`);
}
if (context.eventName == 'pull_request_target') {
expectedArgs.push('-P', `${context.payload.number}`);
Expand Down Expand Up @@ -218,7 +218,7 @@ test('report args using context', async () => {
'github',
];
if (context.eventName == 'pull_request') {
expectedArgs.push('-C', `${context.payload.pull_request.head.sha}`);
expectedArgs.push('-C', `${context.payload.pull_request?.head.sha}`);
}

const {reportExecArgs, reportCommand} = await buildReportExec();
Expand Down Expand Up @@ -278,7 +278,7 @@ test('commit args using context', async () => {

const {commitExecArgs, commitCommand} = await buildCommitExec();
if (context.eventName == 'pull_request') {
expectedArgs.push('-C', `${context.payload.pull_request.head.sha}`);
expectedArgs.push('-C', `${context.payload.pull_request?.head.sha}`);
}
if (context.eventName == 'pull_request_target') {
expectedArgs.push('-P', `${context.payload.number}`);
Expand All @@ -298,7 +298,7 @@ test('commit args using github server url', async () => {

const {commitExecArgs, commitCommand} = await buildCommitExec();
if (context.eventName == 'pull_request') {
expectedArgs.push('-C', `${context.payload.pull_request.head.sha}`);
expectedArgs.push('-C', `${context.payload.pull_request?.head.sha}`);
}
if (context.eventName == 'pull_request_target') {
expectedArgs.push('-P', `${context.payload.number}`);
Expand Down
33 changes: 26 additions & 7 deletions src/buildExec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {setFailure} from './helpers';

const context = github.context;

const isTrue = (variable) => {
const isTrue = (variable: string): boolean => {
const lowercase = variable.toLowerCase();
return (
lowercase === '1' ||
Expand All @@ -18,7 +18,7 @@ const isTrue = (variable) => {
);
};

const getGitService = () => {
const getGitService = (): string => {
const overrideGitService = core.getInput('git_service');
const serverUrl = process.env.GITHUB_SERVER_URL;
if (overrideGitService) {
Expand All @@ -29,7 +29,7 @@ const getGitService = () => {
return 'github';
};

const getToken = async () => {
const getToken = async (): Promise<string> => {
let token = core.getInput('token');
let url = core.getInput('url');
const useOIDC = isTrue(core.getInput('use_oidc'));
Expand All @@ -51,7 +51,11 @@ const getToken = async () => {
return token;
};

const buildCommitExec = async () => {
const buildCommitExec = async (): Promise<{
commitExecArgs: any[];
commitOptions: any;
commitCommand: string;
}> => {
const commitParent = core.getInput('commit_parent');
const gitService = getGitService();
const overrideBranch = core.getInput('override_branch');
Expand Down Expand Up @@ -116,7 +120,10 @@ const buildCommitExec = async () => {
return {commitExecArgs, commitOptions, commitCommand};
};

const buildGeneralExec = () => {
const buildGeneralExec = (): {
args: any[];
verbose: boolean;
} => {
const codecovYmlPath = core.getInput('codecov_yml_path');
const url = core.getInput('url');
const verbose = isTrue(core.getInput('verbose'));
Expand All @@ -134,7 +141,11 @@ const buildGeneralExec = () => {
return {args, verbose};
};

const buildReportExec = async () => {
const buildReportExec = async (): Promise<{
reportExecArgs: any[];
reportOptions: any;
reportCommand: string;
}> => {
const gitService = getGitService();
const overrideCommit = core.getInput('override_commit');
const overridePr = core.getInput('override_pr');
Expand Down Expand Up @@ -191,7 +202,15 @@ const buildReportExec = async () => {
return {reportExecArgs, reportOptions, reportCommand};
};

const buildUploadExec = async () => {
const buildUploadExec = async (): Promise<{
uploadExecArgs: any[];
uploadOptions: any;
disableSafeDirectory: boolean;
failCi: boolean;
os: string;
uploaderVersion: string;
uploadCommand: string;
}> => {
const disableFileFixes = isTrue(core.getInput('disable_file_fixes'));
const disableSafeDirectory = isTrue(core.getInput('disable_safe_directory'));
const disableSearch = isTrue(core.getInput('disable_search'));
Expand Down
7 changes: 4 additions & 3 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const PLATFORMS = [
'alpine',
'linux-arm64',
'alpine-arm64',
];
] as const;
type Platform = typeof PLATFORMS[number];

const setFailure = (message: string, failCi: boolean): void => {
failCi ? core.setFailed(message) : core.warning(message);
Expand All @@ -25,8 +26,8 @@ const getUploaderName = (platform: string): string => {
}
};

const isValidPlatform = (platform: string): boolean => {
return PLATFORMS.includes(platform);
const isValidPlatform = (platform: string): platform is Platform => {
return PLATFORMS.includes(platform as Platform);
};

const isWindows = (platform: string): boolean => {
Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import versionInfo from './version';

let failCi;

const run = async () => {
const run = async (): Promise<void> => {
try {
const {commitExecArgs, commitOptions, commitCommand} = await buildCommitExec();
const {reportExecArgs, reportOptions, reportCommand} = await buildReportExec();
Expand Down Expand Up @@ -62,7 +62,7 @@ const run = async () => {
await setSafeDirectory();
}

const unlink = () => {
const unlink = (): void => {
fs.unlink(filename, (err) => {
if (err) {
setFailure(
Expand All @@ -72,7 +72,7 @@ const run = async () => {
}
});
};
const doUpload = async () => {
const doUpload = async (): Promise<void> => {
await exec.exec(getCommand(filename, args, uploadCommand).join(' '),
uploadExecArgs,
uploadOptions)
Expand All @@ -84,7 +84,7 @@ const run = async () => {
);
});
};
const createReport = async () => {
const createReport = async (): Promise<void> => {
await exec.exec(
getCommand(filename, args, reportCommand).join(' '),
reportExecArgs,
Expand Down

0 comments on commit e8bbe5f

Please sign in to comment.