Browse Source

Merge branch 'repo_list' into web

tags/v1.21.12.1
A00老虎 4 years ago
parent
commit
cad0449576
15 changed files with 132 additions and 25 deletions
  1. +36
    -0
      models/custom_migrations.go
  2. +2
    -0
      models/models.go
  3. +1
    -0
      models/repo.go
  4. +2
    -0
      models/repo_list.go
  5. +4
    -3
      models/topic.go
  6. +1
    -1
      modules/auth/modelarts.go
  7. +25
    -5
      modules/modelarts/modelarts.go
  8. +6
    -5
      modules/setting/setting.go
  9. +14
    -0
      modules/storage/obs.go
  10. +1
    -1
      options/locale/locale_en-US.ini
  11. +1
    -1
      options/locale/locale_zh-CN.ini
  12. +5
    -0
      routers/home.go
  13. +28
    -0
      routers/private/hook.go
  14. +4
    -3
      templates/repo/modelarts/new.tmpl
  15. +2
    -6
      web_src/js/index.js

+ 36
- 0
models/custom_migrations.go View File

@@ -0,0 +1,36 @@
package models

import (
"code.gitea.io/gitea/modules/log"
"xorm.io/xorm"
)

type CustomMigration struct {
Description string
Migrate func(*xorm.Engine) error
}

var customMigrations = []CustomMigration{
{"Custom v1 Topic struct change to support chinese", syncTopicStruct},
}

func MigrateCustom(x *xorm.Engine) {

for _, m := range customMigrations {
log.Info("Migration: %s", m.Description)
if err := m.Migrate(x); err != nil {

log.Error("Migration: %v", err)

}
}

}

func syncTopicStruct(x *xorm.Engine) error {

query := "ALTER TABLE topic ALTER COLUMN name TYPE varchar(105);"

_, err := x.Exec(query)
return err
}

+ 2
- 0
models/models.go View File

@@ -185,6 +185,8 @@ func SetEngine() (err error) {
x.SetMaxOpenConns(setting.Database.MaxOpenConns)
x.SetMaxIdleConns(setting.Database.MaxIdleConns)
x.SetConnMaxLifetime(setting.Database.ConnMaxLifetime)
x.Sync2(tables...)
MigrateCustom(x)
return nil
}



+ 1
- 0
models/repo.go View File

