Browse Source

修改非启智项目的标签逻辑

2023
chenyifan01 2 years ago
parent
commit
3c125805db
2 changed files with 31 additions and 9 deletions
  1. +8
    -8
      modules/structs/tech.go
  2. +23
    -1
      routers/api/v1/tech/repo.go

+ 8
- 8
modules/structs/tech.go View File

@@ -1,14 +1,14 @@
package structs package structs


type NotOpenITechRepo struct { type NotOpenITechRepo struct {
Url string `json:"url" binding:"Required"`
TechNo string `json:"no"`
Institution string `json:"institution"`
UID int64 `json:"uid"` //启智项目uid
RepoName string `json:"repo_name" binding:"Required;AlphaDashDot;MaxSize(100)"`
Alias string `json:"alias" binding:"Required;AlphaDashDotChinese;MaxSize(100)"`
Topics string `json:"topics"` //关键词
Description string `json:"description" binding:"MaxSize(255)"`
Url string `json:"url" binding:"Required"`
TechNo string `json:"no"`
Institution string `json:"institution"`
UID int64 `json:"uid"` //启智项目uid
RepoName string `json:"repo_name" binding:"Required;AlphaDashDot;MaxSize(100)"`
Alias string `json:"alias" binding:"Required;AlphaDashDotChinese;MaxSize(100)"`
Topics []string `json:"topics"` //关键词
Description string `json:"description" binding:"MaxSize(255)"`
} }


type OpenITechRepo struct { type OpenITechRepo struct {


+ 23
- 1
routers/api/v1/tech/repo.go View File

@@ -8,6 +8,7 @@ import (
"code.gitea.io/gitea/routers/response" "code.gitea.io/gitea/routers/response"
"code.gitea.io/gitea/services/repository" "code.gitea.io/gitea/services/repository"
techService "code.gitea.io/gitea/services/tech" techService "code.gitea.io/gitea/services/tech"
"errors"
"fmt" "fmt"
"net/http" "net/http"
) )
@@ -86,7 +87,7 @@ func CommitNotOpenIRepo(ctx *context.APIContext, form api.NotOpenITechRepo) {
RepoName: form.RepoName, RepoName: form.RepoName,
Alias: form.Alias, Alias: form.Alias,
Description: form.Description, Description: form.Description,
Labels: true,
Labels: false,
Mirror: true, Mirror: true,
}) })
if bizErr != nil { if bizErr != nil {
@@ -115,6 +116,9 @@ func CommitNotOpenIRepo(ctx *context.APIContext, form api.NotOpenITechRepo) {
return return
} }


//给仓库加标签
updateTopics(repo.ID, form.Topics)

//写入数据库 //写入数据库
rci := &models.RepoConvergeInfo{ rci := &models.RepoConvergeInfo{
RepoID: repo.ID, RepoID: repo.ID,
@@ -131,3 +135,21 @@ func CommitNotOpenIRepo(ctx *context.APIContext, form api.NotOpenITechRepo) {
} }
ctx.JSON(http.StatusOK, response.OuterSuccess()) ctx.JSON(http.StatusOK, response.OuterSuccess())
} }

func updateTopics(repoId int64, topicNames []string) error {
validTopics, invalidTopics := models.SanitizeAndValidateTopics(topicNames)

if len(validTopics) > 25 {
return errors.New("Exceeding maximum number of topics per repo")
}

if len(invalidTopics) > 0 {
return errors.New("Topic names are invalid")
}

err := models.SaveTopics(repoId, validTopics...)
if err != nil {
return err
}
return nil
}

Loading…
Cancel
Save