forked from Gitlink/gitea-1120-rc1
237 lines
5.2 KiB
Go
237 lines
5.2 KiB
Go
package report
|
|
|
|
import (
|
|
"code.gitea.io/gitea/models"
|
|
"code.gitea.io/gitea/modules/context"
|
|
"fmt"
|
|
"net/http"
|
|
"strconv"
|
|
"time"
|
|
)
|
|
|
|
func GetActivity(ctx *context.APIContext) {
|
|
// swagger:operation GET /activity activity activity
|
|
// ---
|
|
// summary: Statistics of commit and pull request data,Platform required data **
|
|
// produces:
|
|
// - application/json
|
|
// parameters:
|
|
// - name: from
|
|
// in: query
|
|
// description: Query begin timestamp
|
|
// type: string
|
|
// required: false
|
|
// - name: to
|
|
// in: query
|
|
// description: Query end timestamp
|
|
// type: string
|
|
// required: false
|
|
// responses:
|
|
// "200":
|
|
// "$ref": "#/responses/"
|
|
// "404":
|
|
// "$ref": "#/responses/notFound"
|
|
|
|
opt:=GetParamOption(ctx)
|
|
if opt==nil {
|
|
return
|
|
}
|
|
list, err := models.GetActivity(opt)
|
|
if err != nil {
|
|
ctx.ServerError("GetActivity", err)
|
|
return
|
|
}
|
|
ctx.JSON(http.StatusOK,list)
|
|
}
|
|
|
|
|
|
type PrjectDTO struct {
|
|
Project interface{} `json:"project"`
|
|
//Param struct{
|
|
// FromDate string `json:"from_date"`
|
|
// ToDate string `json:"to_date"`
|
|
//} `json:"param"`
|
|
}
|
|
|
|
func GetActivityDevelop(ctx *context.APIContext) {
|
|
// swagger:operation GET /activity/develop activity develop
|
|
// ---
|
|
// summary: Statistics of submitted data by developers **
|
|
// produces:
|
|
// - application/json
|
|
// parameters:
|
|
// - name: from
|
|
// in: query
|
|
// description: Query begin timestamp
|
|
// type: string
|
|
// required: false
|
|
// - name: to
|
|
// in: query
|
|
// description: Query end timestamp
|
|
// type: string
|
|
// required: false
|
|
// - name: top
|
|
// in: query
|
|
// description: Display the previous n records
|
|
// type: integer
|
|
// required: false
|
|
// responses:
|
|
// "200":
|
|
// "$ref": "#/responses"
|
|
// "404":
|
|
// "$ref": "#/responses/notFound"
|
|
|
|
|
|
opt:=GetParamOption(ctx)
|
|
if opt==nil {
|
|
return
|
|
}
|
|
list, err := models.GetActivityDevelop(opt)
|
|
if err != nil {
|
|
ctx.ServerError("GetActivityDevelop", err)
|
|
return
|
|
}
|
|
|
|
data:=DevelopDTO{Develop:list}
|
|
//data.Param.FromDate=opt.FromDate
|
|
//data.Param.ToDate=opt.ToDate
|
|
ctx.JSON(http.StatusOK,data)
|
|
}
|
|
type DevelopDTO struct {
|
|
Develop interface{} `json:"develop"`
|
|
//Param struct {
|
|
// FromDate string `json:"from_date"`
|
|
// ToDate string `json:"to_date"`
|
|
//} `json:"param"`
|
|
}
|
|
|
|
|
|
func GetActivityProject(ctx *context.APIContext) {
|
|
// swagger:operation GET /activity/project activity project
|
|
// ---
|
|
// summary: Statistics of submitted data by project **
|
|
// produces:
|
|
// - application/json
|
|
// parameters:
|
|
// - name: from
|
|
// in: query
|
|
// description: Query begin timestamp
|
|
// type: string
|
|
// required: false
|
|
// - name: to
|
|
// in: query
|
|
// description: Query end timestamp
|
|
// type: string
|
|
// required: false
|
|
// - name: top
|
|
// in: query
|
|
// description: Display the previous n records
|
|
// type: integer
|
|
// required: false
|
|
// responses:
|
|
// "200":
|
|
// "$ref": "#/responses"
|
|
// "404":
|
|
// "$ref": "#/responses/notFound"
|
|
|
|
|
|
opt:=GetParamOption(ctx)
|
|
if opt==nil {
|
|
return
|
|
}
|
|
list, err := models.GetActivityProject(opt)
|
|
if err != nil {
|
|
ctx.ServerError("GetActivityProject", err)
|
|
return
|
|
}
|
|
data:=PrjectDTO{Project:list}
|
|
//data.Param.FromDate=opt.FromDate
|
|
//data.Param.ToDate=opt.ToDate
|
|
ctx.JSON(http.StatusOK,data)
|
|
}
|
|
|
|
|
|
func GetContributors(ctx *context.APIContext) {
|
|
// swagger:operation GET /repos/{owner}/{repo}/contributors repository contributors
|
|
// ---
|
|
// summary: Get all builder information in the repository **
|
|
// produces:
|
|
// - application/json
|
|
// parameters:
|
|
// - name: owner
|
|
// in: path
|
|
// description: owner of the repo
|
|
// type: string
|
|
// required: true
|
|
// - name: repo
|
|
// in: path
|
|
// description: name of the repo
|
|
// type: string
|
|
// required: true
|
|
// responses:
|
|
// "200":
|
|
// "$ref": "#/responses/"
|
|
// "404":
|
|
// "$ref": "#/responses/notFound"
|
|
|
|
opt:= models.GetContributorsOptionsExt{
|
|
UserId:ctx.Repo.Owner.ID,
|
|
RepoId:ctx.Repo.Repository.ID,
|
|
}
|
|
list, err := models.GetContributors(opt)
|
|
if err != nil {
|
|
ctx.ServerError("GetFeedsExt", err)
|
|
return
|
|
}
|
|
ctx.JSON(http.StatusOK,list)
|
|
}
|
|
func GetParamOption(ctx *context.APIContext) (opt *models.GetGetActivityOptions) {
|
|
Layout:="2006-01-02 15:04:05"
|
|
//##top
|
|
top:=ctx.QueryInt64("top")
|
|
if top<=0 {
|
|
top=5
|
|
}else if top>=20 {
|
|
top=20
|
|
}
|
|
|
|
//##from
|
|
FromDate, err := strconv.ParseInt(ctx.QueryTrim("from"), 10, 64)
|
|
if err!=nil {
|
|
ctx.Error(http.StatusBadRequest,"param.from", err)
|
|
return
|
|
}
|
|
if FromDate <= 0 {
|
|
ctx.Error(http.StatusBadRequest,"param.from", fmt.Errorf("请指定from参数"))
|
|
return
|
|
//from=time.Now().Format("2006-01-02")
|
|
}
|
|
|
|
from := time.Unix(FromDate, 0).Format(Layout)
|
|
//fmt.Println("********from:",from," ", FromDate," convert:",time.Unix( FromDate,0).Format("2006-01-02 15:04:05"))
|
|
|
|
|
|
//##to
|
|
ToDate, err := strconv.ParseInt(ctx.QueryTrim("to"), 10, 64)
|
|
if err!=nil {
|
|
ctx.Error(http.StatusBadRequest,"param.to ", err)
|
|
return
|
|
}
|
|
if ToDate <= 0 {
|
|
ctx.Error(http.StatusBadRequest,"param.to", fmt.Errorf("请指定to参数"))
|
|
return
|
|
}
|
|
|
|
to := time.Unix(ToDate, 0).Format(Layout)
|
|
|
|
//fmt.Println("********to:",to ," ", ToDate," convert:",time.Unix( ToDate,0).Format(Layout))
|
|
opt= &models.GetGetActivityOptions{
|
|
FromDateUnix:FromDate,
|
|
ToDateUnix:ToDate,
|
|
FromDate:from,
|
|
ToDate:to,
|
|
Top:top,
|
|
}
|
|
return opt
|
|
}
|