Skip to content

feat(workflow): add grace-period-minutes input to auto-close workflow - #20

Open
Sachindu-Nethmin wants to merge 5 commits into
mainfrom
feature/add-grace-period-minutes
Open

Sachindu-Nethmin wants to merge 5 commits into
mainfrom
feature/add-grace-period-minutes

Conversation

@Sachindu-Nethmin

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

Copy link
Copy Markdown
Owner

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.

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>
@Sachindu-Nethmin
Sachindu-Nethmin force-pushed the feature/add-grace-period-minutes branch from eb914ae to e54db43 Compare March 2, 2026 17:40
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant