Skip to content

Commit 3951fbb

Browse files
committed
add additional debug logging
1 parent 04a1ce0 commit 3951fbb

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

backport/main.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"context"
55
"errors"
6+
"fmt"
67
"log/slog"
78
"os"
89
"strings"
@@ -57,14 +58,15 @@ func main() {
5758
panic("token can not be empty")
5859
}
5960

60-
prInfo, err := GetBackportPrInfo(ctx, client, ghctx)
61+
prInfo, err := GetBackportPrInfo(ctx, log, client, ghctx)
6162
if err != nil {
6263
log.Error("error getting PR info", "error", err)
6364
panic(err)
6465
}
6566

66-
log = log.With("pull_request", prInfo.Pr.Number)
67-
branches, err := ghutil.GetReleaseBranches(ctx, client.Repositories, prInfo.RepoOwner, prInfo.RepoName)
67+
log = log.With("repo", fmt.Sprintf("%s/%s", prInfo.RepoOwner, prInfo.RepoName), "pull_request", prInfo.Pr.GetNumber())
68+
69+
branches, err := ghutil.GetReleaseBranches(ctx, log, client.Repositories, prInfo.RepoOwner, prInfo.RepoName)
6870
if err != nil {
6971
log.Error("error getting branches", "error", err)
7072
panic(err)
@@ -101,7 +103,8 @@ func main() {
101103
MergeBase: mergeBase,
102104
}
103105

104-
prOut, err := Backport(ctx, log, client.PullRequests, client.Issues, client.Issues, NewShellCommandRunner(log), opts)
106+
commandRunner := NewShellCommandRunner(log)
107+
prOut, err := Backport(ctx, log, client.PullRequests, client.Issues, client.Issues, commandRunner, opts)
105108
if err != nil {
106109
log.Error("backport failed", "error", err)
107110
continue

backport/pr_info.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"context"
55
"fmt"
6+
"log/slog"
67
"os"
78
"strconv"
89

@@ -22,20 +23,23 @@ type PrInfo struct {
2223
RepoName string
2324
}
2425

25-
func GetBackportPrInfo(ctx context.Context, client *github.Client, ghctx *githubactions.GitHubContext) (PrInfo, error) {
26+
func GetBackportPrInfo(ctx context.Context, log *slog.Logger, client *github.Client, ghctx *githubactions.GitHubContext) (PrInfo, error) {
2627
prLabel := os.Getenv("PR_LABEL")
2728
prNumber, _ := strconv.Atoi(os.Getenv("PR_NUMBER"))
2829
repoOwner := os.Getenv("REPO_OWNER")
2930
repoName := os.Getenv("REPO_NAME")
3031

32+
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)
33+
3134
// First, try to use the API to get the PR info
3235
if prNumber != 0 && repoOwner != "" && repoName != "" {
36+
log.Debug("getting PR info from API")
3337
return getFromApi(ctx, client, prLabel, repoOwner, repoName, prNumber)
3438
}
3539

3640
// Try to use event data if present
37-
eventPath := ghctx.EventPath
38-
if eventPath != "" {
41+
if ghctx.EventPath != "" {
42+
log.Debug("getting PR info from event")
3943
return getFromEvent(ghctx)
4044
}
4145

pkg/ghutil/release_branches.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package ghutil
33
import (
44
"context"
55
"errors"
6+
"log/slog"
67
"slices"
78
"strconv"
89
"strings"
@@ -92,14 +93,15 @@ func MajorMinorPatch(v string) (string, string, string) {
9293
return groups["major"], groups["minor"], groups["patch"]
9394
}
9495

95-
func GetReleaseBranches(ctx context.Context, client BranchClient, owner, repo string) ([]*github.Branch, error) {
96+
func GetReleaseBranches(ctx context.Context, log *slog.Logger, client BranchClient, owner, repo string) ([]*github.Branch, error) {
9697
var (
9798
page int
9899
count = 50
99100
branches = []*github.Branch{}
100101
)
101102

102103
for {
104+
log.Debug("listing branches", "page", page, "count", count)
103105
b, r, err := client.ListBranches(ctx, owner, repo, &github.BranchListOptions{
104106
Protected: github.Bool(true),
105107
ListOptions: github.ListOptions{

0 commit comments

Comments
 (0)