docs: Type Annotations (#1397)

Add missing type annotations
This commit is contained in:
Marco Biedermann
2024-04-30 10:29:24 +02:00
committed by GitHub
parent a6fd87fc19
commit e8bbe5fc01
4 changed files with 38 additions and 18 deletions

View File

@@ -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}`);
@@ -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();
@@ -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}`);
@@ -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}`);

View File

@@ -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' ||
@@ -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) {
@@ -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'));
@@ -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');
@@ -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'));
@@ -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');
@@ -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'));

View File

@@ -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);
@@ -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 => {

View File

@@ -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();
@@ -62,7 +62,7 @@ const run = async () => {
await setSafeDirectory();
}
const unlink = () => {
const unlink = (): void => {
fs.unlink(filename, (err) => {
if (err) {
setFailure(
@@ -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)
@@ -84,7 +84,7 @@ const run = async () => {
);
});
};
const createReport = async () => {
const createReport = async (): Promise<void> => {
await exec.exec(
getCommand(filename, args, reportCommand).join(' '),
reportExecArgs,