Skip to content

Commit

Permalink
add: project commits included in (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
Seizens authored Sep 6, 2022
1 parent b678d1c commit f645b08
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
19 changes: 19 additions & 0 deletions projects_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,25 @@ func (s *ProjectsService) GetCommit(projectName, commitID string) (*CommitInfo,
return v, resp, err
}

// GetIncludeIn Retrieves the branches and tags in which a change is included.
// Branches that are not visible to the calling user according to the project’s read permissions are filtered out from the result.
//
// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-projects.html#get-included-in
func (s *ProjectsService) GetIncludeIn(projectName, commitID string) (*IncludedInInfo, *Response, error) {
u := fmt.Sprintf("projects/%s/commits/%s/in", url.QueryEscape((projectName)), commitID)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
v := new(IncludedInInfo)
resp, err := s.client.Do(req, v)
if err != nil {
return nil, resp, err
}

return v, resp, err
}

// GetCommitContent gets the content of a file from a certain commit.
// The content is returned as base64 encoded string.
//
Expand Down
39 changes: 39 additions & 0 deletions projects_commit_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package gerrit_test

import (
"fmt"
"net/http"
"reflect"
"testing"

"github.com/andygrunwald/go-gerrit"
)

// +func (s *ProjectsService) GetIncludeIn(projectName, commitID string) (*IncludedInInfo, *Response, error){
func TestProjectsService_GetIncludeIn(t *testing.T) {
setup()
defer teardown()

testMux.HandleFunc("/projects/swift/commits/a8a477efffbbf3b44169bb9a1d3a334cbbd9aa96/in", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `)]}'`+"\n"+`{"branches": ["master"],"tags": ["1.1.0"]}`)
})

includedInInfo, _, err := testClient.Projects.GetIncludeIn("swift", "a8a477efffbbf3b44169bb9a1d3a334cbbd9aa96")
if err != nil {
t.Errorf("Projects.GetIncludeIn returned error: %v", err)
}

want := &gerrit.IncludedInInfo{
Branches: []string{
"master",
},
Tags: []string{
"1.1.0",
},
}

if !reflect.DeepEqual(includedInInfo, want) {
t.Errorf("Projects.GetIncludeIn returned %+v, want %+v", includedInInfo, want)
}
}

0 comments on commit f645b08

Please sign in to comment.