-
Notifications
You must be signed in to change notification settings - Fork 16
Feature/add grace period minutes #94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Kavirubc
merged 5 commits into
similigh:main
from
Sachindu-Nethmin:feature/add-grace-period-minutes
Mar 3, 2026
+317
−2
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
80efcd5
add grace-period-minutes
Sachindu-Nethmin 217d36e
fix(workflow): fall back to github.token when GH_PAT lacks issues scope
Sachindu-Nethmin 31d3547
fix(workflow): use built-in github.token instead of GH_PAT
Sachindu-Nethmin e54db43
test(auto-close): add grace-period-minutes tests and docs
Sachindu-Nethmin c0e6d9a
fix(workflow): prevent shell injection in grace_period_minutes input
Sachindu-Nethmin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| package commands | ||
|
|
||
| import ( | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/similigh/simili-bot/internal/core/config" | ||
| ) | ||
|
|
||
| // TestGracePeriodMinutesCLIMapping validates the flag-to-config mapping logic: | ||
| // - An explicit 0 is stored as 1 (smallest positive value, triggers instant expiry in tests). | ||
| // - Any positive value is stored as-is. | ||
| // - When the flag was not set, GracePeriodMinutesOverride remains 0 (no override). | ||
| func TestGracePeriodMinutesCLIMapping(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| flagChanged bool | ||
| flagValue int | ||
| wantOverride int | ||
| }{ | ||
| { | ||
| name: "flag not provided - no override", | ||
| flagChanged: false, | ||
| flagValue: 0, | ||
| wantOverride: 0, | ||
| }, | ||
| { | ||
| name: "flag set to 0 - stored as 1 (instant expire)", | ||
| flagChanged: true, | ||
| flagValue: 0, | ||
| wantOverride: 1, | ||
| }, | ||
| { | ||
| name: "flag set to negative - stored as 1 (instant expire)", | ||
| flagChanged: true, | ||
| flagValue: -5, | ||
| wantOverride: 1, | ||
| }, | ||
| { | ||
| name: "flag set to 1 - stored as 1", | ||
| flagChanged: true, | ||
| flagValue: 1, | ||
| wantOverride: 1, | ||
| }, | ||
| { | ||
| name: "flag set to 30 - stored as 30", | ||
| flagChanged: true, | ||
| flagValue: 30, | ||
| wantOverride: 30, | ||
| }, | ||
| { | ||
| name: "flag set to 1440 (1 day in minutes) - stored as 1440", | ||
| flagChanged: true, | ||
| flagValue: 1440, | ||
| wantOverride: 1440, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| cfg := &config.Config{} | ||
|
|
||
| // Mirrors the mapping logic in runAutoClose. | ||
| if tt.flagChanged { | ||
| if tt.flagValue <= 0 { | ||
| cfg.AutoClose.GracePeriodMinutesOverride = 1 | ||
| } else { | ||
| cfg.AutoClose.GracePeriodMinutesOverride = tt.flagValue | ||
| } | ||
| } | ||
|
|
||
| if cfg.AutoClose.GracePeriodMinutesOverride != tt.wantOverride { | ||
| t.Errorf("GracePeriodMinutesOverride = %d, want %d", | ||
| cfg.AutoClose.GracePeriodMinutesOverride, tt.wantOverride) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| // TestRepoFlagParsing validates owner/repo splitting used in runAutoClose. | ||
| func TestRepoFlagParsing(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| input string | ||
| wantOrg string | ||
| wantRepo string | ||
| wantValid bool | ||
| }{ | ||
| { | ||
| name: "valid org/repo", | ||
| input: "acme-corp/my-service", | ||
| wantOrg: "acme-corp", | ||
| wantRepo: "my-service", | ||
| wantValid: true, | ||
| }, | ||
| { | ||
| name: "valid single-word org and repo", | ||
| input: "owner/repo", | ||
| wantOrg: "owner", | ||
| wantRepo: "repo", | ||
| wantValid: true, | ||
| }, | ||
| { | ||
| name: "missing slash - invalid", | ||
| input: "ownerrepo", | ||
| wantValid: false, | ||
| }, | ||
| { | ||
| name: "empty org - invalid", | ||
| input: "/repo", | ||
| wantValid: false, | ||
| }, | ||
| { | ||
| name: "empty repo - invalid", | ||
| input: "owner/", | ||
| wantValid: false, | ||
| }, | ||
| { | ||
| name: "empty string - invalid", | ||
| input: "", | ||
| wantValid: false, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| org, repo, ok := strings.Cut(tt.input, "/") | ||
| valid := ok && org != "" && repo != "" | ||
|
|
||
| if valid != tt.wantValid { | ||
| t.Errorf("repo %q: valid=%v, want %v", tt.input, valid, tt.wantValid) | ||
| return | ||
| } | ||
| if tt.wantValid { | ||
| if org != tt.wantOrg { | ||
| t.Errorf("org = %q, want %q", org, tt.wantOrg) | ||
| } | ||
| if repo != tt.wantRepo { | ||
| t.Errorf("repo = %q, want %q", repo, tt.wantRepo) | ||
| } | ||
| } | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.