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 20, 2023
1 parent bcbb48f commit 2bf8eaf
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
30 changes: 30 additions & 0 deletions pkg/types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ limitations under the License.

package types

import "fmt"

type Bot struct {
Prefix string `json:"prefix"`
Spe string `json:"spe"`
Expand Down Expand Up @@ -58,6 +60,34 @@ type Config struct {
Release Release `json:"release"`
}

func (r *Config) Validate() error {
if r.Bot.Username == "" {
return fmt.Errorf("bot username is required")
}
if r.Bot.Email == "" {
return fmt.Errorf("bot email is required")
}
if r.Repo.Name == "" {
return fmt.Errorf("repo name is required")
}
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.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")
}
return nil
}

// GetPrefix returns the prefix for the bot
func (r *Config) GetPrefix() string {
if r.Bot.Prefix == "" {
Expand Down
3 changes: 3 additions & 0 deletions pkg/types/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ func ParseConfig(filePath string) (*Config, error) {
if config.Repo.Org {
config.Repo.OrgCommand = fmt.Sprintf(" --org %s ", strings.SplitN(config.GetRepoName(), "/", 2)[0])
}
if err = config.Validate(); err != nil {
return nil, err
}
return config, nil
}

Expand Down

0 comments on commit 2bf8eaf

Please sign in to comment.