Skip to content

Commit 28fe97a

Browse files
authored
refactor: change structure & automatize (#5)
2 parents b86f6cf + c48b261 commit 28fe97a

File tree

108 files changed

+480
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+480
-0
lines changed

.github/pull_request_template.md

Lines changed: 8 additions & 0 deletions

.github/workflows/review.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Review
2+
on:
3+
pull_request_target: {}
4+
5+
permissions:
6+
contents: write
7+
pull-requests: write
8+
9+
jobs:
10+
review:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
with:
15+
ref: refs/pull/${{ github.event.number }}/merge
16+
- uses: oven-sh/setup-bun@v1
17+
18+
- name: Get changed files
19+
uses: lots0logs/gh-action-get-changed-files@e5c59575dff4a94f74c6cc609a77c71f0becf7ec
20+
with:
21+
token: ${{ secrets.GITHUB_TOKEN }}
22+
23+
- run: |
24+
sudo apt update -y && sudo apt upgrade -y
25+
sudo apt install -y exiftool
26+
27+
- run: bun review
28+
env:
29+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30+
COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
31+
PR_NUMBER: ${{ github.event.pull_request.number }}
32+
33+
- name: Push changes
34+
uses: actions-js/push@master
35+
with:
36+
github_token: "${{ secrets.GITHUB_TOKEN }}"

.gitignore

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore
2+
3+
# Logs
4+
5+
logs
6+
_.log
7+
npm-debug.log_
8+
yarn-debug.log*
9+
yarn-error.log*
10+
lerna-debug.log*
11+
.pnpm-debug.log*
12+
13+
# Caches
14+
15+
.cache
16+
17+
# Diagnostic reports (https://nodejs.org/api/report.html)
18+
19+
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
20+
21+
# Runtime data
22+
23+
pids
24+
_.pid
25+
_.seed
26+
*.pid.lock
27+
28+
# Directory for instrumented libs generated by jscoverage/JSCover
29+
30+
lib-cov
31+
32+
# Coverage directory used by tools like istanbul
33+
34+
coverage
35+
*.lcov
36+
37+
# nyc test coverage
38+
39+
.nyc_output
40+
41+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
42+
43+
.grunt
44+
45+
# Bower dependency directory (https://bower.io/)
46+
47+
bower_components
48+
49+
# node-waf configuration
50+
51+
.lock-wscript
52+
53+
# Compiled binary addons (https://nodejs.org/api/addons.html)
54+
55+
build/Release
56+
57+
# Dependency directories
58+
59+
node_modules/
60+
jspm_packages/
61+
62+
# Snowpack dependency directory (https://snowpack.dev/)
63+
64+
web_modules/
65+
66+
# TypeScript cache
67+
68+
*.tsbuildinfo
69+
70+
# Optional npm cache directory
71+
72+
.npm
73+
74+
# Optional eslint cache
75+
76+
.eslintcache
77+
78+
# Optional stylelint cache
79+
80+
.stylelintcache
81+
82+
# Microbundle cache
83+
84+
.rpt2_cache/
85+
.rts2_cache_cjs/
86+
.rts2_cache_es/
87+
.rts2_cache_umd/
88+
89+
# Optional REPL history
90+
91+
.node_repl_history
92+
93+
# Output of 'npm pack'
94+
95+
*.tgz
96+
97+
# Yarn Integrity file
98+
99+
.yarn-integrity
100+
101+
# dotenv environment variable files
102+
103+
.env
104+
.env.development.local
105+
.env.test.local
106+
.env.production.local
107+
.env.local
108+
109+
# parcel-bundler cache (https://parceljs.org/)
110+
111+
.parcel-cache
112+
113+
# Next.js build output
114+
115+
.next
116+
out
117+
118+
# Nuxt.js build / generate output
119+
120+
.nuxt
121+
dist
122+
123+
# Gatsby files
124+
125+
# Comment in the public line in if your project uses Gatsby and not Next.js
126+
127+
# https://nextjs.org/blog/next-9-1#public-directory-support
128+
129+
# public
130+
131+
# vuepress build output
132+
133+
.vuepress/dist
134+
135+
# vuepress v2.x temp and cache directory
136+
137+
.temp
138+
139+
# Docusaurus cache and generated files
140+
141+
.docusaurus
142+
143+
# Serverless directories
144+
145+
.serverless/
146+
147+
# FuseBox cache
148+
149+
.fusebox/
150+
151+
# DynamoDB Local files
152+
153+
.dynamodb/
154+
155+
# TernJS port file
156+
157+
.tern-port
158+
159+
# Stores VSCode versions used for testing VSCode extensions
160+
161+
.vscode-test
162+
163+
# yarn v2
164+
165+
.yarn/cache
166+
.yarn/unplugged
167+
.yarn/build-state.yml
168+
.yarn/install-state.gz
169+
.pnp.*
170+
171+
# IntelliJ based IDEs
172+
.idea
173+
174+
# Finder (MacOS) folder config
175+
.DS_Store

bun.lockb

3.05 KB
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

creators.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "blobs",
3+
"module": "index.ts",
4+
"scripts": {
5+
"review": "bun scripts/review.ts"
6+
},
7+
"devDependencies": {
8+
"@types/bun": "latest"
9+
},
10+
"peerDependencies": {
11+
"typescript": "^5.0.0"
12+
},
13+
"type": "module"
14+
}

scripts/github.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
const githubToken = process.env["GITHUB_TOKEN"]!;
2+
const commitSha = process.env["COMMIT_SHA"]!;
3+
const pullRequestNumber = process.env["PR_NUMBER"]!;
4+
5+
async function requestGithub(
6+
url: string,
7+
body: any,
8+
method?: "POST" | "DELETE"
9+
) {
10+
await fetch(`https://api.github.com/repos/Hyro-Blobs/blobs/${url}`, {
11+
method: method || "POST",
12+
headers: {
13+
Accept: "application/vnd.github+json",
14+
Authorization: `token ${githubToken}`,
15+
},
16+
body: JSON.stringify(body),
17+
});
18+
}
19+
20+
type ReviewEvent = "APPROVE" | "REQUEST_CHANGES";
21+
22+
type ReviewData = {
23+
commit_id: string;
24+
event: ReviewEvent;
25+
body?: string;
26+
};
27+
28+
async function requestReviewers(reviewers: string[]) {
29+
await requestGithub(`pulls/${pullRequestNumber}/requested_reviewers`, {
30+
reviewers,
31+
});
32+
}
33+
34+
async function createReview(event: ReviewEvent, body?: string) {
35+
const data: ReviewData = {
36+
commit_id: commitSha,
37+
event: event,
38+
};
39+
40+
if (body) {
41+
data.body = body;
42+
}
43+
44+
await requestGithub(`pulls/${pullRequestNumber}/reviews`, data, "POST");
45+
}
46+
47+
async function addLabels(labels: string[]) {
48+
await requestGithub(`issues/${pullRequestNumber}/labels`, labels);
49+
}
50+
51+
async function removeLabel(label: string) {
52+
await requestGithub(
53+
`issues/${pullRequestNumber}/labels/${label}`,
54+
{},
55+
"DELETE"
56+
);
57+
}
58+
59+
async function getBody() {
60+
const response = await fetch(
61+
`https://api.github.com/repos/Hyro-Blobs/blobs/pulls/${pullRequestNumber}`,
62+
{
63+
headers: {
64+
Accept: "application/vnd.github+json",
65+
Authorization: `token ${githubToken}`,
66+
},
67+
}
68+
);
69+
const data = (await response.json()) as { body: string };
70+
return data.body;
71+
}
72+
73+
export { requestReviewers, createReview, addLabels, removeLabel, getBody };

0 commit comments

Comments
 (0)