Skip to content
Merged
Changes from 1 commit
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
106 changes: 106 additions & 0 deletions .github/workflows/major-decision-auto-approve.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
name: Auto-approve Pending Major Decisions

on:
schedule:
- cron: "0 3 * * *"
workflow_dispatch:

permissions:
issues: write
Comment thread
sarthakaggarwal97 marked this conversation as resolved.
pull-requests: write

concurrency:
group: major-decision-auto-approve
cancel-in-progress: false

jobs:
approve:
if: github.repository == 'valkey-io/valkey'
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Approve major decisions pending for two weeks
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const AUTO_LABEL = 'major-decision-pending-auto-approve';
const cutoff = Date.now() - 14 * 24 * 60 * 60 * 1000;
const { owner, repo } = context.repo;

const getLatestAutoLabelTime = async issueNumber => {
const events = await github.paginate(github.rest.issues.listEvents, {
owner,
repo,
issue_number: issueNumber,
per_page: 100,
});

let labeledAt = 0;
for (const event of events) {
if (event.event === 'labeled' && event.label?.name === AUTO_LABEL) {
labeledAt = Math.max(labeledAt, Date.parse(event.created_at));
}
}
return labeledAt;
};

const candidates = await github.paginate(github.rest.issues.listForRepo, {
owner,
repo,
state: 'open',
labels: AUTO_LABEL,
per_page: 100,
});

for (const candidate of candidates) {
const labeledAt = await getLatestAutoLabelTime(candidate.number);
if (!labeledAt || labeledAt > cutoff) {
core.info(`#${candidate.number} is not eligible for auto-approval yet.`);
continue;
}

// Re-read the labels in case they changed while this workflow was running.
const { data: issue } = await github.rest.issues.get({
owner,
repo,
issue_number: candidate.number,
});
const labels = new Set(issue.labels.map(label => label.name ?? label));
if (!labels.has(AUTO_LABEL)) {
Comment thread
sarthakaggarwal97 marked this conversation as resolved.
Outdated
core.info(`#${candidate.number} no longer has ${AUTO_LABEL}; skipping it.`);
continue;
}

const currentLabeledAt = await getLatestAutoLabelTime(candidate.number);
if (!currentLabeledAt || currentLabeledAt > cutoff) {
core.info(`#${candidate.number} is not eligible after re-checking ${AUTO_LABEL}.`);
continue;
}

await github.rest.issues.addLabels({
owner,
repo,
issue_number: candidate.number,
labels: ['major-decision-approved'],
});

const removeLabel = async label => {
if (!labels.has(label)) return;
try {
await github.rest.issues.removeLabel({
owner,
repo,
issue_number: candidate.number,
name: label,
});
} catch (error) {
if (error.status !== 404) throw error;
}
};

await removeLabel('major-decision-pending');
await removeLabel(AUTO_LABEL);

core.info(`Approved major decision for #${candidate.number}.`);
}
Loading