Skip to content

Commit 95d01a6

Browse files
committed
move env vars up into main
1 parent 693a88e commit 95d01a6

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

backport/main.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"log/slog"
88
"os"
9+
"strconv"
910
"strings"
1011

1112
"github.com/google/go-github/v50/github"
@@ -52,13 +53,19 @@ func main() {
5253
token = os.Getenv("GITHUB_TOKEN")
5354
client = github.NewTokenClient(ctx, token)
5455
inputs = GetInputs()
56+
57+
// If specified, takes precedence over event data
58+
repoOwner = os.Getenv("REPO_OWNER")
59+
repoName = os.Getenv("REPO_NAME")
60+
prNumber, _ = strconv.Atoi(os.Getenv("PR_NUMBER"))
61+
prLabel = os.Getenv("PR_LABEL")
5562
)
5663

5764
if token == "" {
5865
panic("token can not be empty")
5966
}
6067

61-
prInfo, err := GetBackportPrInfo(ctx, log, client, ghctx)
68+
prInfo, err := GetBackportPrInfo(ctx, log, client, ghctx, repoOwner, repoName, prNumber, prLabel)
6269
if err != nil {
6370
log.Error("error getting PR info", "error", err)
6471
panic(err)

backport/pr_info.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import (
44
"context"
55
"fmt"
66
"log/slog"
7-
"os"
8-
"strconv"
97

108
"github.com/google/go-github/v50/github"
119
"github.com/sethvargo/go-githubactions"
@@ -23,21 +21,16 @@ type PrInfo struct {
2321
RepoName string
2422
}
2523

26-
func GetBackportPrInfo(ctx context.Context, log *slog.Logger, client *github.Client, ghctx *githubactions.GitHubContext) (PrInfo, error) {
27-
prLabel := os.Getenv("PR_LABEL")
28-
prNumber, _ := strconv.Atoi(os.Getenv("PR_NUMBER"))
29-
repoOwner := os.Getenv("REPO_OWNER")
30-
repoName := os.Getenv("REPO_NAME")
31-
24+
func GetBackportPrInfo(ctx context.Context, log *slog.Logger, client *github.Client, ghctx *githubactions.GitHubContext, repoOwner string, repoName string, prNumber int, prLabel string) (PrInfo, error) {
3225
log.Debug("getting PR info", "event_path", ghctx.EventPath, "env_pr_label", prLabel, "env_pr_number", prNumber, "env_repo_owner", repoOwner, "env_repo_name", repoName)
3326

34-
// First, try to use the API to get the PR info
27+
// Prefer using the env vars and API if they are set
3528
if prNumber != 0 && repoOwner != "" && repoName != "" {
3629
log.Debug("getting PR info from API")
3730
return getFromApi(ctx, client, prLabel, repoOwner, repoName, prNumber)
3831
}
3932

40-
// Try to use event data if present
33+
// Fall back to event data if present
4134
if ghctx.EventPath != "" {
4235
log.Debug("getting PR info from event")
4336
return getFromEvent(ghctx)

0 commit comments

Comments
 (0)