Skip to content

Feature/add grace period minutes#94

Merged
Kavirubc merged 5 commits intosimiligh:mainfrom
Sachindu-Nethmin:feature/add-grace-period-minutes
Mar 3, 2026
Merged

Feature/add grace period minutes#94
Kavirubc merged 5 commits intosimiligh:mainfrom
Sachindu-Nethmin:feature/add-grace-period-minutes

Conversation

@Sachindu-Nethmin
Copy link
Copy Markdown
Contributor

@Sachindu-Nethmin Sachindu-Nethmin commented Mar 2, 2026

Description

Adds a grace_period_minutes workflow dispatch input to the auto-close workflow, allowing users to manually specify a grace period in minutes. Once the grace period expires, issues labelled potential-duplicate are automatically labelled duplicate and closed.

Also fixes a 403 permission error that occurred when GH_PAT was set but lacked issues:write scope — the workflow now uses the built-in github.token which already has the correct permissions via the permissions block.

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to change)
  • 📚 Documentation update
  • 🔧 Configuration/build change
  • ♻️ Refactoring (no functional changes)
  • 🧪 Test update

Related Issues

Relates to #12

Changes Made

  • Added grace_period_minutes input to workflow_dispatch in auto-close.yml — accepts a number of minutes; leave empty to use the configured default (72 h)
  • Passes --grace-period-minutes flag to the CLI when the input is set
  • Replaced secrets.GH_PAT with github.token to fix 403 errors caused by an under-scoped PAT; the workflow permissions: issues: write block already grants the built-in token everything it needs

Testing

  • I have run go build ./... successfully
  • I have run go test ./... successfully
  • I have run go vet ./... successfully
  • I have tested the changes locally

Manually triggered the workflow with grace_period_minutes=1 — issues #15 and #16 were successfully labelled duplicate and closed within seconds.

Screenshots (if applicable)

Workflow run output:

{
  "processed": 3,
  "closed": 2,
  "skipped_grace_period": 0,
  "skipped_human_activity": 1,
  "details": [
    {
      "number": 16,
      "action": "closed",
      "reason": "grace period expired, no human activity"
    },
    {
      "number": 15,
      "action": "closed",
      "reason": "grace period expired, no human activity"
    },
    {
      "number": 3,
      "action": "skipped_human",
      "reason": "human activity detected after label was applied"
    }
  ]
}

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • New and existing unit tests pass locally with my changes

Additional Notes

The grace_period_minutes input overrides the grace_period_hours value in .github/simili.yaml for that specific run only. The daily scheduled run continues to use the config file value.

Summary by CodeRabbit

  • New Features

    • Auto-close now accepts a configurable grace period (minutes) via workflow dispatch and CLI; invalid/non-numeric inputs are ignored with a warning.
  • Documentation

    • Added comprehensive guide for CLI usage, config precedence, GitHub Actions examples, and human-activity signals that prevent auto-close.
  • Tests

    • Added unit tests for grace-period precedence/expiry, CLI flag mapping, and repository flag parsing.

Sachindu-Nethmin and others added 4 commits March 2, 2026 23:10
Signed-off-by: SachinduNethmin <108050026+Sachindu-Nethmin@users.noreply.github.com>
The built-in github.token already has issues:write via the workflow
permissions block, so prefer it when GH_PAT is absent or misconfigured.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: SachinduNethmin <108050026+Sachindu-Nethmin@users.noreply.github.com>
GH_PAT is set but missing issues:write scope, causing 403 errors.
The workflow already declares permissions: issues: write, so the
built-in github.token has everything needed to close and label issues.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: SachinduNethmin <108050026+Sachindu-Nethmin@users.noreply.github.com>
Tests added:
- TestGracePeriodFromConfig: validates minutes override > hours config > 72h
  default precedence in the grace period computation logic
- TestGracePeriodMinutesExpiry: validates expiry checks across several
  minutes-based grace periods and label ages
- TestGracePeriodMinutesCLIMapping: validates that CLI flag 0/negative maps
  to 1, positive values are stored as-is, and absent flag leaves override at 0
- TestRepoFlagParsing: validates owner/repo split for valid and invalid inputs

Docs added:
- README: new simili auto-close CLI section covering flags, grace period
  precedence table, simili.yaml config, human activity signals, and
  workflow_dispatch usage example

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: SachinduNethmin <108050026+Sachindu-Nethmin@users.noreply.github.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 2, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e54db43 and c0e6d9a.

