ut_dash.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. package http
  2. import (
  3. "go-common/app/admin/main/apm/conf"
  4. "go-common/app/admin/main/apm/model/ut"
  5. bm "go-common/library/net/http/blademaster"
  6. )
  7. // @params PCurveReq
  8. // @router get /x/admin/apm/ut/dashboard/pcurve
  9. // @response PCurveResp
  10. func utDashCurve(c *bm.Context) {
  11. var (
  12. curve []*ut.PCurveResp
  13. err error
  14. )
  15. v := new(ut.PCurveReq)
  16. if err = c.Bind(v); err != nil {
  17. return
  18. }
  19. if curve, err = apmSvc.DashCurveGraph(c, name(c), v); err != nil {
  20. c.JSON(nil, err)
  21. return
  22. }
  23. c.JSON(curve, nil)
  24. }
  25. // @params PCurveReq
  26. // @router get /x/admin/apm/ut/dashboard/histogram
  27. // @response PCurveDetailResp
  28. func utDashHistogram(c *bm.Context) {
  29. var (
  30. histogram []*ut.PCurveDetailResp
  31. err error
  32. )
  33. v := new(ut.PCurveReq)
  34. if err = c.Bind(v); err != nil {
  35. return
  36. }
  37. if histogram, err = apmSvc.DashGraphDetail(c, name(c), v); err != nil {
  38. c.JSON(nil, err)
  39. return
  40. }
  41. c.JSON(histogram, nil)
  42. }
  43. // @params PCurveReq
  44. // @router get /x/admin/apm/ut/dashboard/user/detail
  45. // @response PCurveDetailResp
  46. func utDashUserDetail(c *bm.Context) {
  47. var (
  48. detail []*ut.PCurveDetailResp
  49. err error
  50. )
  51. v := new(ut.PCurveReq)
  52. if err = c.Bind(v); err != nil {
  53. return
  54. }
  55. if detail, err = apmSvc.DashGraphDetailSingle(c, name(c), v); err != nil {
  56. c.JSON(nil, err)
  57. return
  58. }
  59. c.JSON(detail, nil)
  60. }
  61. // @params QATrendReq
  62. // @router get /x/admin/apm/ut/quality/trend
  63. // @response QATrendResp
  64. func utQATrend(c *bm.Context) {
  65. var (
  66. trend *ut.QATrendResp
  67. err error
  68. )
  69. v := new(ut.QATrendReq)
  70. if err = c.Bind(v); err != nil {
  71. return
  72. }
  73. if trend, err = apmSvc.QATrend(c, v); err != nil {
  74. c.JSON(nil, err)
  75. return
  76. }
  77. c.JSON(trend, nil)
  78. }
  79. // @params commits
  80. // @router get /x/admin/apm/ut/commits
  81. // @response CommitInfo
  82. func utGeneralCommit(c *bm.Context) {
  83. var (
  84. cmInfos []*ut.CommitInfo
  85. err error
  86. )
  87. v := new(struct {
  88. Commits string `form:"commits"`
  89. })
  90. if err = c.Bind(v); err != nil {
  91. return
  92. }
  93. if cmInfos, err = apmSvc.UTGernalCommit(c, v.Commits); err != nil {
  94. c.JSON(nil, err)
  95. return
  96. }
  97. c.JSON(cmInfos, nil)
  98. }
  99. // @params pkg
  100. // @router get /x/admin/apm/ut/dashboard/pkgs
  101. // @response []*ut.PkgAnls
  102. func utDashPkgsTree(c *bm.Context) {
  103. var (
  104. err error
  105. pkgs []*ut.PkgAnls
  106. username = name(c)
  107. req = new(struct {
  108. PKG string `form:"pkg"`
  109. })
  110. )
  111. if err = c.Bind(req); err != nil {
  112. c.JSON(nil, err)
  113. return
  114. }
  115. if pkgs, err = apmSvc.DashPkgsTree(c, req.PKG, username); err != nil {
  116. c.JSON(nil, err)
  117. return
  118. }
  119. c.JSON(pkgs, nil)
  120. }
  121. // @params project_id,merge_id,commit_id
  122. // @router get /x/admin/apm/ut/git/report
  123. // @response EmptyResp
  124. func utGitReport(c *bm.Context) {
  125. var (
  126. err error
  127. req = new(struct {
  128. ProjectID int `form:"project_id" validate:"required"`
  129. MergeID int `form:"merge_id" validate:"required"`
  130. CommitID string `form:"commit_id" validate:"required"`
  131. })
  132. )
  133. if err = c.Bind(req); err != nil {
  134. c.JSON(nil, err)
  135. return
  136. }
  137. if err = apmSvc.GitReport(c, req.ProjectID, req.MergeID, req.CommitID); err != nil {
  138. c.JSON(nil, err)
  139. return
  140. }
  141. }
  142. // @params username,times
  143. // @router get /x/admin/apm/ut/dashboard/history/commit
  144. // @response []*ut.PkgAnls
  145. func dashHistoryCommit(c *bm.Context) {
  146. var (
  147. err error
  148. pkgs = make([]*ut.PkgAnls, 0)
  149. req = new(struct {
  150. UserName string `form:"user_name" default:""`
  151. Times int64 `form:"times" default:"10"`
  152. })
  153. )
  154. if err = c.Bind(req); err != nil {
  155. c.JSON(nil, err)
  156. return
  157. }
  158. if req.UserName == "" {
  159. req.UserName = name(c)
  160. }
  161. if pkgs, err = apmSvc.CommitHistory(c, req.UserName, req.Times); err != nil {
  162. c.JSON(nil, err)
  163. return
  164. }
  165. data := new(struct {
  166. Pkgs []*ut.PkgAnls `json:"pkgs"`
  167. BaseLine struct {
  168. Coverage int `json:"coverage"`
  169. PassRate int `json:"pass_rate"`
  170. } `json:"base_line"`
  171. })
  172. data.Pkgs = pkgs
  173. data.BaseLine.Coverage = conf.Conf.UTBaseLine.Coverage
  174. data.BaseLine.PassRate = conf.Conf.UTBaseLine.Passrate
  175. c.JSON(data, nil)
  176. }