Skip to content
This repository has been archived by the owner on Dec 9, 2020. It is now read-only.

Commit

Permalink
Merge pull request #6 from babbel/errors-improvement
Browse files Browse the repository at this point in the history
Improved error and made client pass to be a reference
  • Loading branch information
Kirill Zonov committed May 10, 2019
2 parents afc646d + 78cd81e commit 32de526
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion codeclimate/data_source_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func dataSourceRepository() *schema.Resource {
func dataSourceRepositoryRead(d *schema.ResourceData, client interface{}) error {
repositorySlug := d.Get("repository_slug").(string)

c := client.(codeclimateclient.Client)
c := client.(*codeclimateclient.Client)
repository, err := c.GetRepository(repositorySlug)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion codeclimate/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ func configureProvider(d *schema.ResourceData) (interface{}, error) {
BaseUrl: codeClimateApiHost,
}

return client, nil
return &client, nil
}
9 changes: 8 additions & 1 deletion codeclimateclient/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@ func (client *Client) GetRepository(repositorySlug string) (*Repository, error)
return nil, err
}

// TODO: check size of data
numberOfReposFound := len(repositoryData.Data)

if numberOfReposFound != 1 {
return nil, fmt.Errorf(
"The response for %s returned %v repositories (should have been 1)",
repositorySlug, numberOfReposFound,
)
}

repository := &Repository{
Id: repositoryData.Data[0].ID,
Expand Down

0 comments on commit 32de526

Please sign in to comment.