Skip to content

Commit 4d2db9b

Browse files
authored
fix: add MergeCommitSHA check, _PR substitution, PR limit in publish-release automation command (#1833)
add MergeCommitSHA check, _PR substitution, PR limit in publish-release automation command #1786 #1810
1 parent 8f1f5c9 commit 4d2db9b

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

internal/automation/trigger.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ func runCommandWithConfig(ctx context.Context, client CloudBuildClient, ghClient
122122
if len(prs) == 0 {
123123
slog.Info("No pull requests with label 'release:pending' found. Skipping 'publish-release' trigger.", slog.String("repository", repository.Name))
124124
continue
125+
} else {
126+
substitutions["_PR"] = fmt.Sprintf("%v", prs[0].GetHTMLURL())
125127
}
126128
} else if command == "generate" {
127129
// only pass _BUILD to generate trigger

internal/automation/trigger_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func TestRunCommandWithClient(t *testing.T) {
126126
Id: "publish-release-trigger-id",
127127
},
128128
},
129-
ghPRs: []*github.PullRequest{{}},
129+
ghPRs: []*github.PullRequest{{HTMLURL: github.Ptr("https://github.com/googleapis/librarian/pull/1")}},
130130
},
131131
{
132132
name: "skips publish-release with no PRs",

internal/github/github.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,11 @@ func (c *Client) FindMergedPullRequestsWithPendingReleaseLabel(ctx context.Conte
270270
return nil, err
271271
}
272272
for _, pr := range prs {
273-
if pr.GetMerged() && hasLabel(pr, "release:pending") {
273+
if (pr.GetMerged() || pr.GetMergeCommitSHA() != "") && hasLabel(pr, "release:pending") {
274274
allPRs = append(allPRs, pr)
275275
}
276276
}
277-
if resp.NextPage == 0 {
277+
if resp.NextPage == 0 || len(allPRs) >= 10 {
278278
break
279279
}
280280
opt.Page = resp.NextPage

internal/github/github_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -950,18 +950,20 @@ func TestFindMergedPullRequestsWithPendingReleaseLabel(t *testing.T) {
950950
if r.URL.Query().Get("state") != "closed" {
951951
t.Errorf("unexpected state: got %q", r.URL.Query().Get("state"))
952952
}
953+
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")}}}
953954
pr1 := github.PullRequest{Number: github.Ptr(1), Labels: []*github.Label{{Name: github.Ptr("release:pending")}}}
954955
pr2 := github.PullRequest{Number: github.Ptr(2), Labels: []*github.Label{{Name: github.Ptr("other-label")}}}
955-
pr3 := github.PullRequest{Number: github.Ptr(4), Merged: github.Ptr(true), Labels: []*github.Label{{Name: github.Ptr("release:pending")}}}
956-
prs := []*github.PullRequest{&pr1, &pr2, &pr3}
956+
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")}}}
957+
prs := []*github.PullRequest{&pr0, &pr1, &pr2, &pr3}
957958
b, err := json.Marshal(prs)
958959
if err != nil {
959960
t.Fatalf("json.Marshal() failed: %v", err)
960961
}
961962
fmt.Fprint(w, string(b))
962963
},
963964
wantPRs: []*PullRequest{
964-
{Number: github.Ptr(4), Merged: github.Ptr(true), Labels: []*github.Label{{Name: github.Ptr("release:pending")}}},
965+
{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")}}},
966+
{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")}}},
965967
},
966968
},
967969
{

0 commit comments

Comments
 (0)