Skip to content

Commit 4118c36

Browse files
committed
feat: restart parameter
1 parent 77db503 commit 4118c36

6 files changed

Lines changed: 44 additions & 30 deletions

File tree

dist/629.index.js

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/629.index.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js

Lines changed: 18 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,36 @@
11
import * as core from "@actions/core";
22
import FormData from "form-data";
3-
import { request } from "./request";
3+
import { ApiResponse, request } from "./request";
44
import { zipProject } from "./zip";
55

66
async function run(): Promise<void> {
77
try {
8-
const token: string = core.getInput("token");
9-
const id: string = core.getInput("application_id");
10-
const restart: string = core.getInput("restart");
11-
const exclusions: string[] = core.getInput("exclusions").split(" ");
8+
const token: string = core.getInput("token", { required: true });
9+
const id: string = core.getInput("application_id", { required: true });
10+
const restart: boolean = core.getBooleanInput("restart");
11+
const exclusionsString: string = core.getInput("exclusions");
12+
const exclusions = exclusionsString.trim() == "" ? [] : exclusionsString.trim().split(" ")
1213

1314
const buffer = zipProject(exclusions);
1415

1516
const formadata = new FormData();
1617
formadata.append("file", buffer, { filename: "application.zip" });
17-
formadata.append("restart", restart);
1818

19-
request("POST", "/commit/" + id, {
19+
request("POST", `/commit/${id}?restart=${restart}`, {
2020
headers: {
2121
Authorization: token,
2222
...formadata.getHeaders(),
2323
},
2424
body: formadata,
2525
}).then((res) => {
26+
core.debug(JSON.stringify(res));
2627
if (res.code != "SUCCESS") {
27-
core.setFailed(JSON.stringify(res));
28+
console.log(JSON.stringify(res))
29+
core.setFailed(`Square Cloud returned code: ${res.code}`);
2830
}
2931

3032
console.log(res.message);
31-
});
33+
}).catch((err) => core.setFailed(err));
3234
} catch (error) {
3335
if (error instanceof Error) core.setFailed(error.message);
3436
}

src/request.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,26 @@ import type { RequestInit } from "node-fetch";
22
import fetch from "node-fetch";
33

44
const API_VERSION = "v1";
5-
const BASE_URL = `https://api.squarecloud.app/${API_VERSION}/public/`;
5+
const BASE_URL = `https://api.squarecloud.app/${API_VERSION}/public`;
66

7-
interface ApiResponse {
7+
export interface ApiResponse {
88
status: string;
99
code: string;
1010
message: string;
1111
}
1212

13-
export function request<T extends ApiResponse>(
14-
method: string,
15-
path: string,
16-
options: RequestInit,
17-
): Promise<T> {
13+
export function request(method: string, path: string, options: RequestInit): Promise<ApiResponse> {
1814
return fetch(BASE_URL + path, {
1915
method,
16+
redirect: "follow",
2017
...options,
2118
}).then(async (response) => {
22-
return (await response.json()) as T;
19+
const contentType = response.headers.get("Content-Type");
20+
if (!contentType || !contentType.includes("application/json")) {
21+
console.log(response)
22+
throw new Error(`Returned code ${response.status}, but response is not a json`);
23+
}
24+
25+
return response.json() as Promise<ApiResponse>;
2326
});
2427
}

0 commit comments

Comments
 (0)