-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard.js
More file actions
49 lines (42 loc) · 1.4 KB
/
dashboard.js
File metadata and controls
49 lines (42 loc) · 1.4 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const dotenv = require('dotenv');
const { createServer } = require("http");
const { Octokit } = require("@octokit/core");
dotenv.config();
const octokit = new Octokit({
auth: process.env.GH_TOKEN,
});
//create a server object:
createServer(async function (req, res) {
console.log("Reequest ke ", req.url, " dimulai");
console.log(req.url);
if (req.url.includes("/api")) {
res.setHeader("Content-Type", "application/json");
// https://docs.github.com/en/rest/reference/actions#create-a-workflow-dispatch-event
const response = await octokit.request(
"POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches",
{
owner: process.env.GH_OWNER,
repo: process.env.GH_REPO,
workflow_id: process.env.GH_WORKFLOW,
ref: process.env.GH_REF,
inputs: JSON.parse(process.env.GH_INPUT)
},
);
res.write(JSON.stringify(response));
res.end(); //end the response
} else {
res.setHeader("Content-Type", "text/html");
res.write(`
<h2>How To:</h2>
<ul>
<li>Copy .env.example to .env</li>
<li>Update Value</li>
<li>Running Service</li>
<li>Click Submit Button Below</li>
</ul>
<form action="/api">
<input type="submit" value="Submit">
</form>`); //write a response to the client
res.end(); //end the response
}
}).listen(3000); //the server object listens on port 8080