mirror of
https://github.com/community-scripts/ProxmoxVE.git
synced 2026-02-03 20:03:25 +01:00
fix(workflow): use github-script for scheduled lock after 3 days
This commit is contained in:
92
.github/workflows/lock-issue.yaml
generated
vendored
92
.github/workflows/lock-issue.yaml
generated
vendored
@@ -1,68 +1,62 @@
|
||||
name: Lock closed issues
|
||||
|
||||
on:
|
||||
issues:
|
||||
types: [closed]
|
||||
pull_request:
|
||||
types: [closed]
|
||||
schedule:
|
||||
- cron: "0 0 * * *" # Run daily at midnight for backlog
|
||||
- cron: "0 0 * * *" # Run daily at midnight
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
issues: write
|
||||
pull-requests: write
|
||||
|
||||
concurrency:
|
||||
group: lock-threads
|
||||
|
||||
jobs:
|
||||
# Lock immediately when issue/PR is closed (new issues get comment)
|
||||
lock-on-close:
|
||||
if: github.event_name == 'issues' || github.event_name == 'pull_request'
|
||||
lock:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Lock issue/PR after close
|
||||
- name: Lock old issues and PRs
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const createdAt = new Date(context.payload.issue?.created_at || context.payload.pull_request?.created_at);
|
||||
const daysBeforeLock = 3;
|
||||
const cutoffDate = new Date('2026-01-27T00:00:00Z');
|
||||
const isNew = createdAt >= cutoffDate;
|
||||
const number = context.payload.issue?.number || context.payload.pull_request?.number;
|
||||
const isIssue = !!context.payload.issue;
|
||||
const lockDate = new Date();
|
||||
lockDate.setDate(lockDate.getDate() - daysBeforeLock);
|
||||
|
||||
// Add comment only for new issues/PRs
|
||||
if (isNew) {
|
||||
const comment = isIssue
|
||||
? 'This issue has been automatically locked. Please open a new issue for related bugs and reference this issue if needed.'
|
||||
: 'This pull request has been automatically locked. Please open a new issue for related bugs.';
|
||||
|
||||
await github.rest.issues.createComment({
|
||||
...context.repo,
|
||||
issue_number: number,
|
||||
body: comment
|
||||
});
|
||||
}
|
||||
|
||||
// Lock the issue/PR
|
||||
await github.rest.issues.lock({
|
||||
...context.repo,
|
||||
issue_number: number,
|
||||
lock_reason: 'resolved'
|
||||
// Search for closed, unlocked issues older than 3 days
|
||||
const issues = await github.rest.search.issuesAndPullRequests({
|
||||
q: `repo:${context.repo.owner}/${context.repo.repo} is:closed is:unlocked updated:<${lockDate.toISOString().split('T')[0]}`,
|
||||
per_page: 50
|
||||
});
|
||||
|
||||
# Scheduled run for backlog (old issues without comment)
|
||||
lock-backlog:
|
||||
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: dessant/lock-threads@v6
|
||||
with:
|
||||
github-token: ${{ github.token }}
|
||||
issue-inactive-days: 1
|
||||
issue-lock-reason: "resolved"
|
||||
issue-comment: ""
|
||||
pr-inactive-days: 1
|
||||
pr-lock-reason: "resolved"
|
||||
pr-comment: ""
|
||||
|
||||
console.log(`Found ${issues.data.items.length} issues/PRs to lock`);
|
||||
|
||||
for (const item of issues.data.items) {
|
||||
const createdAt = new Date(item.created_at);
|
||||
const isNew = createdAt >= cutoffDate;
|
||||
|
||||
try {
|
||||
// Add comment only for new issues (created after 2026-01-27)
|
||||
if (isNew) {
|
||||
const comment = item.pull_request
|
||||
? 'This pull request has been automatically locked. Please open a new issue for related bugs.'
|
||||
: 'This issue has been automatically locked. Please open a new issue for related bugs and reference this issue if needed.';
|
||||
|
||||
await github.rest.issues.createComment({
|
||||
...context.repo,
|
||||
issue_number: item.number,
|
||||
body: comment
|
||||
});
|
||||
}
|
||||
|
||||
// Lock the issue/PR
|
||||
await github.rest.issues.lock({
|
||||
...context.repo,
|
||||
issue_number: item.number,
|
||||
lock_reason: 'resolved'
|
||||
});
|
||||
|
||||
console.log(`Locked #${item.number} (${item.pull_request ? 'PR' : 'Issue'})`);
|
||||
} catch (error) {
|
||||
console.log(`Failed to lock #${item.number}: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user