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

Commit 4328f84

Browse files
authored
PR feedback (#6)
* fix json structure * cleanup comments * missing error output
1 parent dc896ea commit 4328f84

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Currently the provider supports just retreaving the repository as data source.
2626

2727
```hcl
2828
provider "codeclimate" {
29-
api_key = "${var.api_key}"
29+
api_key = "${var.api_key}" # Will fallback to CODECLIMATE_TOKEN environment variable if not explicitly specified.
3030
}
3131
3232
data "codeclimate_repository" "test" {

codeclimate/resource_repository.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ func resourceRepositoryRead(d *schema.ResourceData, client interface{}) error {
5252
return err
5353
}
5454
err = d.Set("codeclimate_id", repository.Id)
55+
if err != nil {
56+
return err
57+
}
58+
err = d.Set("repository_url", repository.RepositoryURL)
59+
if err != nil {
60+
return err
61+
}
62+
err = d.Set("organization_id", repository.Organization)
5563
return err
5664
}
5765

codeclimateclient/organization.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package codeclimateclient
22

33
import (
44
"encoding/json"
5+
"fmt"
56
"net/http"
67
)
78

@@ -42,5 +43,5 @@ func (client *Client) GetOrganization(organizationName string) (*Organization, e
4243
return organization, nil
4344
}
4445
}
45-
return nil, nil
46+
return nil, fmt.Errorf("The Organization could not be found")
4647
}

codeclimateclient/repository.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ type Repository struct {
1111
Id string
1212
TestReporterId string
1313
GithubSlug string
14+
Organization string
15+
RepositoryURL string
1416
}
1517

1618
// The structure describes just what we need from the response.
@@ -21,7 +23,15 @@ type readRepositoriesResponse struct {
2123
Attributes struct {
2224
TestReporterID string `json:"test_reporter_id"`
2325
GithubSlug string `json:"github_slug"`
26+
VCSHost string `json:"vcs_host"`
2427
} `json:"attributes"`
28+
Relationships struct {
29+
Account struct {
30+
Data struct {
31+
ID string `json:"id"`
32+
} `json:"data"`
33+
} `json:"account"`
34+
} `json:"relationships"`
2535
} `json:"data"`
2636
}
2737

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

7486
return repository, nil

0 commit comments

Comments
 (0)