-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
33 lines (27 loc) · 1.06 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import * as core from "@actions/core";
import axios, { AxiosRequestConfig } from "axios";
async function makeApiRequest() {
try {
// Input parameters from the GitHub Action workflow
const apiUrl = core.getInput("url", { required: true });
const headers = JSON.parse(core.getInput("headers"));
const requestBody = core.getInput("body");
const method = core.getInput("method") || "POST"; // Default to "POST" if not specified
// Define the HTTP request configuration
const config: AxiosRequestConfig = {
url: apiUrl,
method, // Use the specified method or "POST" by default
headers,
data: requestBody,
};
// Make the API request
const response = await axios(config);
// Output the API response data
core.setOutput("response-status", response.status.toString());
core.setOutput("response-data", JSON.stringify(response.data));
core.info(`API request succeeded with status code ${response.status}`);
} catch (err: any) {
core.setFailed(`API request failed: ${err.message}`);
}
}
makeApiRequest();