Skip to content

Commit

Permalink
ticket submission
Browse files Browse the repository at this point in the history
  • Loading branch information
JunyuBD committed Dec 20, 2023
1 parent 9d30aa7 commit 9bc3239
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 6 deletions.
6 changes: 4 additions & 2 deletions pre_oncall_api/pre_oncall_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import (
)

const (
preOncallToken = "26ad213fcdc54e0da3a6e7fc79e99b75"
preOncallPrefix = "https://lark-oncall.bytedance.net"
//preOncallToken = "26ad213fcdc54e0da3a6e7fc79e99b75"
preOncallToken = "98d2d83a05094e6585f93b31f851d53c"
//preOncallPrefix = "https://lark-oncall.bytedance.net"
preOncallPrefix = "https://lark-oncall-boe.byted.org"
)

func preOncallAPIError(ctx context.Context, err error) error {
Expand Down
72 changes: 68 additions & 4 deletions pre_oncall_service/canvas_constructor.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func InitRelatedTicketCanvas(ctx context.Context, oncallTickets pre_oncall.Ticke
}

// InitCreateOncalTicketCanvas is a constructor for Create Create-Ticket CanvasReponse
func InitCreateOncalTicketCanvas(bizLines []string, regions []string, stackNames []string, selectedValues map[string]string, validInput bool) CanvasReponse {
func InitCreateOncalTicketCanvas(bizLines []string, regions []string, stackNames []string, selectedValues map[string]string, ticketCreationStatus string) CanvasReponse {
if selectedValues == nil {
selectedValues = make(map[string]string)
}
Expand Down Expand Up @@ -178,13 +178,25 @@ func InitCreateOncalTicketCanvas(bizLines []string, regions []string, stackNames
// Create button to submit ticket
submitTicketBtn := NewButton(SubmitTicketButtonID, SubmitTicketLabel, action, "primary", false)

content := newContent([]Component{categorySelect, bizLineText, bizLineSearchInput, bizLineSearchBtn,
components := []Component{categorySelect, bizLineText, bizLineSearchInput, bizLineSearchBtn,
bizLineSearchDropDown, ticketTitleText, ticketTitleInput, regionSearchText, regionSearchInput, regionSearchBtn, regionSearchDropDown,
stackSearchText, stackSearchDropDown, priorityText, prioritySingleSelect,
createGroupText, createGroupSingleSelect, userIDText, userIDInput,
tenantIDText, tenantIDInput,
larkVersionText, larkVersionInput,
submitTicketBtn})
submitTicketBtn}

switch ticketCreationStatus {
case WaitingUserInput:
case CreatTicketFailed:
failedText := NewText("Create ticket failed, please check your input and try again", "header")
components = append(components, failedText)
case CreateTicketSucceed:
succeedText := NewText("Create ticket succeed, please do not submit again", "header")
components = append(components, succeedText)
}

content := newContent(components)

//content := newContent([]Component{categorySelect, bizLineText, bizLineSearchInput, bizLineSearchBtn, bizLineSearchDropDown})

Expand Down Expand Up @@ -307,6 +319,8 @@ func GetCreateTicketCanvasBody(ctx context.Context, inputValues map[string]strin
// return InitPreOncallCanvas()
//}

ticketStatus := WaitingUserInput

bizLines := extractBizlinesFromCurrentCanvas(ctx, currentCanvas)
regions := extractRegionsFromCurrentCanvas(ctx, currentCanvas)
stackNames := extractStackNamesFromCurrentCanvas(ctx, currentCanvas)
Expand Down Expand Up @@ -423,5 +437,55 @@ func GetCreateTicketCanvasBody(ctx context.Context, inputValues map[string]strin
regions = searchRegion(ctx, regionSearchKeyword, regionList)
}

return InitCreateOncalTicketCanvas(bizLines, regions, stackNames, inputValues, true)
if buttonClick == SubmitTicketButtonID {
if !validSubmitForm(ctx, inputValues) {
fmt.Printf("GetCreateTicketCanvasBody validSubmitForm failed \n")
ticketStatus = CreatTicketFailed
} else {
fmt.Printf("GetCreateTicketCanvasBody validSubmitForm success \n")
ticket := pre_oncall.TicketSubmitRequest{
Title: "",
Business: "",
Priority: "",
Stack: "",
Region: "",
UserId: "",
Version: "",
CreateChatWay: "",
Type: "",
App: "",
External: "",
Source: "",
Reporter: "",
Remarks: "",
ChannelType: "",
BizTicketId: "",
}
resp, err := pre_oncall.SubmitFakePreOncallTicket(ctx, ticket)
fmt.Printf("GetCreateTicketCanvasBody SubmitPreOncallTicket resp %v \n", larkcore.Prettify(resp))
if err != nil {
//log..Errorf("GetCreateTicketCanvasBody SubmitPreOncallTicket err %v", err)
fmt.Printf("GetCreateTicketCanvasBody SubmitPreOncallTicket err %v \n", err)
ticketStatus = CreatTicketFailed
} else {
ticketStatus = CreateTicketSucceed
}
}
}

return InitCreateOncalTicketCanvas(bizLines, regions, stackNames, inputValues, ticketStatus)
}

func validSubmitForm(ctx context.Context, inputValues map[string]string) bool {
//log. := utils.Get//log.gerWithMethod(ctx, "validSubmitForm")
//log..Infof("validSubmitForm inputValues %v", inputValues)

if inputValues == nil {
return false
}
if _, ok := inputValues[BizLineSearchDropdownID]; !ok {
return false
}

return true
}
4 changes: 4 additions & 0 deletions pre_oncall_service/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,8 @@ const (

RegionSearchDropdownID = "regionSearchDropdown"
RegionSearchDropdownLabel = "regionSearchDropdownLabel"

WaitingUserInput = "waitingUserInput"
CreatTicketFailed = "creatTicketFailed"
CreateTicketSucceed = "createTicketSucceed"
)
2 changes: 2 additions & 0 deletions pre_oncall_service/preoncall_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ func HandlePreoncallCanvasSubmitAction(ctx context.Context, body string) (Canvas
response = GetCreateTicketCanvasBody(ctx, inputValues, intercomConversationID, assigneeID, BizLineSearchButtonID, canvasReq.CurrentCanvas)
case RegionSearchButtonID:
response = GetCreateTicketCanvasBody(ctx, inputValues, intercomConversationID, assigneeID, RegionSearchButtonID, canvasReq.CurrentCanvas)
case SubmitTicketButtonID:
response = GetCreateTicketCanvasBody(ctx, inputValues, intercomConversationID, assigneeID, SubmitTicketButtonID, canvasReq.CurrentCanvas)
}

//log..Infof("HandlePreoncallCanvasSubmitAction vanvas response %v", larkcore.Prettify(response))
Expand Down

0 comments on commit 9bc3239

Please sign in to comment.