ut.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. package http
  2. import (
  3. "go-common/app/admin/main/apm/conf"
  4. "go-common/app/admin/main/apm/model/ut"
  5. saga "go-common/app/tool/saga/model"
  6. bm "go-common/library/net/http/blademaster"
  7. "go-common/library/net/http/blademaster/binding"
  8. )
  9. // @params ListReq
  10. // @router get /x/admin/apm/ut/info/list
  11. // @response Paper
  12. func utList(c *bm.Context) {
  13. var (
  14. mrInfs []*ut.Merge
  15. data *Paper
  16. err error
  17. count int
  18. )
  19. v := new(ut.MergeReq)
  20. if err = c.Bind(v); err != nil {
  21. return
  22. }
  23. if mrInfs, count, err = apmSvc.UtList(c, v); err != nil {
  24. c.JSON(nil, err)
  25. return
  26. }
  27. data = &Paper{
  28. Total: count,
  29. Pn: v.Pn,
  30. Ps: v.Ps,
  31. Items: mrInfs,
  32. }
  33. c.JSON(data, nil)
  34. }
  35. // @params DetailReq
  36. // @router get /x/admin/apm/ut/detail/list
  37. // @response PkgAnls
  38. func utDetail(c *bm.Context) {
  39. var (
  40. utpkgs []*ut.PkgAnls
  41. err error
  42. )
  43. v := new(ut.DetailReq)
  44. if err = c.Bind(v); err != nil {
  45. return
  46. }
  47. if utpkgs, err = apmSvc.UtDetailList(c, v); err != nil {
  48. c.JSON(nil, err)
  49. return
  50. }
  51. c.JSON(utpkgs, nil)
  52. }
  53. // @params HistoryCommitReq
  54. // @router get /x/admin/apm/ut/history/commit
  55. // @response Commit
  56. func utHistoryCommit(c *bm.Context) {
  57. var (
  58. utcmts []*ut.Commit
  59. count int
  60. err error
  61. data *Paper
  62. )
  63. v := new(ut.HistoryCommitReq)
  64. if err = c.Bind(v); err != nil {
  65. return
  66. }
  67. if utcmts, count, err = apmSvc.UtHistoryCommit(c, v); err != nil {
  68. c.JSON(nil, err)
  69. return
  70. }
  71. data = &Paper{
  72. Total: count,
  73. Pn: v.Pn,
  74. Ps: v.Ps,
  75. Items: utcmts,
  76. }
  77. c.JSON(data, nil)
  78. }
  79. func utBaseline(c *bm.Context) {
  80. data := map[string]int{
  81. "coverage": conf.Conf.UTBaseLine.Coverage,
  82. "passrate": conf.Conf.UTBaseLine.Passrate,
  83. }
  84. c.JSON(data, nil)
  85. }
  86. // @params commit_id
  87. // @router get /x/admin/apm/ut/check
  88. // @response Tyrant
  89. func check(c *bm.Context) {
  90. var (
  91. err error
  92. ty *ut.Tyrant
  93. res = new(struct {
  94. CommitID string `form:"commit_id" validate:"required"`
  95. })
  96. )
  97. if err = c.Bind(res); err != nil {
  98. c.JSON(nil, err)
  99. return
  100. }
  101. if ty, err = apmSvc.CheckUT(c, res.CommitID); err != nil {
  102. c.JSON(nil, err)
  103. return
  104. }
  105. c.JSON(ty, nil)
  106. }
  107. // @params merge_id
  108. // @router get /x/admin/apm/ut/merge/set
  109. // @response message
  110. func utSetMerged(c *bm.Context) {
  111. var (
  112. err error
  113. hookMR = &saga.HookMR{}
  114. )
  115. if err = c.BindWith(hookMR, binding.JSON); err != nil {
  116. return
  117. }
  118. if hookMR.ObjectAttributes.State != "merged" {
  119. c.JSON(nil, nil)
  120. return
  121. }
  122. if err = apmSvc.SetMerged(c, hookMR.ObjectAttributes.IID); err != nil {
  123. c.JSON(nil, err)
  124. return
  125. }
  126. if err = apmSvc.WechatReport(c, hookMR.ObjectAttributes.IID, hookMR.ObjectAttributes.LastCommit.ID, hookMR.ObjectAttributes.SourceBranch, hookMR.ObjectAttributes.TargetBranch); err != nil {
  127. c.JSON(nil, err)
  128. return
  129. }
  130. c.JSONMap(map[string]interface{}{
  131. "message": "单元测试is_merged更新成功",
  132. }, nil)
  133. }