Add GetRepoByID #511

Merged
6543 merged 1 commits from J0Nes90/go-sdk:J0Nes90/get_repo_by_id into master 2021-04-03 16:35:19 +00:00
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
}
// 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

View File

@ -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)
6543 marked this conversation as resolved Outdated
Outdated
Review
-	
+
```diff - + ```
repo, _, err := c.GetRepoByID(testrepo.ID)
assert.NoError(t, err)
assert.NotNil(t, repo)
6543 marked this conversation as resolved Outdated
Outdated
Review

can you add assert.EqualValues(t, testrepo.ID, repo.ID) - just to make sure it do what is expected

@J0Nes90

can you add `assert.EqualValues(t, testrepo.ID, repo.ID)` - just to make sure it do what is expected @J0Nes90
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()