|
| 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