Skip to content

Commit c7e9a89

Browse files
committed
ci: add client feedback
1 parent fa826eb commit c7e9a89

2 files changed

Lines changed: 76 additions & 0 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: "client feedback"
2+
3+
on:
4+
issues:
5+
types: [opened]
6+
7+
jobs:
8+
create:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
- uses: actions/setup-node@v2
13+
with:
14+
node-version: "16"
15+
registry-url: https://registry.npmjs.org/
16+
- run: node scripts/client-feedback.js ${{ secrets.GITHUB_TOKEN }} ${{ github.event.issue.number }} "${{ github.event.issue.title }}" ${{ github.event.issue.body }}

scripts/client-feedback.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
const https = require("https");
2+
3+
const args = process.argv;
4+
5+
const token = args[2];
6+
const issueNumber = args[3];
7+
const title = args[4];
8+
const body = args[5];
9+
10+
(async () => {
11+
if (!title || !body) return;
12+
if (title != "From client, DO NOT EDIT!") return;
13+
const bodyObj = JSON.parse(Buffer.from(body, "base64").toString("utf-8"));
14+
if (!bodyObj) return;
15+
console.log("bodyObj", bodyObj);
16+
const req = https.request(
17+
{
18+
hostname: "api.github.com",
19+
port: 443,
20+
path: `/repos/hal-wang/lavcode-test/issues/${issueNumber}`,
21+
method: "PATCH",
22+
headers: {
23+
Authorization: `Bearer ${token}`,
24+
Accept: "application/vnd.github+json",
25+
"user-agent":
26+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36 Edg/105.0.1343.42",
27+
},
28+
},
29+
(res) => {
30+
let chunks = Buffer.from([]);
31+
let chunksLength = chunks.length;
32+
res.on("data", (data) => {
33+
chunks = Buffer.concat([chunks, data], chunksLength + data.length);
34+
chunksLength = chunks.length;
35+
});
36+
res.on("end", () => {
37+
console.log("end", chunks.toString("utf-8"));
38+
});
39+
40+
console.log("statusCode", res.statusCode);
41+
}
42+
);
43+
req.on("error", (err) => {
44+
console.log("err", err);
45+
});
46+
req.write(
47+
JSON.stringify({
48+
title: bodyObj.title,
49+
body: bodyObj.body,
50+
labels: [
51+
"client feedback",
52+
`platform ${bodyObj.platform}`,
53+
`version ${bodyObj.version}`,
54+
`provider ${bodyObj.provider}`,
55+
],
56+
assignees: ["hal-wang"],
57+
})
58+
);
59+
req.end();
60+
})();

0 commit comments

Comments
 (0)