Skip to content
This repository has been archived by the owner on Mar 11, 2021. It is now read-only.

Commit

Permalink
Merge branch 'master' into deployments-check-k8s-auth
Browse files Browse the repository at this point in the history
  • Loading branch information
ebaron authored Aug 21, 2018
2 parents 6b37402 + b0ee723 commit 41e967d
Show file tree
Hide file tree
Showing 28 changed files with 928 additions and 180 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"Cache-Control": [
"max-age=2"
],
"Content-Type": [
"application/vnd.api+json"
],
"Etag": [
"1GmclFDDPcLR1ZWPZnykWw=="
],
"Last-Modified": [
"Mon, 01 Jan 0001 00:00:00 GMT"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"data": [
{
"attributes": {
"name": "workitemtype",
"timestamp": "0001-01-01T00:00:00Z"
},
"id": "00000000-0000-0000-0000-000000000001",
"relationships": {
"modifier": {
"data": {
"id": "00000000-0000-0000-0000-000000000002",
"type": "users"
},
"links": {
"related": "http:///api/users/00000000-0000-0000-0000-000000000002",
"self": "http:///api/users/00000000-0000-0000-0000-000000000002"
}
},
"newValue": {
"data": [
{
"id": "00000000-0000-0000-0000-000000000003",
"type": "workitemtypes"
}
]
},
"oldValue": {
"data": [
{
"id": "00000000-0000-0000-0000-000000000004",
"type": "workitemtypes"
}
]
},
"workItemType": {
"data": {
"id": "00000000-0000-0000-0000-000000000003",
"type": "workitemtypes"
},
"links": {
"self": "http:///api/workitemtypes/00000000-0000-0000-0000-000000000003"
}
}
},
"type": "events"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@
"required": false,
"type": {
"baseType": "string",
"defaultValue": "P3 - Medium",
"kind": "enum",
"values": [
"P1 - Critical",
Expand Down Expand Up @@ -458,6 +459,7 @@
"required": false,
"type": {
"baseType": "string",
"defaultValue": "SEV3 - Medium",
"kind": "enum",
"values": [
"SEV1 - Urgent",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@
"required": false,
"type": {
"baseType": "string",
"defaultValue": "Medium",
"kind": "enum",
"values": [
"Critical",
Expand Down
39 changes: 34 additions & 5 deletions controller/work_item_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,6 @@ func ConvertEvent(ctx context.Context, appl application.Application, req *http.R
if err != nil {
return nil, errs.Wrapf(err, "failed to load work item type: %s", wiEvent.WorkItemTypeID)
}
fieldName := wiEvent.Name
fieldDef, ok := wit.Fields[fieldName]
if !ok {
return nil, errs.Errorf("failed to find field \"%s\" in work item type: %s (%s)", fieldName, wit.Name, wit.ID)
}
modifierData, modifierLinks := ConvertUserSimple(req, wiEvent.Modifier)
e := app.Event{
Type: event.APIStringTypeEvents,
Expand All @@ -111,6 +106,40 @@ func ConvertEvent(ctx context.Context, appl application.Application, req *http.R
},
}

if wiEvent.Name == event.WorkitemTypeChangeEvent {
oldTypeUUID, ok := wiEvent.Old.(uuid.UUID)
if !ok {
return nil, errs.Errorf("failed to convert old workitem type ID to UUID: %s", wiEvent.Old)
}
newTypeUUID, ok := wiEvent.New.(uuid.UUID)
if !ok {
return nil, errs.Errorf("failed to convert new workitem type ID to UUID: %s", wiEvent.New)
}
e.Relationships.OldValue = &app.RelationGenericList{
Data: []*app.GenericData{
{
ID: ptr.String(oldTypeUUID.String()),
Type: ptr.String(APIStringTypeWorkItemType),
},
},
}
e.Relationships.NewValue = &app.RelationGenericList{
Data: []*app.GenericData{
{
ID: ptr.String(newTypeUUID.String()),
Type: ptr.String(APIStringTypeWorkItemType),
},
},
}
return &e, nil
}

fieldName := wiEvent.Name
fieldDef, ok := wit.Fields[fieldName]
if !ok {
return nil, errs.Errorf("failed to find field \"%s\" in work item type: %s (%s)", fieldName, wit.Name, wit.ID)
}

// convertVal returns the given value converted from storage space to
// JSONAPI space. If the given value is supposed to be stored as a
// relationship in JSONAPI, the second return value will be true.
Expand Down
31 changes: 31 additions & 0 deletions controller/work_item_events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,4 +600,35 @@ func (s *TestEvent) TestListEvent() {
// })
}
})

s.T().Run("event list ok - workitem type change", func(t *testing.T) {
fxt := tf.NewTestFixture(t, s.DB, tf.CreateWorkItemEnvironment(), tf.WorkItems(1), tf.WorkItemTypes(2))
svc := testsupport.ServiceAsSpaceUser("Event-Service", *fxt.Identities[0], &TestSpaceAuthzService{*fxt.Identities[0], ""})
EventCtrl := NewEventsController(svc, s.GormDB, s.Configuration)
workitemCtrl := NewWorkitemController(svc, s.GormDB, s.Configuration)
payload := app.UpdateWorkitemPayload{
Data: &app.WorkItem{
Type: APIStringTypeWorkItem,
ID: &fxt.WorkItems[0].ID,
Attributes: map[string]interface{}{
workitem.SystemVersion: fxt.WorkItems[0].Version,
},
Relationships: &app.WorkItemRelationships{
BaseType: &app.RelationBaseType{
Data: &app.BaseTypeData{
ID: fxt.WorkItemTypes[1].ID,
Type: APIStringTypeWorkItemType,
},
},
},
},
}
test.UpdateWorkitemOK(t, svc.Context, svc, workitemCtrl, fxt.WorkItems[0].ID, &payload)
res, eventList := test.ListWorkItemEventsOK(t, svc.Context, svc, EventCtrl, fxt.WorkItems[0].ID, nil, nil)
safeOverriteHeader(t, res, app.ETag, "1GmclFDDPcLR1ZWPZnykWw==")
require.NotEmpty(t, eventList)
require.Len(t, eventList.Data, 1)
compareWithGoldenAgnostic(t, filepath.Join(s.testDir, "list", "ok-witype-change.res.payload.golden.json"), eventList)
compareWithGoldenAgnostic(t, filepath.Join(s.testDir, "list", "ok-witype-change.res.headers.golden.json"), res.Header())
})
}
62 changes: 52 additions & 10 deletions controller/workitemtype.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,26 @@ func ConvertWorkItemTypeFromModel(request *http.Request, t *workitem.WorkItemTyp
return converted
}

// converts the field type from modesl to app representation
// converts the field type from model to app representation
func ConvertFieldTypeFromModel(t workitem.FieldType) app.FieldType {
result := app.FieldType{}
result.Kind = string(t.GetKind())
switch t2 := t.(type) {
switch modelFieldType := t.(type) {
case workitem.ListType:
result.ComponentType = ptr.String(string(t2.ComponentType.GetKind()))
result.ComponentType = ptr.String(string(modelFieldType.ComponentType.GetKind()))
if modelFieldType.DefaultValue != nil {
result.DefaultValue = &modelFieldType.DefaultValue
}
case workitem.EnumType:
result.BaseType = ptr.String(string(t2.BaseType.GetKind()))
result.Values = t2.Values
result.BaseType = ptr.String(string(modelFieldType.BaseType.GetKind()))
result.Values = modelFieldType.Values
if modelFieldType.DefaultValue != nil {
result.DefaultValue = &modelFieldType.DefaultValue
}
case workitem.SimpleType:
if modelFieldType.DefaultValue != nil {
result.DefaultValue = &modelFieldType.DefaultValue
}
}

return result
Expand All @@ -130,7 +140,19 @@ func ConvertFieldTypeToModel(t app.FieldType) (workitem.FieldType, error) {
if !componentType.IsSimpleType() {
return nil, fmt.Errorf("Component type is not list type: %T", componentType)
}
return workitem.ListType{workitem.SimpleType{*kind}, workitem.SimpleType{*componentType}}, nil
listType := workitem.ListType{
SimpleType: workitem.SimpleType{Kind: *kind},
ComponentType: workitem.SimpleType{Kind: *componentType},
}
// convert list default value from app to model
if t.DefaultValue != nil {
fieldType, err := listType.SetDefaultValue(*t.DefaultValue)
if err != nil {
return nil, errs.Wrapf(err, "failed to convert default list value: %+v", *t.DefaultValue)
}
return fieldType, nil
}
return listType, nil
case workitem.KindEnum:
bt, err := workitem.ConvertAnyToKind(*t.BaseType)
if err != nil {
Expand All @@ -139,24 +161,44 @@ func ConvertFieldTypeToModel(t app.FieldType) (workitem.FieldType, error) {
if !bt.IsSimpleType() {
return nil, fmt.Errorf("baseType type is not list type: %T", bt)
}
baseType := workitem.SimpleType{*bt}
baseType := workitem.SimpleType{Kind: *bt}

// convert enum values from app to model
values := t.Values
converted, err := workitem.ConvertList(func(ft workitem.FieldType, element interface{}) (interface{}, error) {
return ft.ConvertToModel(element)
}, baseType, values)
if err != nil {
return nil, errs.WithStack(err)
}
return workitem.EnumType{ // TODO(kwk): handle RewritableValues here?

enumType := workitem.EnumType{ // TODO(kwk): handle RewritableValues here?
SimpleType: workitem.SimpleType{
Kind: *kind,
},
BaseType: baseType,
Values: converted,
}, nil
}
// convert enum default value from app to model
if t.DefaultValue != nil {
fieldType, err := enumType.SetDefaultValue(*t.DefaultValue)
if err != nil {
return nil, errs.Wrapf(err, "failed to convert default enum value: %+v", *t.DefaultValue)
}
return fieldType, nil
}
return enumType, nil
default:
return workitem.SimpleType{*kind}, nil
simpleType := workitem.SimpleType{Kind: *kind}
// convert simple type default value from app to model
if t.DefaultValue != nil {
fieldType, err := simpleType.SetDefaultValue(*t.DefaultValue)
if err != nil {
return nil, errs.Wrapf(err, "failed to convert default simple type value: %+v", *t.DefaultValue)
}
return fieldType, nil
}
return simpleType, nil
}
}

Expand Down
2 changes: 1 addition & 1 deletion design/workitemtype.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var fieldType = a.Type("fieldType", func() {
a.Attribute("componentType", d.String, "The kind of type of the individual elements for a list type. Required for list types. Must be a simple type, not enum or list")
a.Attribute("baseType", d.String, "The kind of type of the enumeration values for an enum type. Required for enum types. Must be a simple type, not enum or list")
a.Attribute("values", a.ArrayOf(d.Any), "The possible values for an enum type. The values must be of a type convertible to the base type")

a.Attribute("defaultValue", d.Any, "Optional default value (if any)")
a.Required("kind")
})

Expand Down
11 changes: 11 additions & 0 deletions id/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ func (s Slice) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}

// Contains returns true if the slice contains the given ID; otherwise false is
// returned.
func (s Slice) Contains(v uuid.UUID) bool {
for _, i := range s {
if i == v {
return true
}
}
return false
}

// Ensure Slice implements the sort.Interface
var _ sort.Interface = Slice{}
var _ sort.Interface = (*Slice)(nil)
8 changes: 8 additions & 0 deletions id/slice_blackbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,11 @@ func TestToStringSlice(t *testing.T) {
s := id.Slice{a, b, c}
require.Equal(t, []string{a.String(), b.String(), c.String()}, s.ToStringSlice())
}

func TestSlice_Contains(t *testing.T) {
a := uuid.FromStringOrNil("cb4364bf-893c-4ac2-a35f-4ef74c212e88")
b := uuid.FromStringOrNil("d085a858-6b98-44ce-8777-b36d927b07dc")
require.True(t, id.Slice{a, b}.Contains(a))
require.False(t, id.Slice{}.Contains(a))
require.False(t, id.Slice{a}.Contains(b))
}
2 changes: 2 additions & 0 deletions spacetemplate/assets/agile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ work_item_types:
- SEV2 - High
- SEV3 - Medium
- SEV4 - Low
default_value: SEV3 - Medium
"priority":
label: Priority
description: The order in which the developer should resolve a defect.
Expand All @@ -137,6 +138,7 @@ work_item_types:
- P2 - High
- P3 - Medium
- P4 - Low
default_value: P3 - Medium
"resolution":
label: Resolution
description: >
Expand Down
2 changes: 2 additions & 0 deletions spacetemplate/assets/scrum.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ work_item_types:
- Minor
- Optional
- Trivial
default_value: Minor

- id: &impedimentID "ec6918d6-f732-4fc0-a902-6571415aa73c"
extends: *scrumCommonTypeID
Expand Down Expand Up @@ -178,6 +179,7 @@ work_item_types:
- High
- Medium
- Low
default_value: Medium
"found_in":
label: Found in
description: >
Expand Down
6 changes: 5 additions & 1 deletion spacetemplate/importer/import_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,15 @@ func (s *ImportHelper) Validate() error {
return errs.Wrap(err, "failed to validate space template")
}

// Ensure all artifacts have the correct space template ID set
// Ensure all artifacts have the correct space template ID set and are
// valid
for _, wit := range s.WITs {
if wit.SpaceTemplateID != s.Template.ID {
return errors.NewBadParameterError("work item types's space template ID", wit.SpaceTemplateID.String()).Expected(s.Template.ID.String())
}
if err := wit.Validate(); err != nil {
return errs.Wrapf(err, `failed to validate work item type "%s" (ID=%s)`, wit.Name, wit.ID)
}
}
for _, wilt := range s.WILTs {
if wilt.SpaceTemplateID != s.Template.ID {
Expand Down
Loading

0 comments on commit 41e967d

Please sign in to comment.