Skip to content
This repository was archived by the owner on Oct 17, 2023. It is now read-only.

Commit c66f5b5

Browse files
committed
initial commit
0 parents  commit c66f5b5

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const axios = require('axios');
2+
const fs = require('fs');
3+
4+
const PR_NUMBER = process.env.GITHUB_EVENT_PATH ? JSON.parse(fs.readFileSync(process.env.GITHUB_EVENT_PATH, 'utf8')).number : null;
5+
const REPO = process.env.GITHUB_REPOSITORY;
6+
7+
console.log(`https://api.github.com/repos/${REPO}/pulls/${PR_NUMBER}/files`);
8+
9+
axios.get(`https://api.github.com/repos/${REPO}/pulls/${PR_NUMBER}/files`, {})
10+
.then(response => {
11+
const files = response.data;
12+
const root_directories = new Set();
13+
14+
files.forEach(file => {
15+
const root_directory = file.filename.split("/")[0];
16+
root_directories.add(root_directory);
17+
});
18+
19+
if (root_directories.size > 1) {
20+
throw new Error("Multiple root directories changed, action failed.");
21+
}
22+
23+
const root_dir = [...root_directories][0];
24+
console.log(`::set-output name=root_directory::${root_dir}`);
25+
})
26+
.catch(error => {
27+
console.error(error.message || 'Error occurred');
28+
process.exit(1);
29+
});

.github/workflows/check-pr.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Check PR Requirements
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
check-pr:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout code
11+
uses: actions/checkout@v4
12+
13+
- name: Install Node.js
14+
uses: actions/setup-node@v2
15+
with:
16+
node-version: '14'
17+
18+
- name: Install dependencies
19+
run: |
20+
npm install axios
21+
22+
- name: Get root directory
23+
run: node .github/scripts/get_root_directories.js
24+
id: get-dir

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.idea
2+
3+
**/node_modules/

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# frontend_2023_freshman_task
2+
3+
2023 杭助前端招新小任务提交仓库
4+
5+
- fork本仓库
6+
- git clone 你 fork 出来的仓库
7+
- 在仓库根目录下新建一个和你 github 用户名同名的文件夹
8+
- 在此文件夹内,放入你的代码
9+
- 提交 Pull request
10+
- github action通过后,即为提交成功

0 commit comments

Comments
 (0)