From 8639915182bb286d9962f8f0e0a9b02832e46830 Mon Sep 17 00:00:00 2001 From: "Dat. Ba Dao" Date: Wed, 7 Aug 2024 21:37:35 +0700 Subject: [PATCH] atlasaction/orb: fetch github PRs with owner (#192) --- atlasaction/circleci_action.go | 10 ++++++++-- atlasaction/circleci_action_test.go | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/atlasaction/circleci_action.go b/atlasaction/circleci_action.go index 5b8b113a..0181bc41 100644 --- a/atlasaction/circleci_action.go +++ b/atlasaction/circleci_action.go @@ -143,12 +143,18 @@ func getGHPR(repo, branch string) (*PullRequest, error) { }, Timeout: time.Second * 30, } - // get open pull requests for the branch. + // Extract owner and repo from the GITHUB_REPOSITORY. + s := strings.Split(repo, "/") + if len(s) != 2 { + return nil, fmt.Errorf("GITHUB_REPOSITORY must be in the format of 'owner/repo'") + } + // Get open pull requests for the branch. + head := fmt.Sprintf("%s:%s", s[0], branch) req, err := client.Get( fmt.Sprintf("%s/repos/%s/pulls?state=open&head=%s&sort=created&direction=desc&per_page=1&page=1", defaultGHApiUrl, repo, - branch)) + head)) if err != nil { return nil, err } diff --git a/atlasaction/circleci_action_test.go b/atlasaction/circleci_action_test.go index a3cb4578..156c1eec 100644 --- a/atlasaction/circleci_action_test.go +++ b/atlasaction/circleci_action_test.go @@ -30,7 +30,7 @@ func Test_circleCIOrb_GetTriggerContext(t *testing.T) { server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { require.Equal(t, "/repos/ariga/atlas-orb/pulls", r.URL.Path) require.Equal(t, "GET", r.Method) - require.Equal(t, "state=open&head=main&sort=created&direction=desc&per_page=1&page=1", r.URL.RawQuery) + require.Equal(t, "state=open&head=ariga:main&sort=created&direction=desc&per_page=1&page=1", r.URL.RawQuery) w.Write([]byte(` [ {"number":1,"url":"https://api.github.com/repos/ariga/atlas-orb/pulls/9","head":{"sha":"1234567890"}},