forked from LangChain-OpenTutorial/LangChain-OpenTutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
83 lines (77 loc) · 2.9 KB
/
pr-age.yml
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
name: pr-age
on:
schedule:
- cron: '30 0,3,9,15 * * *'
pull_request:
types: [opened, synchronize, reopened]
workflow_dispatch:
permissions:
pull-requests: write
checks: write
contents: read
jobs:
check-pr-age:
runs-on: ubuntu-latest
if: github.repository == 'LangChain-OpenTutorial/LangChain-OpenTutorial' # 원본 레포에서만 실행
steps:
- name: Check if 24 hours have passed since PR creation
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// Function to check PR age
async function checkPrAge(pr) {
const createdAt = new Date(pr.created_at);
const now = new Date();
const diffHours = (now - createdAt) / (1000 * 60 * 60);
if (diffHours >= 24) {
console.log(`PR #${pr.number} is older than 24 hours. Merge allowed.`);
await github.rest.checks.create({
owner: context.repo.owner,
repo: context.repo.repo,
name: 'check-pr-age',
head_sha: pr.head.sha,
status: 'completed',
conclusion: 'success',
output: {
title: 'check-pr-age',
summary: `PR #${pr.number} is older than 24 hours.`,
},
});
} else {
const hoursLeft = (24 - diffHours).toFixed(2);
console.log(`PR #${pr.number} is not yet older than 24 hours. Left ${hoursLeft} hours.`);
await github.rest.checks.create({
owner: context.repo.owner,
repo: context.repo.repo,
name: 'check-pr-age',
head_sha: pr.head.sha,
status: 'completed',
conclusion: 'failure',
output: {
title: 'check-pr-age',
summary: `PR #${pr.number} is not yet older than 24 hours. Please wait another ${hoursLeft} hours.`,
},
});
}
}
// Check if it's a scheduled event
const isScheduled = !context.payload.pull_request;
if (isScheduled) {
const { data: pullRequests } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
per_page: 100,
});
for (const pr of pullRequests) {
await checkPrAge(pr);
}
} else {
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number,
});
await checkPrAge(pr.data);
}