-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
47 lines (32 loc) · 1.69 KB
/
main.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { PullRequestClient, ProjectClient } from "https://deno.land/x/[email protected]/GitHubClients/mod.ts";
import { BasePayload } from "./data/payloads/base-payload.ts";
import { Validator } from "./services/validator.ts";
import { PayloadProcessor } from "./payload-processor.ts";
const prMetaDataRegex = /<!--\s*closed-by-pr:\s*[1-9][0-9]*\s*-->/gm;
Deno.serve({ port: 3000 }, async (req) => {
const url = new URL(req.url);
if (url.pathname !== "/webhook") {
return new Response("Not Found", { status: 404 });
}
const jsonData = await req.text();
const validationResult = await Validator.validateRequest(req.headers, jsonData);
if (!validationResult.isValid) {
return new Response(validationResult.message, { status: 403 });
}
const data: BasePayload = JSON.parse(jsonData);
const processor = new PayloadProcessor();
processor.processPayload(data);
return new Response("asdf", { status: 200 });
const repoOwner = data.repository.owner.login;
const repoName = data.repository.name;
const token = Deno.env.get("GITHUB_TOKEN") ?? "";
const prClient = new PullRequestClient(repoOwner, repoName, token);
await prClient.addLabel(2, data.label.name);
// TODO: NEed to get the pull request number based on the issue body that contains the special syntax
const pr = await prClient.getPullRequest(2);
// const projClient = new ProjectClient(repoOwner, repoName, token);
const prUrl = `https://github.com/${repoOwner}/${repoName}/pull/${2}`;
const msg = `The label '${data.label.name}' has been added to pull request '${2} - (${prUrl})'`;
console.log(msg);
return new Response(msg, { status: 200 });
});