Created
June 14, 2023 02:34
-
-
Save Fatpandac/b5ff166d9571f5c474feba15c9cde84b to your computer and use it in GitHub Desktop.
Push GitHub repo update to channel of QQ qunpro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Application, Router } from "https://deno.land/x/[email protected]/mod.ts"; | |
const sentMsgToQQ = (channelId: string, body: string) => { | |
const QQ_QUNPRO_API_BASE = "https://sandbox.api.sgroup.qq.com" | |
const QQ_QUNPRO_API_SENT_MESSAGE = `/channels/${channelId}/messages` | |
const options = { | |
method: 'POST', | |
headers: { | |
'Authorization': 'Bot ${QQ_BOT_ID}.${QQ_BOT_TOKEN}', | |
'Content-Type': 'application/json' | |
}, | |
body, | |
}; | |
fetch(QQ_QUNPRO_API_BASE + QQ_QUNPRO_API_SENT_MESSAGE, options) | |
.then(response => response.json()) | |
.then(data => console.log(data)) | |
.catch(error => console.error(error)); | |
} | |
interface BodyData { | |
full_name: string, | |
html_url: string, | |
commitsMsg: string | |
} | |
const sentPushEvent = (channelId: string, bodyData: BodyData) => { | |
const sentMsg = JSON.stringify({ | |
content: `${bodyData.full_name}\n\nCommits:\n${bodyData.commitsMsg}` | |
}) | |
sentMsgToQQ(channelId, sentMsg) | |
} | |
const router = new Router(); | |
router.get("/", (ctx) => { | |
ctx.response.body = `<!DOCTYPE html> | |
<html> | |
<head><title>Hello oak!</title><head> | |
<body> | |
<h1>Hello oak!</h1> | |
</body> | |
</html> | |
`; | |
}).post("/notify/:channelId", async (ctx) => { | |
const result = ctx.request.body() | |
const channelId = ctx.params.channelId; | |
const data = await result.value | |
const {full_name, html_url} = data.repository | |
// deno-lint-ignore no-explicit-any | |
const commitsMsg = data.commits.map((commit: any) => commit.message).join("\n") || data.head_commit.message | |
sentPushEvent(channelId, { | |
full_name, | |
html_url, | |
commitsMsg | |
}) | |
ctx.response.body = "OK" | |
}) | |
const app = new Application(); | |
app.use(router.routes()); | |
app.use(router.allowedMethods()); | |
app.listen({ port: 8080 }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment