Skip to content

Commit 919487b

Browse files
authored
fix: specify the repository when searching for pull requests (#1986)
1 parent 9bef458 commit 919487b

File tree

4 files changed

+8
-3
lines changed

4 files changed

+8
-3
lines changed

internal/automation/repositories.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ type RepositoriesConfig struct {
4545
Repositories []*RepositoryConfig `yaml:"repositories"`
4646
}
4747

48-
// GitURL returns the full git url to clone.
48+
// GitURL returns the full git url to clone. If full name is not available,
49+
// it defaults to "https://github.com/googleapis/<name>".
4950
func (c *RepositoryConfig) GitURL() (string, error) {
5051
if c.FullName == "" {
5152
if c.Name == "" {

internal/automation/trigger.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"iter"
2222
"log/slog"
2323
"os"
24+
"strings"
2425

2526
cloudbuild "cloud.google.com/go/cloudbuild/apiv1/v2"
2627
"cloud.google.com/go/cloudbuild/apiv1/v2/cloudbuildpb"
@@ -113,7 +114,9 @@ func runCommandWithConfig(ctx context.Context, client CloudBuildClient, ghClient
113114
"_PUSH": fmt.Sprintf("%v", push),
114115
}
115116
if command == "publish-release" {
116-
prs, err := ghClient.FindMergedPullRequestsWithPendingReleaseLabel(ctx, "googleapis", repository.Name)
117+
parts := strings.Split(gitUrl, "/")
118+
repositoryOwner := parts[len(parts)-2]
119+
prs, err := ghClient.FindMergedPullRequestsWithPendingReleaseLabel(ctx, repositoryOwner, repository.Name)
117120
if err != nil {
118121
slog.Error("Error finding merged pull requests for publish-release", slog.Any("err", err), slog.String("repository", repository.Name))
119122
errs = append(errs, err)

internal/github/github.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ func (c *Client) SearchPullRequests(ctx context.Context, query string) ([]*PullR
228228
opts := &github.SearchOptions{
229229
ListOptions: github.ListOptions{PerPage: 100},
230230
}
231+
query = fmt.Sprintf("repo:%s/%s %s", c.repo.Owner, c.repo.Name, query)
231232
for {
232233
result, resp, err := c.Search.Issues(ctx, query, opts)
233234
if err != nil {

internal/github/github_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ func TestSearchPullRequests(t *testing.T) {
704704
query: "is:pr is:open author:app/dependabot",
705705
handler: func(w http.ResponseWriter, r *http.Request) {
706706
if strings.HasPrefix(r.URL.Path, "/search/issues") {
707-
if r.URL.Query().Get("q") != "is:pr is:open author:app/dependabot" {
707+
if r.URL.Query().Get("q") != "repo:owner/repo is:pr is:open author:app/dependabot" {
708708
t.Errorf("unexpected query: got %q", r.URL.Query().Get("q"))
709709
}
710710
fmt.Fprint(w, `{"items": [{"number": 1, "pull_request": {}}]}`)

0 commit comments

Comments
 (0)