Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use new dedicated HoverURL field #51

Merged
merged 1 commit into from
Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.14
require (
github.com/google/go-cmp v0.5.6
github.com/hashicorp/go-version v1.3.0
github.com/hashicorp/hcl-lang v0.0.0-20210522074354-f7480edf31b5
github.com/hashicorp/hcl-lang v0.0.0-20210603100913-81056fd9a6e0
github.com/hashicorp/hcl/v2 v2.10.0
github.com/hashicorp/terraform-json v0.11.0
github.com/hashicorp/terraform-registry-address v0.0.0-20210412075316-9b2996cce896
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9
github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/go-version v1.3.0 h1:McDWVJIU/y+u1BRV06dPaLfLCaT7fUTJLp5r04x7iNw=
github.com/hashicorp/go-version v1.3.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/hcl-lang v0.0.0-20210522074354-f7480edf31b5 h1:lgywSdFExtTcqjaenkU2xhnbmtYLJIW+Ch3qQW0z6Jg=
github.com/hashicorp/hcl-lang v0.0.0-20210522074354-f7480edf31b5/go.mod h1:yPc3ggegh0njWLfIBPbmTk6a5T/vJVsMm4z6IuEgePU=
github.com/hashicorp/hcl-lang v0.0.0-20210603100913-81056fd9a6e0 h1:CmEDMGKu8J5E8Yk4lcYwS8tC/K2ybAQ4nStw8raIjVQ=
github.com/hashicorp/hcl-lang v0.0.0-20210603100913-81056fd9a6e0/go.mod h1:uMsq6wV8ZXEH8qndov4tncXlHDYnZ8aHsGmS4T74e2o=
github.com/hashicorp/hcl/v2 v2.10.0 h1:1S1UnuhDGlv3gRFV4+0EdwB+znNP5HmcGbIqwnSCByg=
github.com/hashicorp/hcl/v2 v2.10.0/go.mod h1:FwWsfWEjyV/CMj8s/gqAuiviY72rJ1/oayI9WftqcKg=
github.com/hashicorp/terraform-json v0.11.0 h1:4zDqqW2F3kOysORIaYKFGgWDYIRA3hwqx3XHeHkbBQ0=
Expand Down
20 changes: 15 additions & 5 deletions schema/convert_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func ProviderSchemaFromJson(jsonSchema *tfjson.ProviderSchema, pAddr tfaddr.Prov
if jsonSchema.ConfigSchema != nil {
ps.Provider = bodySchemaFromJson(jsonSchema.ConfigSchema.Block)
ps.Provider.Detail = detailForSrcAddr(pAddr, nil)
ps.Provider.HoverURL = urlForProvider(pAddr, nil)
ps.Provider.DocsLink = docsLinkForProvider(pAddr, nil)
}

Expand All @@ -39,6 +40,7 @@ func ProviderSchemaFromJson(jsonSchema *tfjson.ProviderSchema, pAddr tfaddr.Prov
func (ps *ProviderSchema) SetProviderVersion(pAddr tfaddr.Provider, v *version.Version) {
if ps.Provider != nil {
ps.Provider.Detail = detailForSrcAddr(pAddr, v)
ps.Provider.HoverURL = urlForProvider(pAddr, v)
ps.Provider.DocsLink = docsLinkForProvider(pAddr, v)
}
for _, rSchema := range ps.Resources {
Expand Down Expand Up @@ -199,16 +201,24 @@ func docsLinkForProvider(addr tfaddr.Provider, v *version.Version) *schema.DocsL
return nil
}

return &schema.DocsLink{
URL: urlForProvider(addr, v),
Tooltip: fmt.Sprintf("%s Documentation", addr.ForDisplay()),
}
}

func urlForProvider(addr tfaddr.Provider, v *version.Version) string {
if !providerHasDocs(addr) {
return ""
}

ver := "latest"
if v != nil {
ver = v.String()
}

return &schema.DocsLink{
URL: fmt.Sprintf("https://registry.terraform.io/providers/%s/%s/%s/docs",
addr.Namespace, addr.Type, ver),
Tooltip: fmt.Sprintf("%s Documentation", addr.ForDisplay()),
}
return fmt.Sprintf("https://registry.terraform.io/providers/%s/%s/%s/docs",
addr.Namespace, addr.Type, ver)
}

func providerHasDocs(addr tfaddr.Provider) bool {
Expand Down
3 changes: 2 additions & 1 deletion schema/convert_json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ func TestProviderSchema_SetProviderVersion(t *testing.T) {
}
expectedSchema := &ProviderSchema{
Provider: &schema.BodySchema{
Detail: "hashicorp/aws 1.2.5",
Detail: "hashicorp/aws 1.2.5",
HoverURL: "https://registry.terraform.io/providers/hashicorp/aws/1.2.5/docs",
DocsLink: &schema.DocsLink{
URL: "https://registry.terraform.io/providers/hashicorp/aws/1.2.5/docs",
Tooltip: "hashicorp/aws Documentation",
Expand Down
2 changes: 2 additions & 0 deletions schema/schema_merge_v012_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var expectedMergedSchema_v012 = &schema.BodySchema{
Blocks: map[string]*schema.BlockSchema{},
Attributes: map[string]*schema.AttributeSchema{},
Detail: "hashicorp/null",
HoverURL: "https://registry.terraform.io/providers/hashicorp/null/latest/docs",
DocsLink: &schema.DocsLink{
URL: "https://registry.terraform.io/providers/hashicorp/null/latest/docs",
Tooltip: "hashicorp/null Documentation",
Expand All @@ -36,6 +37,7 @@ var expectedMergedSchema_v012 = &schema.BodySchema{
Blocks: map[string]*schema.BlockSchema{},
Attributes: map[string]*schema.AttributeSchema{},
Detail: "hashicorp/random",
HoverURL: "https://registry.terraform.io/providers/hashicorp/random/latest/docs",
DocsLink: &schema.DocsLink{
URL: "https://registry.terraform.io/providers/hashicorp/random/latest/docs",
Tooltip: "hashicorp/random Documentation",
Expand Down
9 changes: 6 additions & 3 deletions schema/schema_merge_v013_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ var expectedMergedSchema_v013 = &schema.BodySchema{
},
DependentBody: map[schema.SchemaKey]*schema.BodySchema{
`{"labels":[{"index":0,"value":"grafana"}]}`: {
Detail: "grafana/grafana",
Detail: "grafana/grafana",
HoverURL: "https://registry.terraform.io/providers/grafana/grafana/latest/docs",
DocsLink: &schema.DocsLink{
URL: "https://registry.terraform.io/providers/grafana/grafana/latest/docs",
Tooltip: "grafana/grafana Documentation",
Expand Down Expand Up @@ -56,7 +57,8 @@ var expectedMergedSchema_v013 = &schema.BodySchema{
},
},
`{"labels":[{"index":0,"value":"null"}]}`: {
Detail: "hashicorp/null",
Detail: "hashicorp/null",
HoverURL: "https://registry.terraform.io/providers/hashicorp/null/latest/docs",
DocsLink: &schema.DocsLink{
URL: "https://registry.terraform.io/providers/hashicorp/null/latest/docs",
Tooltip: "hashicorp/null Documentation",
Expand All @@ -65,7 +67,8 @@ var expectedMergedSchema_v013 = &schema.BodySchema{
Attributes: map[string]*schema.AttributeSchema{},
},
`{"labels":[{"index":0,"value":"rand"}]}`: {
Detail: "hashicorp/random",
Detail: "hashicorp/random",
HoverURL: "https://registry.terraform.io/providers/hashicorp/random/latest/docs",
DocsLink: &schema.DocsLink{
URL: "https://registry.terraform.io/providers/hashicorp/random/latest/docs",
Tooltip: "hashicorp/random Documentation",
Expand Down
1 change: 1 addition & 0 deletions schema/schema_merge_v015_aliased_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ var expectedMergedSchema_v015_aliased = &schema.BodySchema{
Blocks: map[string]*schema.BlockSchema{},
Attributes: map[string]*schema.AttributeSchema{},
Detail: "hashicorp/hashicup",
HoverURL: "https://registry.terraform.io/providers/hashicorp/hashicup/latest/docs",
DocsLink: &schema.DocsLink{
URL: "https://registry.terraform.io/providers/hashicorp/hashicup/latest/docs",
Tooltip: "hashicorp/hashicup Documentation",
Expand Down
1 change: 1 addition & 0 deletions schema/schema_merge_v015_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ var expectedMergedSchema_v015 = &schema.BodySchema{
Blocks: map[string]*schema.BlockSchema{},
Attributes: map[string]*schema.AttributeSchema{},
Detail: "hashicorp/hashicup",
HoverURL: "https://registry.terraform.io/providers/hashicorp/hashicup/latest/docs",
DocsLink: &schema.DocsLink{
URL: "https://registry.terraform.io/providers/hashicorp/hashicup/latest/docs",
Tooltip: "hashicorp/hashicup Documentation",
Expand Down