Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Commit

Permalink
PR feedback (#6)
Browse files Browse the repository at this point in the history
* fix json structure

* cleanup comments

* missing error output
  • Loading branch information
varditn authored Sep 2, 2020
1 parent dc896ea commit 4328f84
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Currently the provider supports just retreaving the repository as data source.

```hcl
provider "codeclimate" {
api_key = "${var.api_key}"
api_key = "${var.api_key}" # Will fallback to CODECLIMATE_TOKEN environment variable if not explicitly specified.
}
data "codeclimate_repository" "test" {
Expand Down
8 changes: 8 additions & 0 deletions codeclimate/resource_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ func resourceRepositoryRead(d *schema.ResourceData, client interface{}) error {
return err
}
err = d.Set("codeclimate_id", repository.Id)
if err != nil {
return err
}
err = d.Set("repository_url", repository.RepositoryURL)
if err != nil {
return err
}
err = d.Set("organization_id", repository.Organization)
return err
}

Expand Down
3 changes: 2 additions & 1 deletion codeclimateclient/organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package codeclimateclient

import (
"encoding/json"
"fmt"
"net/http"
)

Expand Down Expand Up @@ -42,5 +43,5 @@ func (client *Client) GetOrganization(organizationName string) (*Organization, e
return organization, nil
}
}
return nil, nil
return nil, fmt.Errorf("The Organization could not be found")
}
12 changes: 12 additions & 0 deletions codeclimateclient/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ type Repository struct {
Id string
TestReporterId string
GithubSlug string
Organization string
RepositoryURL string
}

// The structure describes just what we need from the response.
Expand All @@ -21,7 +23,15 @@ type readRepositoriesResponse struct {
Attributes struct {
TestReporterID string `json:"test_reporter_id"`
GithubSlug string `json:"github_slug"`
VCSHost string `json:"vcs_host"`
} `json:"attributes"`
Relationships struct {
Account struct {
Data struct {
ID string `json:"id"`
} `json:"data"`
} `json:"account"`
} `json:"relationships"`
} `json:"data"`
}

Expand Down Expand Up @@ -69,6 +79,8 @@ func (client *Client) GetRepository(repositorySlug string) (*Repository, error)
Id: repositoryData.Data[0].ID,
TestReporterId: repositoryData.Data[0].Attributes.TestReporterID,
GithubSlug: repositoryData.Data[0].Attributes.GithubSlug,
Organization: repositoryData.Data[0].Relationships.Account.Data.ID,
RepositoryURL: repositoryData.Data[0].Attributes.VCSHost + "/" + repositoryData.Data[0].Attributes.GithubSlug,
}

return repository, nil
Expand Down

0 comments on commit 4328f84

Please sign in to comment.