Skip to content

Commit

Permalink
Merge branch 'LangChain-OpenTutorial:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikaPark authored Jan 1, 2025
2 parents 8b1f66e + 5ca79e4 commit 678efc9
Show file tree
Hide file tree
Showing 3 changed files with 959 additions and 14 deletions.
80 changes: 66 additions & 14 deletions .github/workflows/pr-age.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
name: pr-age

on:
schedule:
- cron: '0 0,3,9,15,21 * * *' # (KST) 0:00, 6:00, 9:00, 12:00, 18:00
- cron: '38 8 * * *' # (KST) 17:35
pull_request:
types: [opened, synchronize, reopened]
pull_request_review:
types: [submitted]

permissions:
pull-requests: read
pull-requests: write
checks: write
contents: read

jobs:
Expand All @@ -16,20 +22,66 @@ jobs:
uses: actions/github-script@v6
with:
script: |
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number,
});
// check 24-hours
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) {
// success
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 {
// fail
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.`,
},
});
}
}
// know whether sceduled event
const isScheduled = !context.payload.pull_request;
const createdAt = new Date(pr.data.created_at);
const now = new Date();
const diffHours = (now - createdAt) / (1000 * 60 * 60);
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);
}
if (diffHours >= 24) {
console.log('PR is older than 24 hours. Merge allowed.');
return;
} else {
const hoursLeft = (24 - diffHours).toFixed(2);
throw new Error(`Cannot merge PR yet. Left ${hoursLeft} hours.`);
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);
}
Loading

0 comments on commit 678efc9

Please sign in to comment.