@@ -5,22 +5,29 @@ import (
55 "fmt"
66 "net/url"
77 "strings"
8+
9+ "coder.com/coder-registry/cmd/github"
810)
911
1012type coderResourceFrontmatter struct {
1113 Description string `yaml:"description"`
1214 IconURL string `yaml:"icon"`
1315 DisplayName * string `yaml:"display_name"`
14- Tags []string `yaml:"tags"`
1516 Verified * bool `yaml:"verified"`
17+ Tags []string `yaml:"tags"`
1618}
1719
18- type coderResourceReadme struct {
20+ // coderResource represents a generic concept for a Terraform resource used to
21+ // help create Coder workspaces. As of 2025-04-15, this encapsulates both
22+ // Coder Modules and Coder Templates.
23+ type coderResource struct {
24+ name string
25+ filePath string
26+ readmeBody string
1927 oldFrontmatter * coderResourceFrontmatter
2028 newFrontmatter * coderResourceFrontmatter
21- newBody string
22- moduleName string
23- filePath string
29+ oldIsVerified bool
30+ newIsVerified bool
2431}
2532
2633func validateCoderResourceDisplayName (displayName * string ) error {
@@ -95,6 +102,37 @@ func validateCoderResourceTags(tags []string) error {
95102 return nil
96103}
97104
98- func validateCoderResourceReadmeBody (body string ) []error {
105+ func validateCoderResourceVerifiedStatus (oldVerified bool , newVerified bool , actorOrgStatus github.OrgStatus ) error {
106+ // If the actor making the changes is an employee of Coder, any changes are
107+ // assumed to be valid
108+ if actorOrgStatus == github .OrgStatusMember {
109+ return nil
110+ }
111+
112+ // Right now, because we collapse the omitted/nil case and false together,
113+ // the only field transition that's allowed is if the verified statuses are
114+ // exactly the same (which includes the field going from omitted to
115+ // explicitly false, or vice-versa).
116+ isPermittedChangeForNonEmployee := oldVerified == newVerified
117+ if isPermittedChangeForNonEmployee {
118+ return nil
119+ }
120+
121+ return fmt .Errorf ("actor with status %q is not allowed to flip verified status from %t to %t" , actorOrgStatus .String (), oldVerified , newVerified )
122+ }
123+
124+ // Todo: once we decide on how we want the README frontmatter to be formatted
125+ // for the Embedded Registry work, update this function to validate that the
126+ // correct Terraform code snippets are included in the README and are actually
127+ // valid Terraform
128+ func validateCoderResourceReadmeBody (body string ) error {
129+ trimmed := strings .TrimSpace (body )
130+ if ! strings .HasPrefix (trimmed , "# " ) {
131+ return errors .New ("README body must start with ATX-style h1 header (i.e., \" # \" )" )
132+ }
133+ return nil
134+ }
135+
136+ func validateCoderResource (resource coderResource ) []error {
99137 return nil
100138}
0 commit comments