mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 15:20:43 +00:00
f366f762cc
## Description:
# Issue Lifecycle Actions
Adds two GitHub Actions workflows that enforce OpenFront's
issue-lifecycle invariants. No LLM calls — only the default
`GITHUB_TOKEN`. Layer B (Claude-powered triage) will build on this
foundation.
## Summary
- **Stale closer** — daily cron. Unmilestoned issues get warned at 5
days of inactivity, auto-closed at 10. Exempt: milestoned or
`keep-open`. Bot comments don't reset the timer.
- **Assignment invariant** — event + cron backstop. You cannot assign
anyone to an unmilestoned issue. Violators are unassigned automatically
with an explanatory comment.
- **Approval label sync** — event + cron backstop. The `not-approved`
(red) and `approved` (green) labels are derived from milestone state.
These labels are *only* ever touched by this Action.
## Rollout
Both workflows ship gated by `vars.ISSUE_LIFECYCLE_DRY_RUN` (defaults to
`'true'`). They log decisions but do not mutate anything until the
maintainer flips that variable in **Settings → Variables**.
Suggested rollout:
1. Merge with dry-run on.
2. Watch the cron logs for ~1 week. Verify the action list matches
expectations.
3. Flip `ISSUE_LIFECYCLE_DRY_RUN=false` to go live.
## File layout
```
.github/workflows/
issue-lifecycle-cron.yml # daily 06:00 UTC + workflow_dispatch
issue-lifecycle-events.yml # issues: [opened, assigned, milestoned, demilestoned]
scripts/issue-lifecycle/
config.ts # labels, colors, thresholds, comment templates
github.ts # Octokit wrapper, Action applier, label idempotent-creation
rules/
approval-label-sync.ts # pure function — idempotent
assignment-invariant.ts # pure function
stale-closer.ts # async — reads comment history, filters bots
cron.ts # daily sweep orchestrator
events.ts # event-mode dispatcher
index.ts # entrypoint, CLI arg parser
README.md
```
Structure mirrors `scripts/pr-gate/` from Unit 2 — same Octokit/Action
patterns, same dry-run convention.
## Self-installing labels
On every run, the Action ensures the six labels exist (`not-approved`,
`approved`, `stale`, `keep-open`, `needs-info`, `auto-closed-stale`)
with the correct colors and descriptions. No manual setup required.
## Local testing
```bash
cd scripts/issue-lifecycle
npm install
export GITHUB_TOKEN=ghp_...
# Full cron sweep, dry-run (default for CLI):
npx tsx index.ts --mode cron
# Simulate an event:
EVENT_NAME=assigned npx tsx index.ts --mode event --issue 1234
```
CLI invocations are dry-run unless `--no-dry-run` is passed explicitly.
## Please complete the following:
- [x] I have added screenshots for all UI updates
- [x] I process any text displayed to the user through translateText()
and I've added it to the en.json file
- [x] I have added relevant tests to the test directory
## Please put your Discord username so you can be contacted if a bug or
regression is found:
evan
73 lines
2.1 KiB
TypeScript
73 lines
2.1 KiB
TypeScript
import type { Octokit } from "@octokit/rest";
|
|
import {
|
|
type Action,
|
|
applyActions,
|
|
describeAction,
|
|
iterateOpenIssues,
|
|
} from "./github";
|
|
import { syncApprovalLabel } from "./rules/approval-label-sync";
|
|
import { enforceAssignmentInvariant } from "./rules/assignment-invariant";
|
|
import { checkStale } from "./rules/stale-closer";
|
|
|
|
export async function runCron(
|
|
octokit: Octokit,
|
|
dryRun: boolean,
|
|
): Promise<void> {
|
|
const now = new Date();
|
|
let issueCount = 0;
|
|
let actedOnCount = 0;
|
|
|
|
for await (const issue of iterateOpenIssues(octokit)) {
|
|
issueCount++;
|
|
const prefix = `[issue-lifecycle] issue #${issue.number}`;
|
|
|
|
try {
|
|
const stale = await checkStale(issue, octokit, now);
|
|
if (stale.length > 0) {
|
|
logActions(`${prefix} — rule: stale-closer`, stale);
|
|
await maybeApply(octokit, issue.number, stale, dryRun, prefix);
|
|
actedOnCount++;
|
|
}
|
|
|
|
const assignment = enforceAssignmentInvariant(issue);
|
|
if (assignment.length > 0) {
|
|
logActions(`${prefix} — rule: assignment-invariant`, assignment);
|
|
await maybeApply(octokit, issue.number, assignment, dryRun, prefix);
|
|
actedOnCount++;
|
|
}
|
|
|
|
const labelSync = syncApprovalLabel(issue);
|
|
if (labelSync.length > 0) {
|
|
logActions(`${prefix} — rule: approval-label-sync`, labelSync);
|
|
await maybeApply(octokit, issue.number, labelSync, dryRun, prefix);
|
|
actedOnCount++;
|
|
}
|
|
} catch (err) {
|
|
console.error(`${prefix} — error: ${err}`);
|
|
}
|
|
}
|
|
|
|
console.log(
|
|
`[issue-lifecycle] cron sweep complete — issues scanned: ${issueCount}, rules triggered: ${actedOnCount}, dry_run: ${dryRun}`,
|
|
);
|
|
}
|
|
|
|
function logActions(prefix: string, actions: Action[]): void {
|
|
const summary = actions.map(describeAction).join(", ");
|
|
console.log(`${prefix} — actions: ${summary}`);
|
|
}
|
|
|
|
async function maybeApply(
|
|
octokit: Octokit,
|
|
issueNumber: number,
|
|
actions: Action[],
|
|
dryRun: boolean,
|
|
prefix: string,
|
|
): Promise<void> {
|
|
if (dryRun) {
|
|
console.log(`${prefix} — DRY_RUN: not applied`);
|
|
return;
|
|
}
|
|
await applyActions(octokit, issueNumber, actions);
|
|
}
|