Add configurable polling interval for GitHub API calls (#197)

- Add polling-interval-seconds input parameter to action.yaml (default: 10)
- Update polling logic to use configurable interval
- Add input validation to ensure positive values
- Update README with usage documentation

This allows users to customize how frequently the action polls GitHub API
for approval status, enabling them to reduce API calls or speed up response
times based on their needs.
This commit is contained in:
Brian Sneddon 2025-11-16 07:10:04 -09:00 committed by GitHub
parent 32d182eec2
commit 1afc677e1f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 25 additions and 3 deletions

19
main.go
View file

@ -32,7 +32,7 @@ func handleInterrupt(ctx context.Context, client *github.Client, apprv *approval
}
}
func newCommentLoopChannel(ctx context.Context, apprv *approvalEnvironment, client *github.Client) chan int {
func newCommentLoopChannel(ctx context.Context, apprv *approvalEnvironment, client *github.Client, pollingInterval time.Duration) chan int {
channel := make(chan int)
go func() {
for {
@ -198,6 +198,21 @@ func main() {
}
}
pollingInterval := defaultPollingInterval
pollingIntervalSecondsRaw := os.Getenv(envVarPollingIntervalSeconds)
if pollingIntervalSecondsRaw != "" {
pollingIntervalSeconds, err := strconv.Atoi(pollingIntervalSecondsRaw)
if err != nil {
fmt.Printf("error parsing polling interval: %v\n", err)
os.Exit(1)
}
if pollingIntervalSeconds <= 0 {
fmt.Printf("error: polling interval must be greater than 0\n")
os.Exit(1)
}
pollingInterval = time.Duration(pollingIntervalSeconds) * time.Second
}
issueTitle := os.Getenv(envVarIssueTitle)
var issueBody string
if os.Getenv(envVarIssueBodyFilePath) != "" {
@ -245,7 +260,7 @@ func main() {
killSignalChannel := make(chan os.Signal, 1)
signal.Notify(killSignalChannel, os.Interrupt)
commentLoopChannel := newCommentLoopChannel(ctx, apprv, client)
commentLoopChannel := newCommentLoopChannel(ctx, apprv, client, pollingInterval)
select {
case exitCode := <-commentLoopChannel: