Skip to content

Commit 8014ad1

Browse files
authored
Merge pull request #1 from them2dt/main
implement pull-check
2 parents 529fe9b + 2214c32 commit 8014ad1

13 files changed

+4636
-0
lines changed

.eslintrc.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "next/core-web-vitals"
3+
}

.gitignore

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
.yarn/install-state.gz
8+
9+
# testing
10+
/coverage
11+
12+
# next.js
13+
/.next/
14+
/out/
15+
16+
# production
17+
/build
18+
19+
# misc
20+
.DS_Store
21+
*.pem
22+
23+
# debug
24+
npm-debug.log*
25+
yarn-debug.log*
26+
yarn-error.log*
27+
28+
# local env files
29+
.env*.local
30+
31+
# vercel
32+
.vercel
33+
34+
# typescript
35+
*.tsbuildinfo
36+
next-env.d.ts

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1+
# Pull-Check by THEM2DT
2+
With this small local NextJS-app you can check if pull requests are open or closed.
13

4+
## Getting Started
5+
```bash
6+
# initialize
7+
npm install
8+
# run
9+
npm run dev

app/favicon.ico

25.3 KB
Binary file not shown.

app/globals.css

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
html,
2+
body {
3+
margin: 0;
4+
padding: 0;
5+
}
6+
7+
main {
8+
width: 100vw;
9+
height: 100vh;
10+
11+
display: flex;
12+
align-items: center;
13+
justify-content: center;
14+
font-family: 'consolas';
15+
}
16+
17+
.input-row {
18+
display: flex;
19+
align-items: center;
20+
justify-content: center;
21+
gap: 5px;
22+
}
23+
24+
input {
25+
width: 500px;
26+
height: 60px;
27+
padding: 10px;
28+
border: 1px solid rgba(0, 0, 0, 0.25);
29+
border-radius: 10px;
30+
box-sizing: border-box;
31+
font-family: 'consolas';
32+
outline: none;
33+
34+
}
35+
36+
button {
37+
width: fit-content;
38+
height: 60px;
39+
padding: 10px;
40+
background-color: rgb(111, 66, 216);
41+
border: 1px solid rgba(0, 0, 0, 0.05);
42+
border-radius: 10px;
43+
box-sizing: border-box;
44+
color: rgb(255, 255, 255);
45+
font-size: 18px;
46+
font-weight: 600;
47+
font-family: 'consolas';
48+
cursor: pointer;
49+
}
50+
51+
.validation {
52+
display: flex;
53+
flex-direction: column;
54+
align-items: center;
55+
justify-content: center;
56+
gap: 10px;
57+
58+
padding-top: 10px;
59+
}
60+
61+
.status-bar {
62+
width: fill;
63+
height: 80px;
64+
65+
padding: 10px;
66+
display: flex;
67+
align-items: center;
68+
justify-content: flex-start;
69+
70+
background-color: rgb(255, 226, 148);
71+
border: 1px solid rgb(209, 184, 114);
72+
border-radius: 10px;
73+
box-sizing: border-box;
74+
}
75+
76+
.status-bar.open {
77+
background-color: rgb(155, 247, 155);
78+
border-color: green;
79+
}
80+
81+
.status-bar.closed {
82+
background-color: rgb(206, 155, 247);
83+
border-color: rgb(87, 0, 128);
84+
}

app/layout.tsx

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export default function RootLayout({
2+
children,
3+
}: Readonly<{
4+
children: React.ReactNode;
5+
}>) {
6+
return (
7+
<html lang="en">
8+
<body>{children}</body>
9+
</html>
10+
);
11+
}

app/page.tsx

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
"use client";
2+
import "./globals.css";
3+
import { useState } from "react";
4+
import { Octokit } from "@octokit/core";
5+
6+
export default function Home() {
7+
const [link, setLink] = useState<string>("");
8+
const [pullStatus, setPullStatus] = useState<string>();
9+
const [requestStatus, setRequestStatus] = useState<number>();
10+
11+
const filterParams = () => {
12+
const delimiter1 = "github.com";
13+
const delimiter2 = "https://github.com";
14+
// remove head
15+
const regex = new RegExp(`${delimiter1}|${delimiter2}`, "g");
16+
const withoutHead = link.split(regex);
17+
// split into required parameters
18+
const params = withoutHead[1].split("/");
19+
return params;
20+
};
21+
22+
const run = async () => {
23+
const params = filterParams();
24+
try {
25+
console.log("initializing octokit...");
26+
const octokit = new Octokit({
27+
auth: "GITHUB_ACCESS_TOKEN",//here goes your personal github access token
28+
});
29+
console.log("validating input...");
30+
31+
if (params[1] && params[2] && params[4]) {
32+
console.log("sending request...");
33+
const response = await octokit.request(
34+
"GET /repos/{owner}/{repo}/pulls/{pull_number}",
35+
{
36+
owner: params[1],
37+
repo: params[2],
38+
pull_number: Number(params[4]),
39+
headers: {
40+
"X-GitHub-Api-Version": "2022-11-28",
41+
},
42+
}
43+
);
44+
console.log(JSON.parse(JSON.stringify(response)));
45+
46+
setPullStatus(JSON.parse(JSON.stringify(response))["data"]["state"]);
47+
setRequestStatus(JSON.parse(JSON.stringify(response))["status"]);
48+
} else {
49+
console.log("Missing parameters...");
50+
}
51+
} catch (e) {}
52+
};
53+
return (
54+
<main>
55+
<div className="container">
56+
<div className="input-row">
57+
<input
58+
placeholder="URL of pull request (E.g: github.com/anthony/myrepo/pull/453"
59+
type="text"
60+
value={link}
61+
onChange={(e) => setLink(e.target.value)}
62+
/>
63+
<button onClick={run}>submit</button>
64+
</div>
65+
<div className="validation">
66+
{requestStatus != 200 && requestStatus && (
67+
<div className="status-bar invalid">Pull request is invalid.</div>
68+
)}
69+
{requestStatus == 200 && pullStatus == "open" && (
70+
<div className="status-bar open">Pull request is open.</div>
71+
)}
72+
{requestStatus == 200 && pullStatus == "closed" && (
73+
<div className="status-bar closed">Pull request is closed.</div>
74+
)}
75+
</div>
76+
</div>
77+
</main>
78+
);
79+
}

next.config.mjs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/** @type {import('next').NextConfig} */
2+
const nextConfig = {};
3+
4+
export default nextConfig;

0 commit comments

Comments
 (0)