Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[github] Add new action checking PR age #4386

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .github/workflows/pr-timing-checker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Check PR Age
on:
pull_request:
types:
- synchronize
- opened
- reopened
- labeled
- unlabeled


jobs:

check_labels:
name: Check labels
runs-on: ubuntu-latest
steps:
- name: Check Labels and Age
id: check_labels_and_comment
uses: actions/github-script@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// Get PR labels
const labels = context.payload.pull_request.labels.map(label => label.name);

// Define the fast merge label
const fastMergeFlag = ['pr: fast merge'];

// Check if any label fits fast merge
const isFastMerge = labels.some(label => fastMergeFlag.includes(label));

// If regular PR (not fast merge), check PR age
if (!isFastMerge) {
const creationDate = new Date(context.payload.pull_request.created_at);
const currentDate = new Date();

// Check if the PR is more than 7 days old
const daysDiff = Math.floor((currentDate - creationDate) / (1000 * 60 * 60 * 24));

if (daysDiff < 7) {
core.setFailed("PR is less than 7 days old and it is not flagged as 'pr: fast merge'");
} else {
console.log('PR is more than 7 days old');
}
} else {
console.log("PR is flagged as 'pr: fast merge'");
}
Loading