Add GetRepoByID (#511)

Add a function to get a repository by a given ID

Co-authored-by: Jochen Hunz <j.hunz@anchorpoint.app>
Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/511
Reviewed-by: 6543 <6543@obermui.de>
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: J0Nes90 <j0nes90@noreply.gitea.io>
Co-committed-by: J0Nes90 <j0nes90@noreply.gitea.io>
This commit is contained in:
J0Nes90 2021-04-04 00:35:19 +08:00 committed by 6543
parent 7de882b744
commit 4e4d6dd731
2 changed files with 21 additions and 0 deletions

View file

@ -382,6 +382,13 @@ func (c *Client) GetRepo(owner, reponame string) (*Repository, *Response, error)
return repo, resp, err return repo, resp, err
} }
// GetRepoByID returns information of a repository by a giver repository ID.
func (c *Client) GetRepoByID(id int64) (*Repository, *Response, error) {
repo := new(Repository)
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repositories/%d", id), nil, nil, repo)
return repo, resp, err
}
// EditRepoOption options when editing a repository's properties // EditRepoOption options when editing a repository's properties
type EditRepoOption struct { type EditRepoOption struct {
// name of the repository // name of the repository

View file

@ -157,6 +157,20 @@ func TestGetArchiveReader(t *testing.T) {
assert.EqualValues(t, nBytes, len(archive.Bytes())) assert.EqualValues(t, nBytes, len(archive.Bytes()))
} }
func TestGetRepoByID(t *testing.T) {
log.Println("== TestGetRepoByID ==")
c := newTestClient()
testrepo, _ := createTestRepo(t, "TestGetRepoByID", c)
repo, _, err := c.GetRepoByID(testrepo.ID)
assert.NoError(t, err)
assert.NotNil(t, repo)
assert.EqualValues(t, testrepo.ID, repo.ID)
_, err = c.DeleteRepo(repo.Owner.UserName, repo.Name)
assert.NoError(t, err)
}
// standard func to create a init repo for test routines // standard func to create a init repo for test routines
func createTestRepo(t *testing.T, name string, c *Client) (*Repository, error) { func createTestRepo(t *testing.T, name string, c *Client) (*Repository, error) {
user, _, uErr := c.GetMyUserInfo() user, _, uErr := c.GetMyUserInfo()