Skip to content

Commit e8bbe5f

Browse files
docs: Type Annotations (#1397)
Add missing type annotations
1 parent a6fd87f commit e8bbe5f

File tree

4 files changed

+38
-18
lines changed

4 files changed

+38
-18
lines changed

src/buildExec.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ test('upload args using context', async () => {
5353
];
5454
const {uploadExecArgs, uploadCommand} = await buildUploadExec();
5555
if (context.eventName == 'pull_request') {
56-
expectedArgs.push('-C', `${context.payload.pull_request.head.sha}`);
56+
expectedArgs.push('-C', `${context.payload.pull_request?.head.sha}`);
5757
}
5858
if (context.eventName == 'pull_request_target') {
5959
expectedArgs.push('-P', `${context.payload.number}`);
@@ -218,7 +218,7 @@ test('report args using context', async () => {
218218
'github',
219219
];
220220
if (context.eventName == 'pull_request') {
221-
expectedArgs.push('-C', `${context.payload.pull_request.head.sha}`);
221+
expectedArgs.push('-C', `${context.payload.pull_request?.head.sha}`);
222222
}
223223

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

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

299299
const {commitExecArgs, commitCommand} = await buildCommitExec();
300300
if (context.eventName == 'pull_request') {
301-
expectedArgs.push('-C', `${context.payload.pull_request.head.sha}`);
301+
expectedArgs.push('-C', `${context.payload.pull_request?.head.sha}`);
302302
}
303303
if (context.eventName == 'pull_request_target') {
304304
expectedArgs.push('-P', `${context.payload.number}`);

src/buildExec.ts

+26-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {setFailure} from './helpers';
77

88
const context = github.context;
99

10-
const isTrue = (variable) => {
10+
const isTrue = (variable: string): boolean => {
1111
const lowercase = variable.toLowerCase();
1212
return (
1313
lowercase === '1' ||
@@ -18,7 +18,7 @@ const isTrue = (variable) => {
1818
);
1919
};
2020

21-
const getGitService = () => {
21+
const getGitService = (): string => {
2222
const overrideGitService = core.getInput('git_service');
2323
const serverUrl = process.env.GITHUB_SERVER_URL;
2424
if (overrideGitService) {
@@ -29,7 +29,7 @@ const getGitService = () => {
2929
return 'github';
3030
};
3131

32-
const getToken = async () => {
32+
const getToken = async (): Promise<string> => {
3333
let token = core.getInput('token');
3434
let url = core.getInput('url');
3535
const useOIDC = isTrue(core.getInput('use_oidc'));
@@ -51,7 +51,11 @@ const getToken = async () => {
5151
return token;
5252
};
5353

54-
const buildCommitExec = async () => {
54+
const buildCommitExec = async (): Promise<{
55+
commitExecArgs: any[];
56+
commitOptions: any;
57+
commitCommand: string;
58+
}> => {
5559
const commitParent = core.getInput('commit_parent');
5660
const gitService = getGitService();
5761
const overrideBranch = core.getInput('override_branch');
@@ -116,7 +120,10 @@ const buildCommitExec = async () => {
116120
return {commitExecArgs, commitOptions, commitCommand};
117121
};
118122

119-
const buildGeneralExec = () => {
123+
const buildGeneralExec = (): {
124+
args: any[];
125+
verbose: boolean;
126+
} => {
120127
const codecovYmlPath = core.getInput('codecov_yml_path');
121128
const url = core.getInput('url');
122129
const verbose = isTrue(core.getInput('verbose'));
@@ -134,7 +141,11 @@ const buildGeneralExec = () => {
134141
return {args, verbose};
135142
};
136143

137-
const buildReportExec = async () => {
144+
const buildReportExec = async (): Promise<{
145+
reportExecArgs: any[];
146+
reportOptions: any;
147+
reportCommand: string;
148+
}> => {
138149
const gitService = getGitService();
139150
const overrideCommit = core.getInput('override_commit');
140151
const overridePr = core.getInput('override_pr');
@@ -191,7 +202,15 @@ const buildReportExec = async () => {
191202
return {reportExecArgs, reportOptions, reportCommand};
192203
};
193204

194-
const buildUploadExec = async () => {
205+
const buildUploadExec = async (): Promise<{
206+
uploadExecArgs: any[];
207+
uploadOptions: any;
208+
disableSafeDirectory: boolean;
209+
failCi: boolean;
210+
os: string;
211+
uploaderVersion: string;
212+
uploadCommand: string;
213+
}> => {
195214
const disableFileFixes = isTrue(core.getInput('disable_file_fixes'));
196215
const disableSafeDirectory = isTrue(core.getInput('disable_safe_directory'));
197216
const disableSearch = isTrue(core.getInput('disable_search'));

src/helpers.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ const PLATFORMS = [
88
'alpine',
99
'linux-arm64',
1010
'alpine-arm64',
11-
];
11+
] as const;
12+
type Platform = typeof PLATFORMS[number];
1213

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

28-
const isValidPlatform = (platform: string): boolean => {
29-
return PLATFORMS.includes(platform);
29+
const isValidPlatform = (platform: string): platform is Platform => {
30+
return PLATFORMS.includes(platform as Platform);
3031
};
3132

3233
const isWindows = (platform: string): boolean => {

src/index.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import versionInfo from './version';
2424

2525
let failCi;
2626

27-
const run = async () => {
27+
const run = async (): Promise<void> => {
2828
try {
2929
const {commitExecArgs, commitOptions, commitCommand} = await buildCommitExec();
3030
const {reportExecArgs, reportOptions, reportCommand} = await buildReportExec();
@@ -62,7 +62,7 @@ const run = async () => {
6262
await setSafeDirectory();
6363
}
6464

65-
const unlink = () => {
65+
const unlink = (): void => {
6666
fs.unlink(filename, (err) => {
6767
if (err) {
6868
setFailure(
@@ -72,7 +72,7 @@ const run = async () => {
7272
}
7373
});
7474
};
75-
const doUpload = async () => {
75+
const doUpload = async (): Promise<void> => {
7676
await exec.exec(getCommand(filename, args, uploadCommand).join(' '),
7777
uploadExecArgs,
7878
uploadOptions)
@@ -84,7 +84,7 @@ const run = async () => {
8484
);
8585
});
8686
};
87-
const createReport = async () => {
87+
const createReport = async (): Promise<void> => {
8888
await exec.exec(
8989
getCommand(filename, args, reportCommand).join(' '),
9090
reportExecArgs,

0 commit comments

Comments
 (0)