|
|
package test
|
|
|
|
|
|
import (
|
|
|
"autogo/common"
|
|
|
"autogo/dbsql"
|
|
|
"autogo/models"
|
|
|
"fmt"
|
|
|
"strings"
|
|
|
|
|
|
"github.com/spf13/cast"
|
|
|
)
|
|
|
|
|
|
func GetMonkeyResult() {
|
|
|
var ano models.MonkeyAnomaly
|
|
|
dbsql.SetDSN("Flatincbr.com")
|
|
|
db, err := dbsql.GetConn(dbsql.DSN_local)
|
|
|
if err != nil {
|
|
|
fmt.Println(err)
|
|
|
return
|
|
|
}
|
|
|
defer dbsql.Close(db)
|
|
|
db.Model(models.MonkeyAnomaly{}).Last(&ano)
|
|
|
|
|
|
var task models.MonkeyTask
|
|
|
db.Table(task.TableName()).Model(models.MonkeyTask{}).Where("id = ?", ano.TaskId).Last(&task)
|
|
|
|
|
|
bug_type := "Other"
|
|
|
if strings.Contains(ano.AnomalyInfos, "FATAL EXCEPTION") {
|
|
|
bug_type = "EXCEPTION"
|
|
|
}
|
|
|
|
|
|
content := "**异常ID:**" + cast.ToString(ano.ID) + " "
|
|
|
content += "**关联Monkey报告:** [点击查看](http://qa.flatincbr.work/#/monkey/result/" + cast.ToString(ano.TaskId) + ")" + "\n\n<br>\n\n"
|
|
|
content += "**上报时间:**" + ano.CreateTime.Format("2006-01-02 15:04:05") + "\n\n<br>\n\n"
|
|
|
content += "**应用版本:**" + task.Version + "\n\n<br>\n\n"
|
|
|
content += "**信息预览:**" + "\n\n"
|
|
|
|
|
|
title := "【Monkey测试】"
|
|
|
|
|
|
ano.JsonReady()
|
|
|
for i, v := range ano.Anomalies {
|
|
|
for ii, vv := range strings.Split(v, "\n") {
|
|
|
content += "> " + vv + "\n"
|
|
|
switch bug_type {
|
|
|
case "EXCEPTION":
|
|
|
// 取第一行和第三行内容拼接
|
|
|
if i == 0 && ii == 0 {
|
|
|
_strs := strings.Split(vv, "): ")
|
|
|
if len(_strs) > 1 {
|
|
|
title += _strs[1] + " - "
|
|
|
}
|
|
|
} else if i == 0 && ii == 2 {
|
|
|
_strs := strings.Split(vv, "): ")
|
|
|
if len(_strs) > 1 {
|
|
|
title += _strs[1]
|
|
|
}
|
|
|
}
|
|
|
default:
|
|
|
if i == 0 && ii == 0 {
|
|
|
title += "未知异常 - " + vv
|
|
|
}
|
|
|
}
|
|
|
if ii > 10 {
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
content += "> " + "——————————————————————" + "\n"
|
|
|
}
|
|
|
content += "> " + "(...更多请查看Monkey报告)" + "\n"
|
|
|
content += "\n"
|
|
|
|
|
|
bug := common.NewBug("crushu") //task.Project
|
|
|
|
|
|
bug.SetTitle(title).
|
|
|
SetPlatform(task.Platform).
|
|
|
SetContent(content).
|
|
|
SetCategory(common.BugCategory_Anomaly)
|
|
|
|
|
|
id, err := bug.Create()
|
|
|
if err != nil {
|
|
|
fmt.Println(err)
|
|
|
return
|
|
|
}
|
|
|
fmt.Println("缺陷创建成功:", "https://www.teambition.com/task/"+id)
|
|
|
|
|
|
db.Table(ano.TableName()).Model(models.MonkeyAnomaly{}).Where("id = ?", ano.ID).Update("bug_id", id)
|
|
|
}
|