Documentation ¶
Overview ¶
Package genyaml can generate an example YAML snippet from an initialized struct and decorate it with godoc comments parsed from the AST of a given file.
Example:
cm, err := NewCommentMap("example_config.go") yamlSnippet, err := cm.GenYaml(&plugins.Configuration{ Approve: []plugins.Approve{ { Repos: []string{ "ORGANIZATION", "ORGANIZATION/REPOSITORY", }, IssueRequired: false, RequireSelfApproval: new(bool), LgtmActsAsApprove: false, IgnoreReviewState: new(bool), }, }, })
Alternatively, you can also use `PopulateStruct` to recursively fill all pointer fields, slices and maps of a struct via reflection:
yamlSnippet, err := cm.GenYaml(PopulateStruct(&plugins.Configuration{}))
yamlSnippet will be assigned a string containing the following YAML: # Approve is the configuration for the Approve plugin. approve: - # Repos is either of the form org/repos or just org. repos: - ORGANIZATION - ORGANIZATION/REPOSITORY # IssueRequired indicates if an associated issue is required for approval in the specified repos. issue_required: true # RequireSelfApproval requires PR authors to explicitly approve their PRs. Otherwise the plugin assumes the author of the PR approves the changes in the PR. require_self_approval: false # LgtmActsAsApprove indicates that the lgtm command should be used to indicate approval lgtm_acts_as_approve: true # IgnoreReviewState causes the approve plugin to ignore the GitHub review state. Otherwise: * an APPROVE github review is equivalent to leaving an \"/approve\" message. * A REQUEST_CHANGES github review is equivalent to leaving an /approve cancel\" message. ignore_review_state: false
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PopulateStruct ¶
func PopulateStruct(in interface{}) interface{}
PopulateStruct will recursively populate a struct via reflection for consumption by genyaml by: * Filling all pointer fields * Filling all slices with a one-element slice and filling that one element * Filling all maps with a one-element map and filling that one element NOTE: PopulateStruct will panic if not fed a pointer. Generally if you care about the stability of the app that runs this code, it is strongly recommended to recover panics: defer func(){if r := recover(); r != nil { fmt.Printf("Recovered panic: %v", r } }(
Types ¶
type Comment ¶
type Comment struct { // Type is the underlying type of the identifier associated with the comment. Type string // IsObj determines if the underlying type is a object type (e.g. struct) or primitive type (e.g. string). IsObj bool // Doc is a comment string parsed from the AST of a node. Doc string }
Comment is an abstract structure for storing parsed AST comments decorated with contextual information.
type CommentMap ¶
type CommentMap struct { // RWMutex is a read/write mutex. sync.RWMutex // contains filtered or unexported fields }
Comment is an abstract structure for storing mapped types to comments.
func NewCommentMap ¶
func NewCommentMap(rawFiles map[string][]byte, paths ...string) (*CommentMap, error)
NewCommentMap is the constructor for CommentMap accepting a variadic number of path and raw files contents.
func (*CommentMap) EncodeYaml ¶
func (cm *CommentMap) EncodeYaml(config interface{}, encoder *yaml3.Encoder) error
EncodeYaml encodes a fully commented YAML snippet for a given plugin configuration using the given encoder.
func (*CommentMap) GenYaml ¶
func (cm *CommentMap) GenYaml(config interface{}) (string, error)
GenYaml generates a fully commented YAML snippet for a given plugin configuration.
func (*CommentMap) PrintComments ¶
func (cm *CommentMap) PrintComments()
PrintComments pretty prints comments.