Skip to content

Commit 05544cf

Browse files
committed
Closes #5 and #6
1 parent 0719f9c commit 05544cf

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

src/action.ts

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,25 @@ const uploadAsset = async (client: GitHub, params: ReposUploadReleaseAssetParams
1717
return response.data.value;
1818
};
1919

20+
21+
const prepareHeaders = (fullPathChecked: string, mime: string) => {
22+
return {
23+
"content-length": fs.statSync(fullPathChecked).size,
24+
"content-type": mime || getType(fullPathChecked.toString()) || "application/zip",
25+
};
26+
};
27+
28+
const prepareParams = (data: Buffer, headers: { "content-length": number; "content-type": string; },
29+
label: string, name: string, url: string): Octokit.Octokit.ReposUploadReleaseAssetParams => {
30+
return {
31+
data,
32+
headers,
33+
label,
34+
name,
35+
url,
36+
};
37+
};
38+
2039
export const run = async () => {
2140
const path = core.getInput("path", { required: true });
2241

@@ -32,25 +51,15 @@ export const run = async () => {
3251

3352
const github = new GitHub(process.env.GITHUB_TOKEN);
3453
const fullPathChecked: fs.PathLike = resolve(fs.realpathSync(path));
35-
36-
const headers = {
37-
"content-length": fs.statSync(fullPathChecked).size,
38-
"content-type": mime || getType(fullPathChecked.toString()) || "application/zip",
39-
};
40-
54+
const headers = prepareHeaders(fullPathChecked, mime);
4155
const data = fs.readFileSync(fullPathChecked);
4256

43-
const asset = await uploadAsset(github, {
44-
data,
45-
headers,
46-
label,
47-
name,
48-
url,
49-
});
57+
const asset = await uploadAsset(github, prepareParams(data, headers, label, name, url));
5058

5159
core.setOutput("id", asset.id.toString());
5260
core.setOutput("url", asset.browser_download_url);
5361
} catch (error) {
5462
core.setFailed(error);
5563
}
5664
};
65+

tslint.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"rules": {
44
"align": [
55
true,
6-
"parameters",
76
"arguments",
87
"statements"
98
],

0 commit comments

Comments
 (0)