Skip to content

Commit 31e3ef3

Browse files
authored
fix: change merge PR check condition to use merge_at field (#1959)
If the PR is merged, then the `merged_at` field has value. Otherwise it is a closed PR, and the `merged_at` field is null. Test Example: In my forked repo, only catchyzheng/google-cloud-python#4 is closed PR, and its `merged_at` field is null. Other PRs were merged and has `merged_at` values. The `merged_at` field can be checked here: https://api.github.com/repos/catchyzheng/google-cloud-python/pulls?per_page=100&state=closed
1 parent f890a37 commit 31e3ef3

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

internal/github/github.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ func (c *Client) FindMergedPullRequestsWithPendingReleaseLabel(ctx context.Conte
300300
return nil, err
301301
}
302302
for _, pr := range prs {
303-
if (pr.GetMerged() || pr.GetMergeCommitSHA() != "") && hasLabel(pr, "release:pending") {
303+
if !pr.GetMergedAt().IsZero() && hasLabel(pr, "release:pending") {
304304
allPRs = append(allPRs, pr)
305305
}
306306
}

internal/github/github_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"net/url"
2424
"strings"
2525
"testing"
26+
"time"
2627

2728
"github.com/go-git/go-git/v5"
2829
gogitConfig "github.com/go-git/go-git/v5/config"
@@ -1026,10 +1027,10 @@ func TestFindMergedPullRequestsWithPendingReleaseLabel(t *testing.T) {
10261027
if r.URL.Query().Get("state") != "closed" {
10271028
t.Errorf("unexpected state: got %q", r.URL.Query().Get("state"))
10281029
}
1029-
pr0 := github.PullRequest{Number: github.Ptr(0), HTMLURL: github.Ptr("https://github.com/owner/repo/pull/0"), MergeCommitSHA: github.Ptr("sha456"), Labels: []*github.Label{{Name: github.Ptr("release:pending")}}}
1030+
pr0 := github.PullRequest{Number: github.Ptr(0), HTMLURL: github.Ptr("https://github.com/owner/repo/pull/0"), MergedAt: &github.Timestamp{Time: time.Date(2025, time.September, 5, 20, 44, 59, 0, time.UTC)}, Labels: []*github.Label{{Name: github.Ptr("release:pending")}}}
10301031
pr1 := github.PullRequest{Number: github.Ptr(1), Labels: []*github.Label{{Name: github.Ptr("release:pending")}}}
10311032
pr2 := github.PullRequest{Number: github.Ptr(2), Labels: []*github.Label{{Name: github.Ptr("other-label")}}}
1032-
pr3 := github.PullRequest{Number: github.Ptr(3), HTMLURL: github.Ptr("https://github.com/owner/repo/pull/3"), MergeCommitSHA: github.Ptr("sha123"), Merged: github.Ptr(true), Labels: []*github.Label{{Name: github.Ptr("release:pending")}}}
1033+
pr3 := github.PullRequest{Number: github.Ptr(3), HTMLURL: github.Ptr("https://github.com/owner/repo/pull/3"), ClosedAt: &github.Timestamp{Time: time.Date(2025, time.September, 5, 20, 44, 59, 0, time.UTC)}, Labels: []*github.Label{{Name: github.Ptr("release:pending")}}}
10331034
prs := []*github.PullRequest{&pr0, &pr1, &pr2, &pr3}
10341035
b, err := json.Marshal(prs)
10351036
if err != nil {
@@ -1038,8 +1039,7 @@ func TestFindMergedPullRequestsWithPendingReleaseLabel(t *testing.T) {
10381039
fmt.Fprint(w, string(b))
10391040
},
10401041
wantPRs: []*PullRequest{
1041-
{Number: github.Ptr(0), HTMLURL: github.Ptr("https://github.com/owner/repo/pull/0"), MergeCommitSHA: github.Ptr("sha456"), Labels: []*github.Label{{Name: github.Ptr("release:pending")}}},
1042-
{Number: github.Ptr(3), HTMLURL: github.Ptr("https://github.com/owner/repo/pull/3"), MergeCommitSHA: github.Ptr("sha123"), Merged: github.Ptr(true), Labels: []*github.Label{{Name: github.Ptr("release:pending")}}},
1042+
{Number: github.Ptr(0), HTMLURL: github.Ptr("https://github.com/owner/repo/pull/0"), MergedAt: &github.Timestamp{Time: time.Date(2025, time.September, 5, 20, 44, 59, 0, time.UTC)}, Labels: []*github.Label{{Name: github.Ptr("release:pending")}}},
10431043
},
10441044
},
10451045
{

0 commit comments

Comments
 (0)