Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions internal/api/sm.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ func (s *SMService) GetServiceDesks(ctx context.Context) ([]*ServiceDesk, error)

// RequestType represents a request type in a service desk.
type RequestType struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
ServiceDesk *struct {
ID string `json:"id"`
} `json:"serviceDeskId,omitempty"`
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
IssueTypeID string `json:"issueTypeId"`
ServiceDeskID string `json:"serviceDeskId"`
PortalID string `json:"portalId"`
}

// RequestTypePage represents a paginated list of request types.
Expand Down
22 changes: 15 additions & 7 deletions internal/api/sm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,18 @@ func TestGetServiceDesks(t *testing.T) {
}

func TestGetRequestTypes(t *testing.T) {
// Shaped like the real servicedeskapi response: the id fields are plain strings.
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(RequestTypePage{
Size: 2, Start: 0, Limit: 50, IsLastPage: true,
Values: []*RequestType{
{ID: "10", Name: "Incident", Description: "Report an incident"},
{ID: "26", Name: "Service Delivery", Description: "DL ticket creation"},
},
})
_, _ = w.Write([]byte(`{
"size": 2, "start": 0, "limit": 50, "isLastPage": true,
"values": [
{"id": "10", "name": "Incident", "description": "Report an incident",
"issueTypeId": "10035", "serviceDeskId": "1", "portalId": "1", "groupIds": ["50"]},
{"id": "26", "name": "Service Delivery", "description": "DL ticket creation",
"issueTypeId": "10036", "serviceDeskId": "1", "portalId": "1", "groupIds": []}
]
}`))
}))
defer server.Close()

Expand All @@ -90,6 +93,11 @@ func TestGetRequestTypes(t *testing.T) {
if result.Values[1].Name != "Service Delivery" {
t.Errorf("second type name = %q, want Service Delivery", result.Values[1].Name)
}
first := result.Values[0]
if first.IssueTypeID != "10035" || first.ServiceDeskID != "1" || first.PortalID != "1" {
t.Errorf("first type ids = issueType %q, serviceDesk %q, portal %q; want 10035, 1, 1",
first.IssueTypeID, first.ServiceDeskID, first.PortalID)
}
}

func TestGetRequestTypeFields(t *testing.T) {
Expand Down
4 changes: 4 additions & 0 deletions internal/cmd/issue/field_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ func ParseCustomField(ctx context.Context, jira *api.JiraService, raw string) (s
// based on the field's schema.
func coerceFieldValue(field *api.Field, value string) interface{} {
if field != nil && field.Schema != nil {
// Jira silently ignores a Service Management request type id sent as a number.
if field.Schema.Type == "sd-customerrequesttype" {
return value
}
customType := field.Schema.Custom
if strings.Contains(customType, "select") || strings.Contains(customType, "radiobuttons") {
return map[string]string{"value": value}
Expand Down
18 changes: 18 additions & 0 deletions internal/cmd/issue/field_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,24 @@ func TestCoerceFieldValue_SelectStillWorks(t *testing.T) {
}
}

// TestCoerceFieldValue_RequestTypeStaysString covers the Service Management
// Request Type field: Jira silently ignores its id when it is sent as a number.
func TestCoerceFieldValue_RequestTypeStaysString(t *testing.T) {
field := &api.Field{
ID: "customfield_10010",
Name: "Request Type",
Schema: &api.FieldSchema{
Type: "sd-customerrequesttype",
Custom: "com.atlassian.servicedesk:vp-origin",
},
}

got := coerceFieldValue(field, "3")
if got != "3" {
t.Errorf("got %#v (%T), want the string \"3\"", got, got)
}
}

// TestCoerceFieldValue_RadioStillWorks verifies radiobutton fields are not regressed.
func TestCoerceFieldValue_RadioStillWorks(t *testing.T) {
field := &api.Field{
Expand Down
14 changes: 9 additions & 5 deletions internal/cmd/sm/requesttype.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,22 @@ func runRequestTypeList(opts *RequestTypeListOptions) error {
return output.JSON(opts.IO.Out, types)
}

headers := []string{"ID", "Name", "Description"}
headers := []string{"ID", "Name", "Issue Type ID", "Description"}
output.SimpleTable(opts.IO.Out, headers, requestTypeRows(types))
return nil
}

// requestTypeRows builds the table rows for request types.
func requestTypeRows(types []*api.RequestType) [][]string {
rows := make([][]string, 0, len(types))
for _, t := range types {
desc := t.Description
if len(desc) > 60 {
desc = desc[:57] + "..."
}
rows = append(rows, []string{t.ID, t.Name, desc})
rows = append(rows, []string{t.ID, t.Name, t.IssueTypeID, desc})
}
Comment thread
fjung marked this conversation as resolved.
Resolved

output.SimpleTable(opts.IO.Out, headers, rows)
return nil
return rows
}

// ── request-type fields ────────────────────────────────────────────
Expand Down
19 changes: 19 additions & 0 deletions internal/cmd/sm/requesttype_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package sm

import (
"reflect"
"testing"

"github.com/enthus-appdev/atl-cli/internal/api"
)

func TestRequestTypeRows_IncludesIssueType(t *testing.T) {
rows := requestTypeRows([]*api.RequestType{
{ID: "3", Name: "Änderungs-Ticket", IssueTypeID: "10035", Description: "Change request"},
})

want := [][]string{{"3", "Änderungs-Ticket", "10035", "Change request"}}
if !reflect.DeepEqual(rows, want) {
t.Errorf("rows = %v, want %v", rows, want)
}
}
Loading