@@ -1,6 +1,7 @@
package models
import (
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/timeutil"
"fmt"
)
@@ -12,6 +13,7 @@ type OfficialTag struct {
Name string `xorm:"NOT NULL"`
Code string `xorm:"NOT NULL"`
Limit int `xorm:"NOT NULL default(-1)"`
Status int `xorm:"NOT NULL default(0)"`
CreatedUnix timeutil.TimeStamp `xorm:"created"`
UpdatedUnix timeutil.TimeStamp `xorm:"updated"`
}
@@ -40,21 +42,41 @@ type TagReposSelected struct {
type TagsDetail struct {
TagId int64
TagName string
RepoList []RepositoryForTag
TagLimit int
RepoList []Repository
}
type RepositoryForTag struct {
TagId int64
TagName string
ID int64
Name string
Description string
NumWatches int
NumStars int
NumForks int
Topics []string
TagId int64
TagName string
Repo Repository
}
//
//type RepositoryForTag struct {
// TagId int64
// TagName string
// ID int64
// Name string
// Description string
// NumWatches int
// NumStars int
// NumForks int
// Topics []string
// Link string
// OwnerName string
//}
//// Link returns the repository link
//func (repo *RepositoryForTag) FullPath() string {
// return setting.AppSubURL + "/" + repo.FullName()
//}
//
//// FullName returns the repository full name
//func (repo *RepositoryForTag) FullName() string {
// return repo.OwnerName + "/" + repo.Name
//}
func GetTagByID(id int64) (*OfficialTag, error) {
r := &OfficialTag{
ID: id,
@@ -104,7 +126,7 @@ func UpdateTagReposByID(tagID, orgID int64, repoIdList []int64) error {
func GetTagRepos(tagID, orgID int64) ([]TagReposSelected, error) {
t := make([]TagReposBrief, 0)
const SQLCmd = "select t1.id as repo_id,t1.name as repo_name,t2.id as tag_id from repository t1 left join official_tag_repos t2 on (t1.id = t2.repo_id and t2.tag_id = ?) where t1.owner_id = ? and t1.is_private = false"
const SQLCmd = "select t1.id as repo_id,t1.name as repo_name,t2.id as tag_id from repository t1 left join official_tag_repos t2 on (t1.id = t2.repo_id and t2.tag_id = ?) where t1.owner_id = ? and t1.is_private = false order by t1.updated_unix desc "
if err := x.SQL(SQLCmd, tagID, orgID).Find(&t); err != nil {
return nil, err
@@ -124,31 +146,47 @@ func GetTagRepos(tagID, orgID int64) ([]TagReposSelected, error) {
return r, nil
}
func GetTagsDetails(orgID int64) ([]TagsDetail, error) {
t := make([]RepositoryForTag, 0)
const SQLCmd = "select t1.tag_id ,t3.name as tag_name,t2.* from official_tag_repos t1 inner join repository t2 on t1.repo_id = t2.id inner join official_tag t3 on t1.tag_id = t3.id where t1.org_id = ?"
if err := x.SQL(SQLCmd, orgID).Find(&t); err != nil {
func GetAllOfficialTagRepos(orgID int64, isOwner bool) ([]TagsDetail, error) {
result := make([]TagsDetail, 0)
tags, err := GetAllOfficialTags()
if err != nil {
return nil, err
}
r := make([]TagsDetail, 0)
tempMap := make(map[int64]TagsDetail, 0)
for _, v := range t {
tagId := v.TagId
detail, ok := tempMap[tagId]
if !ok {
detail = TagsDetail{
TagId: v.TagId,
TagName: v.TagName,
RepoList: make([]RepositoryForTag, 0),
}
for _, tag := range tags {
repos, err := GetOfficialTagDetail(orgID, tag.ID)
if err != nil {
return nil, err
}
detail.RepoList = append(detail.RepoList, v)
tempMap[tagId] = detail
if len(repos) == 0 && !isOwner {
continue
}
result = append(result, TagsDetail{
TagId: tag.ID,
TagName: tag.Name,
TagLimit: tag.Limit,
RepoList: repos,
})
}
return result, nil
}
func GetOfficialTagDetail(orgID, tagId int64) ([]Repository, error) {
t := make([]Repository, 0)
const SQLCmd = "select t2.* from official_tag_repos t1 inner join repository t2 on t1.repo_id = t2.id where t1.org_id = ? and t1.tag_id=? order by t2.updated_unix desc"
for _, v := range tempMap {
r = append(r, v)
if err := x.SQL(SQLCmd, orgID, tagId).Find(&t); err != nil {
return nil, err
}
return r, nil
return t, nil
}
func GetAllOfficialTags() ([]OfficialTag, error) {
//todo redis?
o := make([]OfficialTag, 0)
err := x.Where("status = ?", 0).Find(&o)
if err != nil {
log.Error("GetAllOfficialTags error,%v", err)
return nil, err
}
return o, nil
}