|
|
package common
|
|
|
|
|
|
import (
|
|
|
"errors"
|
|
|
"fmt"
|
|
|
"time"
|
|
|
|
|
|
"github.com/imroc/req/v3"
|
|
|
"github.com/tidwall/gjson"
|
|
|
)
|
|
|
|
|
|
const API_tbapi = "http://qa.flatincbr.work:5354"
|
|
|
|
|
|
type BugInfo struct {
|
|
|
ProjectName string `json:"project_name"` // tb项目名称
|
|
|
ProjectID string `json:"project_id"` // tb项目id
|
|
|
ExecutorID string `json:"executor_id"` // tb缺陷的处理人
|
|
|
Title string `json:"title"` // tb缺陷的标题
|
|
|
Content string `json:"content"` // tb缺陷的备注
|
|
|
InvolveMembers []string `json:"involve_members"` // tb缺陷的参与人
|
|
|
Pf string `json:"pf"` // 所属平台,除了adr/ios其它不处理
|
|
|
}
|
|
|
|
|
|
func NewBug(project_name string) BugInfo {
|
|
|
var v BugInfo
|
|
|
v.ProjectName = project_name
|
|
|
return v
|
|
|
}
|
|
|
|
|
|
// 指定执行者
|
|
|
func (b *BugInfo) SetExecutor(id string) *BugInfo {
|
|
|
b.ExecutorID = id
|
|
|
return b
|
|
|
}
|
|
|
|
|
|
// 指定参与者
|
|
|
func (b *BugInfo) SetInvolveMember(id ...string) *BugInfo {
|
|
|
b.InvolveMembers = id
|
|
|
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.Pf = 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/tb/v2/bug/create")
|
|
|
if err != nil {
|
|
|
fmt.Println("Teambition提单失败:", err)
|
|
|
return "", err
|
|
|
}
|
|
|
if resp.IsErrorState() {
|
|
|
fmt.Println("Teambition提单失败:", resp.StatusCode, resp.String())
|
|
|
return "", err
|
|
|
}
|
|
|
bug_id := gjson.Get(resp.String(), "data").String()
|
|
|
if len(bug_id) == 0 {
|
|
|
return "", errors.New("请求成功,但返回bug_id为空")
|
|
|
}
|
|
|
fmt.Println("Teambition提单成功, id =", bug_id)
|
|
|
|
|
|
return bug_id, nil
|
|
|
}
|