You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
2.1 KiB
Go

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package common
import (
"errors"
"fmt"
"time"
"github.com/imroc/req/v3"
"github.com/tidwall/gjson"
)
const API_tbapi = "http://qa.flatincbr.work:5354"
const BugCategory_Anomaly = "monkey异常"
const BugCategory_Anomaly_adr = "monkey异常-安卓端"
const BugCategory_Anomaly_ios = "monkey异常-iOS端"
type BugInfo struct {
ProjectName string `json:"project_name"` // tb项目名称
Category string `json:"category"` // 提单配置中的缺陷类型
Title string `json:"title"` // tb缺陷的标题
Content string `json:"content"` // tb缺陷的备注
Platform string `json:"platform"` // 所属平台除了adr/ios其它不处理
}
func NewBug(project_name string) BugInfo {
var v BugInfo
v.ProjectName = project_name
return v
}
// 设置类别
func (b *BugInfo) SetCategory(category string) *BugInfo {
b.Category = category
return b
}
// 设置标题
func (b *BugInfo) SetTitle(title string) *BugInfo {
b.Title = title
return b
}
// 设置备注内容
func (b *BugInfo) SetContent(content string) *BugInfo {
b.Content = content
return b
}
// 设置所属平台adr/ios
func (b *BugInfo) SetPlatform(pf string) *BugInfo {
b.Platform = pf
return b
}
func (b *BugInfo) Create() (string, error) {
// buf, err := json.Marshal(b)
// if err != nil {
// fmt.Println("序列化失败:", err)
// return "", err
// }
// fmt.Println(string(buf))
client := req.C().
SetTimeout(10 * time.Second)
resp, err := client.R().
SetBodyJsonMarshal(b).
Post(API_tbapi + "/api/bug/v2/create")
if err != nil {
fmt.Println("Teambition提单失败", err)
return "", err
}
if resp.IsErrorState() {
fmt.Println("Teambition提单失败", resp.StatusCode, resp.String())
return "", err
}
if gjson.Get(resp.String(), "code").Int() != 200 {
return "", errors.New(gjson.Get(resp.String(), "msg").String())
}
bug_id := gjson.Get(resp.String(), "data").String()
if len(bug_id) == 0 {
fmt.Println(resp.String())
return "", errors.New("请求成功但返回bug_id为空")
}
fmt.Println("Teambition提单成功, id =", bug_id)
return bug_id, nil
}