package bot import ( "errors" "fmt" "strings" "git.front.kjuulh.io/kjuulh/contractor/internal/models" "git.front.kjuulh.io/kjuulh/contractor/internal/providers" ) type BotHandler struct { giteaClient *providers.GiteaClient } func NewBotHandler(gitea *providers.GiteaClient) *BotHandler { return &BotHandler{giteaClient: gitea} } func (b *BotHandler) Handle(input string) (output string, err error) { innerHandle := func(input string) (output string, err error) { if strings.HasPrefix(input, "help") { return b.Help(), nil } if strings.HasPrefix(input, "refresh") { return `

Contractor triggered renovate refresh on this repository

This comment will be updated with status `, nil } return b.Help(), errors.New("could not recognize command") } output, err = innerHandle(input) output = fmt.Sprintf( "%s\nThis comment was generated by Contractor", output, ) return output, err } func (b *BotHandler) Help() string { return `

/contractor [command]

Commands: * /contractor help * triggers the help menu * /contractor refresh * triggers renovate to refresh the current pull request
` } func (b *BotHandler) AppendComment( owner string, repository string, pullRequest int, comment string, ) (*models.AddCommentResponse, error) { return b.giteaClient.AddComment(owner, repository, pullRequest, comment) }