Skip to content

Commit

Permalink
feature(main): add rebot code
Browse files Browse the repository at this point in the history
  • Loading branch information
cuisongliu committed Apr 27, 2023
1 parent 06cd393 commit aae2a57
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
10 changes: 6 additions & 4 deletions cmd/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/spf13/cobra"
)

// commentCmd represents the comment command
var commentCmd = &cobra.Command{
Use: "comment",
Args: cobra.ExactArgs(0),
Expand All @@ -34,9 +33,12 @@ var commentCmd = &cobra.Command{
cmds := strings.Split(comment, "\n")
for _, t := range cmds {
logger.Debug("cmds: ", strings.TrimSpace(t))
wfs := []workflow.Interface{
workflow.NewRelease(strings.TrimSpace(t)),
workflow.NewChangelog(strings.TrimSpace(t)),
wfs := make([]workflow.Interface, 0)
if types.GlobalsBotConfig.Changelog != nil {
wfs = append(wfs, workflow.NewChangelog(strings.TrimSpace(t)))
}
if types.GlobalsBotConfig.Release != nil {
wfs = append(wfs, workflow.NewRelease(strings.TrimSpace(t)))
}
used := 0
for _, wf := range wfs {
Expand Down
29 changes: 17 additions & 12 deletions pkg/types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ type Config struct {
Message map[string]string `json:"message"`
Token string `json:"-"`

Changelog Changelog `json:"changelog"`
Release Release `json:"release"`
Changelog *Changelog `json:"changelog,omitempty"`
Release *Release `json:"release,omitempty"`
}

func (r *Config) Validate() error {
Expand All @@ -72,18 +72,23 @@ func (r *Config) Validate() error {
if r.Repo.Fork == "" {
return fmt.Errorf("repo fork is required")
}
if r.Changelog.Body == "" {
return fmt.Errorf("changelog body is required")
if r.Changelog != nil {
if r.Changelog.Body == "" {
return fmt.Errorf("changelog body is required")
}
if r.Changelog.Title == "" {
return fmt.Errorf("changelog title is required")
}
}
if r.Changelog.Title == "" {
return fmt.Errorf("changelog title is required")
}
if r.Release.Action == "" {
return fmt.Errorf("release action is required")
}
if r.Release.Retry == "" {
return fmt.Errorf("release retry is required")
if r.Release != nil {
if r.Release.Action == "" {
return fmt.Errorf("release action is required")
}
if r.Release.Retry == "" {
return fmt.Errorf("release retry is required")
}
}

return nil
}

Expand Down

0 comments on commit aae2a57

Please sign in to comment.