📒 Files selected for processing (1)
  • .github/workflows/auto-close.yml
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/auto-close.yml

📝 Walkthrough

Walkthrough

Adds a configurable grace-period input to the auto-close GitHub Actions workflow, switches the workflow token to github.token, wires the grace-period into the simili auto-close CLI invocation, updates README, and adds unit tests for CLI mapping and grace-period expiry logic.

Changes

Cohort / File(s) Summary
Workflow
.github/workflows/auto-close.yml
Add grace_period_minutes workflow_dispatch input, use github.token, compute GRACE_ARGS when numeric, pass --grace-period-minutes to simili auto-close.
Documentation
README.md
Document new simili auto-close feature: CLI flags, simili.yaml config (auto_close.grace_period_hours), precedence rules, human-activity signals, and workflow usage examples.
CLI tests
cmd/simili/commands/auto_close_test.go
Add tests for CLI mapping of --grace-period-minutes to GracePeriodMinutesOverride and owner/repo parsing, including edge cases (zero/negative).
Auto-closer tests
internal/steps/auto_closer_test.go
Add parameterized tests for grace-period precedence (CLI override → config → default 72h) and expiry calculations based on labeled age.

Sequence Diagram

sequenceDiagram
    actor User
    participant "GitHub Actions" as GH_Action
    participant "simili-cli" as Simili
    participant "Repository" as Repo

    User->>GH_Action: trigger workflow (optional grace_period_minutes)
    GH_Action->>GH_Action: validate/construct GRACE_ARGS
    GH_Action->>Simili: run `simili auto-close` with GRACE_ARGS
    Simili->>Repo: list issues labeled potential-duplicate
    Simili->>Simili: compute grace expiry per issue
    Simili->>Repo: if expired and no human activity -> relabel & close
    Simili-->>GH_Action: return status
    GH_Action-->>User: workflow complete
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Possibly related PRs

Suggested labels

e2e

Suggested reviewers

  • Kavirubc

Poem

🐰 A tiny hop for code, a graceful timer set,
Labels wait in silence for the deadline met,
Minutes passed or defaults kept,
The rabbit nods, the issues swept,
Hooray — automated tidy-up, no fret!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Feature/add grace period minutes' directly corresponds to the main feature addition: a new grace_period_minutes workflow input parameter for the auto-close workflow that allows manual override of the grace period.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.github/workflows/auto-close.yml:
- Around line 63-65: The workflow currently interpolates the input into
GRACE_FLAG allowing shell injection; instead, read the input into an environment
variable (e.g., GRACE_PERIOD_INPUT), validate it with a numeric regex (only
digits) and reject/ignore non-matching values, then build the kubectl/command
argument as a safe array/explicit argument (e.g., pass "--grace-period-minutes"
and the validated value as separate, quoted arguments) rather than expanding an
unquoted string in GRACE_FLAG; update handling around GRACE_FLAG and
inputs.grace_period_minutes to use the env var, the regex check, and pass the
argument safely to prevent word-splitting/command substitution.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 62b867d and e54db43.

📒 Files selected for processing (4)
  • .github/workflows/auto-close.yml
  • README.md
  • cmd/simili/commands/auto_close_test.go
  • internal/steps/auto_closer_test.go

Comment thread .github/workflows/auto-close.yml Outdated
inputs.grace_period_minutes is a free-text string that was previously
interpolated directly into the shell script body, allowing a crafted
value (e.g. "1 $(malicious)") to execute arbitrary commands.

Fix:
- Assign the input to GRACE_PERIOD_INPUT env var so it never reaches
  the script body as a template expression.
- Validate with ^[0-9]+$ before use; emit a ::warning:: and skip the
  flag if the value is non-numeric.
- Build the argument as a bash array (GRACE_ARGS) so the flag name and
  value are always passed as two separate quoted tokens, eliminating
  word-splitting and command-substitution risks.

Signed-off-by: SachinduNethmin <108050026+Sachindu-Nethmin@users.noreply.github.com>
@gh-simili-bot
Copy link
Copy Markdown
Contributor

🧪 E2E Test

Bot responded: yes

| Auto-closer (dry-run) | processed: 0 closed: 0 grace: 0 human: 0 |

Test repo → gh-simili-bot/simili-e2e-22589098648
Run → logs

Auto-generated by E2E pipeline

@Kavirubc Kavirubc merged commit 0cfc0d2 into similigh:main Mar 3, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants