diff --git a/README.md b/README.md index 9e5497c..b65cf17 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ steps: fail-on-denial: true additional-approved-words: '' additional-denied-words: '' + polling-interval-seconds: 10 ``` * `approvers` is a comma-delimited list of all required approvers. An approver can either be a user or an org team. (*Note: Required approvers must have the ability to be set as approvers in the repository. If you add an approver that doesn't have this permission then you would receive an HTTP/402 Validation Failed error when running this action*) @@ -65,6 +66,7 @@ steps: * `fail-on-denial` is a boolean that indicates if the workflow should fail if any approver denies the approval. This is optional and defaults to `true`. Set this to `false` to allow the workflow to continue if any approver denies the approval. * `additional-approved-words` is a comma separated list of strings to expand the dictionary of words that indicate approval. This is optional and defaults to an empty string. * `additional-denied-words` is a comma separated list of strings to expand the dictionary of words that indicate denial. This is optional and defaults to an empty string. +* `polling-interval-seconds` is an integer that sets the number of seconds to wait between polling the GitHub API for approval status. This is optional and defaults to `10` seconds. Increase this value if you want to reduce API calls, or decrease it for faster response times. > [!Note] > 1. If You are using issue-body-file-path then please make sure the file is reachable; for example, if the file is in your repo, then please checkout to your repo in the same job as the approval issue. diff --git a/action.yaml b/action.yaml index a8b661b..cdbf793 100644 --- a/action.yaml +++ b/action.yaml @@ -44,6 +44,10 @@ inputs: description: Whether or not to fail the workflow if the approval is denied required: false default: 'true' + polling-interval-seconds: + description: Number of seconds to wait between polling GitHub API for approval status + required: false + default: '10' outputs: issue-number: description: The number of the issue created diff --git a/constants.go b/constants.go index 88867e3..69c509e 100644 --- a/constants.go +++ b/constants.go @@ -7,7 +7,7 @@ import ( ) const ( - pollingInterval time.Duration = 10 * time.Second + defaultPollingInterval time.Duration = 10 * time.Second envVarRepoFullName string = "GITHUB_REPOSITORY" envVarRunID string = "GITHUB_RUN_ID" @@ -25,6 +25,7 @@ const ( envVarFailOnDenial string = "INPUT_FAIL-ON-DENIAL" envVarTargetRepoOwner string = "INPUT_TARGET-REPOSITORY-OWNER" envVarTargetRepo string = "INPUT_TARGET-REPOSITORY" + envVarPollingIntervalSeconds string = "INPUT_POLLING-INTERVAL-SECONDS" ) var ( diff --git a/main.go b/main.go index e18a395..89305fd 100644 --- a/main.go +++ b/main.go @@ -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: