diff --git a/gitea/repo.go b/gitea/repo.go index 67bd956..0d36571 100644 --- a/gitea/repo.go +++ b/gitea/repo.go @@ -382,6 +382,13 @@ func (c *Client) GetRepo(owner, reponame string) (*Repository, *Response, error) 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 type EditRepoOption struct { // name of the repository diff --git a/gitea/repo_test.go b/gitea/repo_test.go index e5eedc7..ee9c396 100644 --- a/gitea/repo_test.go +++ b/gitea/repo_test.go @@ -157,6 +157,20 @@ func TestGetArchiveReader(t *testing.T) { 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 func createTestRepo(t *testing.T, name string, c *Client) (*Repository, error) { user, _, uErr := c.GetMyUserInfo()