Skip to content

Commit

Permalink
Allow a procedure definition to include custom labels
Browse files Browse the repository at this point in the history
  • Loading branch information
paddybyers committed Aug 19, 2019
1 parent c5a1bd8 commit 0a17a03
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
5 changes: 1 addition & 4 deletions internal/cli/procedure.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ func procedureAction(c *cli.Context) error {

for _, procedure := range procedures {
if procedure.ID == procedureID {
err = tp.Create(&model.Ticket{
Name: procedure.Name,
Body: fmt.Sprintf("%s\n\n\n---\nProcedure-ID: %s", procedure.Body, procedure.ID),
}, []string{"comply", "comply-procedure"})
err = tp.Create(procedure.NewTicket(), procedure.Labels())
if err != nil {
return err
}
Expand Down
25 changes: 21 additions & 4 deletions internal/model/procedure.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package model

import "time"
import (
"fmt"
"time"
)

var defaultLabels = []string{"comply", "comply-procedure"}

type Procedure struct {
Name string `yaml:"name"`
ID string `yaml:"id"`
Cron string `yaml:"cron"`
Name string `yaml:"name"`
ID string `yaml:"id"`
Cron string `yaml:"cron"`
CustomLabels []string `yaml:"labels"`

Revisions []Revision `yaml:"majorRevisions"`
Satisfies Satisfaction `yaml:"satisfies"`
Expand All @@ -14,3 +20,14 @@ type Procedure struct {
ModifiedAt time.Time
Body string
}

func (p *Procedure) Labels() []string {
return append(defaultLabels, p.CustomLabels...)
}

func (p *Procedure) NewTicket() *Ticket {
return &Ticket{
Name: p.Name,
Body: fmt.Sprintf("%s\n\n\n---\nProcedure-ID: %s", p.Body, p.ID),
}
}
5 changes: 1 addition & 4 deletions internal/ticket/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,6 @@ func trigger(procedure *model.Procedure) error {
}

tp := model.GetPlugin(model.TicketSystem(ts))
err = tp.Create(&model.Ticket{
Name: procedure.Name,
Body: fmt.Sprintf("%s\n\n\n---\nProcedure-ID: %s", procedure.Body, procedure.ID),
}, []string{"comply", "comply-procedure"})
err = tp.Create(procedure.NewTicket(), procedure.Labels())
return err
}

0 comments on commit 0a17a03

Please sign in to comment.