forked from ubiquity/ubiquibot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.ts
More file actions
44 lines (39 loc) · 1.3 KB
/
Copy pathparser.ts
File metadata and controls
44 lines (39 loc) · 1.3 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
import axios from "axios";
import { HTMLElement, parse } from "node-html-parser";
interface GitParser {
owner: string;
repo: string;
issue_number: number;
}
export const gitIssueParser = async ({ owner, repo, issue_number }: GitParser): Promise<boolean> => {
try {
const { data } = await axios.get(`https://github.com/${owner}/${repo}/issues/${issue_number}`);
const dom = parse(data);
const devForm = dom.querySelector("[data-target='create-branch.developmentForm']") as HTMLElement;
const linkedPRs = devForm.querySelectorAll(".my-1");
if (linkedPRs.length > 0) {
//has LinkedPRs
return true;
} else {
//no LinkedPRs
return false;
}
} catch (error) {
return true;
}
};
export const gitLinkedIssueParser = async ({ owner, repo, issue_number }: GitParser): Promise<string> => {
try {
const { data } = await axios.get(`https://github.com/${owner}/${repo}/pull/${issue_number}`);
const dom = parse(data);
const devForm = dom.querySelector("[data-target='create-branch.developmentForm']") as HTMLElement;
const linkedPRs = devForm.querySelectorAll(".my-1");
if (linkedPRs.length === 0) {
return "";
}
const prUrl = linkedPRs[0].querySelector("a")?.attrs?.href || "";
return prUrl;
} catch (error) {
return "";
}
};