goploy/controller/RepositoryController.go

99 lines
2.5 KiB
Go
Raw Normal View History

2021-05-23 22:29:35 +08:00
package controller
import (
"github.com/zhenorzz/goploy/core"
"github.com/zhenorzz/goploy/model"
2021-08-15 23:27:22 +08:00
"github.com/zhenorzz/goploy/repository"
2021-05-23 22:29:35 +08:00
"strconv"
)
// Repository struct
type Repository Controller
// GetCommitList get latest 10 commit list
func (Repository) GetCommitList(gp *core.Goploy) *core.Response {
id, err := strconv.ParseInt(gp.URLQuery.Get("id"), 10, 64)
if err != nil {
return &core.Response{Code: core.Error, Message: err.Error()}
}
project, err := model.Project{ID: id}.GetData()
if err != nil {
return &core.Response{Code: core.Error, Message: err.Error()}
}
2021-08-15 23:27:22 +08:00
2021-08-19 14:40:42 +08:00
repo, err := repository.GetRepo(project.RepoType)
2021-08-15 23:27:22 +08:00
if err != nil {
return &core.Response{Code: core.Error, Message: err.Error()}
2021-05-23 22:29:35 +08:00
}
2021-08-15 23:27:22 +08:00
list, err := repo.BranchLog(project.ID, gp.URLQuery.Get("branch"), 10)
if err != nil {
return &core.Response{Code: core.Error, Message: err.Error()}
}
2021-05-23 22:29:35 +08:00
return &core.Response{
Data: struct {
2021-08-15 23:27:22 +08:00
CommitList []repository.CommitInfo `json:"list"`
}{CommitList: list},
2021-05-23 22:29:35 +08:00
}
}
// GetBranchList get all branch list
func (Repository) GetBranchList(gp *core.Goploy) *core.Response {
id, err := strconv.ParseInt(gp.URLQuery.Get("id"), 10, 64)
if err != nil {
return &core.Response{Code: core.Error, Message: err.Error()}
}
project, err := model.Project{ID: id}.GetData()
if err != nil {
return &core.Response{Code: core.Error, Message: err.Error()}
}
2021-08-19 14:40:42 +08:00
repo, err := repository.GetRepo(project.RepoType)
2021-08-16 19:45:07 +08:00
if err != nil {
return &core.Response{Code: core.Error, Message: err.Error()}
2021-05-23 22:29:35 +08:00
}
2021-08-16 19:45:07 +08:00
branchList, err := repo.BranchList(project.ID)
if err != nil {
return &core.Response{Code: core.Error, Message: err.Error()}
2021-05-23 22:29:35 +08:00
}
return &core.Response{
Data: struct {
BranchList []string `json:"list"`
}{BranchList: branchList},
}
}
// GetTagList get latest 10 tag list
func (Repository) GetTagList(gp *core.Goploy) *core.Response {
id, err := strconv.ParseInt(gp.URLQuery.Get("id"), 10, 64)
if err != nil {
return &core.Response{Code: core.Error, Message: err.Error()}
}
project, err := model.Project{ID: id}.GetData()
if err != nil {
return &core.Response{Code: core.Error, Message: err.Error()}
}
2021-08-19 14:40:42 +08:00
repo, err := repository.GetRepo(project.RepoType)
2021-08-15 23:27:22 +08:00
if err != nil {
return &core.Response{Code: core.Error, Message: err.Error()}
2021-05-23 22:29:35 +08:00
}
2021-08-16 19:45:07 +08:00
list, err := repo.TagLog(project.ID, 10)
2021-08-15 23:27:22 +08:00
if err != nil {
return &core.Response{Code: core.Error, Message: err.Error()}
2021-05-23 22:29:35 +08:00
}
return &core.Response{
Data: struct {
2021-08-15 23:27:22 +08:00
TagList []repository.CommitInfo `json:"list"`
}{TagList: list},
2021-05-23 22:29:35 +08:00
}
}