@@ -175,6 +175,7 @@ type Repository struct {
NumMilestones int `xorm:"NOT NULL DEFAULT 0"`
NumClosedMilestones int `xorm:"NOT NULL DEFAULT 0"`
NumOpenMilestones int `xorm:"-"`
NumCommit int64

IsPrivate bool `xorm:"INDEX"`
IsEmpty bool `xorm:"INDEX"`


+ 2
- 0
models/repo_list.go View File

@@ -198,6 +198,8 @@ const (
SearchOrderByForks SearchOrderBy = "num_forks ASC"
SearchOrderByForksReverse SearchOrderBy = "num_forks DESC"
SearchOrderByDownloadTimes SearchOrderBy = "download_times DESC"
SearchOrderByHot SearchOrderBy = "(num_watches + num_stars + num_forks + clone_cnt) DESC"
SearchOrderByActive SearchOrderBy = "(num_issues + num_pulls) DESC"
)

// SearchRepositoryCondition creates a query condition according search repository options


+ 4
- 3
models/topic.go View File

@@ -8,6 +8,7 @@ import (
"fmt"
"regexp"
"strings"
"unicode/utf8"

"code.gitea.io/gitea/modules/timeutil"

@@ -21,12 +22,12 @@ func init() {
)
}

var topicPattern = regexp.MustCompile(`^[a-z0-9][a-z0-9-]*$`)
var topicPattern = regexp.MustCompile(`^[\x{4e00}-\x{9fa5}a-z0-9][\x{4e00}-\x{9fa5}a-z0-9-]*$`)

// Topic represents a topic of repositories
type Topic struct {
ID int64
Name string `xorm:"UNIQUE VARCHAR(25)"`
Name string `xorm:"UNIQUE VARCHAR(105)"`
RepoCount int
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
@@ -56,7 +57,7 @@ func (err ErrTopicNotExist) Error() string {

// ValidateTopic checks a topic by length and match pattern rules
func ValidateTopic(topic string) bool {
return len(topic) <= 35 && topicPattern.MatchString(topic)
return utf8.RuneCountInString(topic) <= 35 && topicPattern.MatchString(topic)
}

// SanitizeAndValidateTopics sanitizes and checks an array or topics


+ 1
- 1
modules/auth/modelarts.go View File

@@ -7,7 +7,7 @@ import (

type CreateModelArtsForm struct {
JobName string `form:"job_name" binding:"Required"`
Attachment string `form:"attachment" binding:"Required"`
Attachment string `form:"attachment"`
Description string `form:"description"`
}



+ 25
- 5
modules/modelarts/modelarts.go View File

@@ -1,13 +1,13 @@
package modelarts

import (
"code.gitea.io/gitea/modules/setting"
"encoding/json"
"path"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/storage"
"encoding/json"
"path"
)

const (
@@ -25,7 +25,27 @@ var (
)

func GenerateTask(ctx *context.Context, jobName, uuid, description string) error {
dataActualPath := setting.Bucket + "/" + setting.BasePath + path.Join(uuid[0:1], uuid[1:2]) + "/" + uuid + "/"
var dataActualPath string
if uuid != "" {
dataActualPath = setting.Bucket + "/" + setting.BasePath + path.Join(uuid[0:1], uuid[1:2]) + "/" + uuid + "/"
} else {
userPath := setting.UserBasePath + ctx.User.Name + "/"
isExist, err := storage.ObsHasObject(userPath)
if err != nil {
log.Error("ObsHasObject failed:%v", err.Error(), ctx.Data["MsgID"])
return err
}

if !isExist {
if err = storage.ObsCreateObject(userPath); err != nil {
log.Error("ObsCreateObject failed:%v", err.Error(), ctx.Data["MsgID"])
return err
}
}

dataActualPath = setting.Bucket + "/" + userPath
}

if poolInfos == nil {
json.Unmarshal([]byte(setting.PoolInfos), &poolInfos)
}


+ 6
- 5
modules/setting/setting.go View File

@@ -463,7 +463,7 @@ var (
Bucket string
Location string
BasePath string
//RealPath string
UserBasePath string

//modelarts config
ModelArtsHost string
@@ -473,10 +473,10 @@ var (
ModelArtsUsername string
ModelArtsPassword string
ModelArtsDomain string
ProfileID string
PoolInfos string
Flavor string
FlavorInfos string
ProfileID string
PoolInfos string
Flavor string
FlavorInfos string
)

// DateLang transforms standard language locale name to corresponding value in datetime plugin.
@@ -1177,6 +1177,7 @@ func NewContext() {
Bucket = sec.Key("BUCKET").MustString("testopendata")
Location = sec.Key("LOCATION").MustString("cn-south-222")
BasePath = sec.Key("BASE_PATH").MustString("attachment/")
UserBasePath = sec.Key("BASE_PATH_USER").MustString("users/")

sec = Cfg.Section("modelarts")
ModelArtsHost = sec.Key("ENDPOINT").MustString("112.95.163.80")


+ 14
- 0
modules/storage/obs.go View File

@@ -143,3 +143,17 @@ func ObsGetPreSignedUrl(uuid, fileName string) (string, error) {

return output.SignedUrl, nil
}

func ObsCreateObject(path string) error {
input := &obs.PutObjectInput{}
input.Bucket = setting.Bucket
input.Key = path

_, err := ObsCli.PutObject(input)
if err != nil {
log.Error("PutObject failed:", err.Error())
return err
}

return nil
}

+ 1
- 1
options/locale/locale_en-US.ini View File

@@ -1815,7 +1815,7 @@ branch.included = Included
topic.manage_topics = Manage Topics
topic.done = Done
topic.count_prompt = You can not select more than 25 topics
topic.format_prompt = Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
topic.format_prompt = Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

[org]
org_name_holder = Organization Name


+ 1
- 1
options/locale/locale_zh-CN.ini View File

@@ -1817,7 +1817,7 @@ branch.included=已包含
topic.manage_topics=管理主题
topic.done=保存
topic.count_prompt=您最多选择25个主题
topic.format_prompt=主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
topic.format_prompt=主题必须以汉字、字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

[org]
org_name_holder=组织名称


+ 5
- 0
routers/home.go View File

@@ -136,6 +136,11 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
orderBy = models.SearchOrderByForksReverse
case "fewestforks":
orderBy = models.SearchOrderByForks
case "hot":
orderBy = models.SearchOrderByHot
case "active":
orderBy = models.SearchOrderByHot

default:
ctx.Data["SortType"] = "recentupdate"
orderBy = models.SearchOrderByRecentUpdated


+ 28
- 0
routers/private/hook.go View File

@@ -520,12 +520,40 @@ func HookPostReceive(ctx *macaron.Context, opts private.HookOptions) {
}
}
}
if err := updateRepoCommitCnt(ctx, repo); err != nil {
log.Error("updateRepoCommitCnt failed:%v", err.Error(), ctx.Data["MsgID"])
}

ctx.JSON(http.StatusOK, private.HookPostReceiveResult{
Results: results,
RepoWasEmpty: wasEmpty,
})
}

func updateRepoCommitCnt(ctx *macaron.Context, repo *models.Repository) error {
gitRepo, err := git.OpenRepository(repo.RepoPath())
if err != nil {
log.Error("OpenRepository failed:%v", err.Error(), ctx.Data["MsgID"])
return err
}
defer gitRepo.Close()

count, err := gitRepo.GetAllCommitsCount()
if err != nil {
log.Error("GetAllCommitsCount failed:%v", err.Error(), ctx.Data["MsgID"])
return err
}

repo.NumCommit = count
if err = models.UpdateRepositoryCols(repo, "num_commit"); err != nil {
log.Error("UpdateRepositoryCols failed:%v", err.Error(), ctx.Data["MsgID"])
return err
}

return nil
}

// SetDefaultBranch updates the default branch
func SetDefaultBranch(ctx *macaron.Context) {
ownerName := ctx.Params(":owner")


+ 4
- 3
templates/repo/modelarts/new.tmpl View File

@@ -112,14 +112,15 @@
<input name="job_name" id="cloudbrain_job_name" placeholder="任务名称" value="{{.job_name}}" tabindex="3" autofocus required maxlength="255">
</div>

<div class="inline required field">
<div class="inline field">
<label>数据集</label>
<select id="cloudbrain_dataset" class="ui search dropdown" placeholder="选择数据集" style='width:385px' name="attachment">
<input type="text" list="cloudbrain_dataset" placeholder="选择数据集" name="attachment" autofocus maxlength="36">
<datalist id="cloudbrain_dataset" class="ui search" style='width:385px' name="attachment">
{{range .attachments}}
<option name="attachment" value="{{.UUID}}">{{.Attachment.Name}}</option>

{{end}}
</select>
</datalist>
</div>

<div class="inline required field">


+ 2
- 6
web_src/js/index.js View File

@@ -4113,11 +4113,7 @@ function initTopicbar() {
$.fn.form.settings.rules.validateTopic = function (_values, regExp) {
const topics = topicDropdown.children('a.ui.label');
const status =
topics.length === 0 ||
topics
.last()
.attr('data-value')
.match(regExp);
topics.length === 0 || (topics.last().attr('data-value').match(regExp) !== null && topics.last().attr('data-value').length <= 35);
if (!status) {
topics
.last()
@@ -4136,7 +4132,7 @@ function initTopicbar() {
rules: [
{
type: 'validateTopic',
value: /^[a-z0-9][a-z0-9-]{0,35}$/,
value: /^[\u4e00-\u9fa5a-z0-9][\u4e00-\u9fa5a-z0-9-]{0,105}$/,
prompt: topicPrompts.formatPrompt
},
{


Loading…
Cancel
Save