Skip to content

Commit

Permalink
atlasaction/orb: fetch github PRs with owner (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
datdao authored Aug 7, 2024
1 parent c814dbd commit 8639915
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions atlasaction/circleci_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion atlasaction/circleci_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}},
Expand Down

0 comments on commit 8639915

Please sign in to comment.