Skip to content

Commit

Permalink
Don't require ticket status and type (#162)
Browse files Browse the repository at this point in the history
* dont require status and type

* check if ticket type id exists on template before setting type

* leave better comments/better var names
  • Loading branch information
laurenleach authored Jul 2, 2024
1 parent 45be7d8 commit fd4aee6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
9 changes: 6 additions & 3 deletions pkg/tasks/local/ticket.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,13 @@ func (m *localCreateTicket) Process(ctx context.Context, task *v1.Task, cc types
ticketRequestBody := &v2.TicketRequest{
DisplayName: template.DisplayName,
Description: template.Description,
Type: &v2.TicketType{
Labels: template.Labels,
}

if template.TypeId != "" {
ticketRequestBody.Type = &v2.TicketType{
Id: template.TypeId,
},
Labels: template.Labels,
}
}

if template.StatusId != "" {
Expand Down
51 changes: 24 additions & 27 deletions pkg/types/ticket/custom_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,39 +244,36 @@ func GetCustomFieldValue(field *v2.TicketCustomField) (interface{}, error) {
func ValidateTicket(ctx context.Context, schema *v2.TicketSchema, ticket *v2.Ticket) (bool, error) {
l := ctxzap.Extract(ctx)

// Look for a matching status
foundMatch := false
for _, status := range schema.GetStatuses() {
// Status is not required
if ticket.Status == nil {
foundMatch = true
break
}

if ticket.Status.GetId() == status.GetId() {
foundMatch = true
break
// Validate the ticket status is one defined in the schema
// Ticket status is not required so if a ticket doesn't have a status
// we don't need to validate, skip the loop in this case
validTicketStatus := ticket.Status == nil
if !validTicketStatus {
for _, status := range schema.GetStatuses() {
if ticket.Status.GetId() == status.GetId() {
validTicketStatus = true
break
}
}
}

if !foundMatch {
if !validTicketStatus {
l.Debug("error: invalid ticket: could not find status", zap.String("status_id", ticket.Status.GetId()))
return false, nil
}

// Look for a matching ticket type
foundMatch = false
for _, tType := range schema.GetTypes() {
if ticket.Type == nil {
return false, nil
}
if ticket.Type.GetId() == tType.GetId() {
foundMatch = true
break
// Validate the ticket type is one defined in the schema
// Ticket type is not required so if a ticket doesn't have a type
// we don't need to validate, skip the loop in this case
validTicketType := ticket.Type == nil
if !validTicketType {
for _, tType := range schema.GetTypes() {
if ticket.Type.GetId() == tType.GetId() {
validTicketType = true
break
}
}
}

if !foundMatch {
if !validTicketType {
l.Debug("error: invalid ticket: could not find ticket type", zap.String("ticket_type_id", ticket.Type.GetId()))
return false, nil
}
Expand Down Expand Up @@ -360,7 +357,7 @@ func ValidateTicket(ctx context.Context, schema *v2.TicketSchema, ticket *v2.Tic
return false, nil
}

foundMatch = false
foundMatch := false
for _, m := range allowedValues {
if m == ticketValue {
foundMatch = true
Expand Down Expand Up @@ -435,7 +432,7 @@ func ValidateTicket(ctx context.Context, schema *v2.TicketSchema, ticket *v2.Tic
return false, nil
}

foundMatch = false
foundMatch := false
for _, m := range allowedValues {
if m.GetId() == ticketValue.GetId() {
foundMatch = true
Expand Down

0 comments on commit fd4aee6

Please sign in to comment.