From 4328f84e83523dedf2710db8e2813acd7f1fdccd Mon Sep 17 00:00:00 2001 From: Varditn <38429204+TAvardit@users.noreply.github.com> Date: Wed, 2 Sep 2020 15:03:37 +0200 Subject: [PATCH] PR feedback (#6) * fix json structure * cleanup comments * missing error output --- README.md | 2 +- codeclimate/resource_repository.go | 8 ++++++++ codeclimateclient/organization.go | 3 ++- codeclimateclient/repository.go | 12 ++++++++++++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3b63915..d6166cb 100644 --- a/README.md +++ b/README.md @@ -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" { diff --git a/codeclimate/resource_repository.go b/codeclimate/resource_repository.go index 632f60d..7c83c9d 100644 --- a/codeclimate/resource_repository.go +++ b/codeclimate/resource_repository.go @@ -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 } diff --git a/codeclimateclient/organization.go b/codeclimateclient/organization.go index f9d1932..f071f00 100644 --- a/codeclimateclient/organization.go +++ b/codeclimateclient/organization.go @@ -2,6 +2,7 @@ package codeclimateclient import ( "encoding/json" + "fmt" "net/http" ) @@ -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") } diff --git a/codeclimateclient/repository.go b/codeclimateclient/repository.go index 6f2c217..52c39bd 100644 --- a/codeclimateclient/repository.go +++ b/codeclimateclient/repository.go @@ -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. @@ -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"` } @@ -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