Skip to content

Commit

Permalink
[v17] ListUserTasks WebAPI: include issue type title (#52786)
Browse files Browse the repository at this point in the history
* ListUserTasks WebAPI: include issue type title

* Update lib/web/ui/usertask.go

Co-authored-by: STeve (Xin) Huang <[email protected]>

* Update lib/web/ui/usertask.go

Co-authored-by: Edoardo Spadolini <[email protected]>

---------

Co-authored-by: STeve (Xin) Huang <[email protected]>
Co-authored-by: Edoardo Spadolini <[email protected]>
  • Loading branch information
3 people authored Mar 5, 2025
1 parent ef999a5 commit 61afd2a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
31 changes: 22 additions & 9 deletions lib/web/ui/usertask.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ type UserTask struct {
State string `json:"state,omitempty"`
// IssueType identifies this task's issue type.
IssueType string `json:"issueType,omitempty"`
// Title is the issue title.
Title string `json:"title,omitempty"`
// Integration is the Integration Name this User Task refers to.
Integration string `json:"integration,omitempty"`
// LastStateChange indicates when the current's user task state was last changed.
Expand All @@ -49,8 +51,6 @@ type UserTask struct {
type UserTaskDetail struct {
// UserTask has the basic fields that all tasks include.
UserTask
// Title is the issue title.
Title string `json:"title,omitempty"`
// Description is a markdown document that explains the issue and how to fix it.
Description string `json:"description,omitempty"`
// DiscoverEC2 contains the task details for the DiscoverEC2 tasks.
Expand Down Expand Up @@ -99,44 +99,57 @@ func MakeUserTasks(uts []*usertasksv1.UserTask) []UserTask {

// MakeDetailedUserTask creates a UI UserTask representation containing all the details.
func MakeDetailedUserTask(ut *usertasksv1.UserTask) UserTaskDetail {
var title string
var description string

var discoverEC2 *usertasks.UserTaskDiscoverEC2WithURLs
var discoverEKS *usertasks.UserTaskDiscoverEKSWithURLs
var discoverRDS *usertasks.UserTaskDiscoverRDSWithURLs

switch ut.GetSpec().GetTaskType() {
case apiusertasks.TaskTypeDiscoverEC2:
title, description = usertasks.DescriptionForDiscoverEC2Issue(ut.GetSpec().GetIssueType())
discoverEC2 = usertasks.EC2InstancesWithURLs(ut)

case apiusertasks.TaskTypeDiscoverEKS:
title, description = usertasks.DescriptionForDiscoverEKSIssue(ut.GetSpec().GetIssueType())
discoverEKS = usertasks.EKSClustersWithURLs(ut)

case apiusertasks.TaskTypeDiscoverRDS:
title, description = usertasks.DescriptionForDiscoverRDSIssue(ut.GetSpec().GetIssueType())
discoverRDS = usertasks.RDSDatabasesWithURLs(ut)
}

_, description := userTaskTitleAndDescription(ut)

return UserTaskDetail{
UserTask: MakeUserTask(ut),
Title: title,
Description: description,
DiscoverEC2: discoverEC2,
DiscoverEKS: discoverEKS,
DiscoverRDS: discoverRDS,
}
}

func userTaskTitleAndDescription(ut *usertasksv1.UserTask) (string, string) {
switch ut.GetSpec().GetTaskType() {
case apiusertasks.TaskTypeDiscoverEC2:
return usertasks.DescriptionForDiscoverEC2Issue(ut.GetSpec().GetIssueType())

case apiusertasks.TaskTypeDiscoverEKS:
return usertasks.DescriptionForDiscoverEKSIssue(ut.GetSpec().GetIssueType())

case apiusertasks.TaskTypeDiscoverRDS:
return usertasks.DescriptionForDiscoverRDSIssue(ut.GetSpec().GetIssueType())

default:
return "", ""
}
}

// MakeUserTask creates a UI UserTask representation.
func MakeUserTask(ut *usertasksv1.UserTask) UserTask {
title, _ := userTaskTitleAndDescription(ut)
return UserTask{
Name: ut.GetMetadata().GetName(),
TaskType: ut.GetSpec().GetTaskType(),
State: ut.GetSpec().GetState(),
IssueType: ut.GetSpec().GetIssueType(),
Title: title,
Integration: ut.GetSpec().GetIntegration(),
LastStateChange: ut.GetStatus().GetLastStateChange().AsTime(),
}
Expand Down
1 change: 1 addition & 0 deletions lib/web/usertasks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func TestUserTask(t *testing.T) {
err = json.Unmarshal(resp.Bytes(), &listResponse)
require.NoError(t, err)
require.NotEmpty(t, listResponse.Items)
require.NotEmpty(t, listResponse.Items[0].Title)
listedTasks = append(listedTasks, listResponse.Items...)

if listResponse.NextKey == "" {
Expand Down

0 comments on commit 61afd2a

Please sign in to comment.