diff --git a/models/repo.go b/models/repo.go index e03390e8e..63c4178f2 100755 --- a/models/repo.go +++ b/models/repo.go @@ -230,9 +230,10 @@ type Repository struct { CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` - Hot int64 `xorm:"-"` - Active int64 `xorm:"-"` - Alias string + Hot int64 `xorm:"-"` + Active int64 `xorm:"-"` + Alias string `xorm:"INDEX"` + LowerAlias string `xorm:"INDEX"` } // SanitizedOriginalURL returns a sanitized OriginalURL @@ -963,10 +964,10 @@ func isRepositoryExist(e Engine, u *User, repoName string, alias string) (bool, cond = cond.And(builder.Eq{"owner_id": u.ID}) if alias != "" { subCon := builder.NewCond() - subCon = subCon.Or(builder.Eq{"alias": alias}, builder.Eq{"lower_name": repoName}) + subCon = subCon.Or(builder.Eq{"lower_alias": strings.ToLower(alias)}, builder.Eq{"lower_name": strings.ToLower(repoName)}) cond = cond.And(subCon) } else { - cond = cond.And(builder.Eq{"lower_name": repoName}) + cond = cond.And(builder.Eq{"lower_name": strings.ToLower(repoName)}) } count, err := e.Where(cond).Count(&Repository{}) return count > 0 || com.IsDir(RepoPath(u.Name, repoName)), err @@ -985,7 +986,7 @@ func IsRepositoryAliasExist(u *User, alias string) (bool, error) { func isRepositoryAliasExist(e Engine, u *User, alias string) (bool, error) { var cond = builder.NewCond() cond = cond.And(builder.Eq{"owner_id": u.ID}) - cond = cond.And(builder.Eq{"alias": alias}) + cond = cond.And(builder.Eq{"lower_alias": strings.ToLower(alias)}) count, err := e.Where(cond).Count(&Repository{}) return count > 0, err } @@ -1131,6 +1132,7 @@ func IsUsableRepoAlias(name string) error { // CreateRepository creates a repository for the user/organization. func CreateRepository(ctx DBContext, doer, u *User, repo *Repository, opts ...CreateRepoOptions) (err error) { + repo.LowerAlias = strings.ToLower(repo.Alias) if err = IsUsableRepoName(repo.Name); err != nil { return err } diff --git a/modules/notification/action/action.go b/modules/notification/action/action.go index 9956940f3..4bc296657 100644 --- a/modules/notification/action/action.go +++ b/modules/notification/action/action.go @@ -154,6 +154,22 @@ func (a *actionNotifier) NotifyRenameRepository(doer *models.User, repo *models. } } +func (a *actionNotifier) NotifyAliasRepository(doer *models.User, repo *models.Repository, oldAlias string) { + log.Trace("action.ChangeRepositoryAlias: %s/%s", doer.Name, repo.Alias) + + if err := models.NotifyWatchers(&models.Action{ + ActUserID: doer.ID, + ActUser: doer, + OpType: models.ActionRenameRepo, + RepoID: repo.ID, + Repo: repo, + IsPrivate: repo.IsPrivate, + Content: oldAlias, + }); err != nil { + log.Error("NotifyWatchers: %v", err) + } +} + func (a *actionNotifier) NotifyTransferRepository(doer *models.User, repo *models.Repository, oldOwnerName string) { if err := models.NotifyWatchers(&models.Action{ ActUserID: doer.ID, diff --git a/modules/notification/base/notifier.go b/modules/notification/base/notifier.go index 0b3e1173b..8325f710c 100644 --- a/modules/notification/base/notifier.go +++ b/modules/notification/base/notifier.go @@ -18,6 +18,7 @@ type Notifier interface { NotifyDeleteRepository(doer *models.User, repo *models.Repository) NotifyForkRepository(doer *models.User, oldRepo, repo *models.Repository) NotifyRenameRepository(doer *models.User, repo *models.Repository, oldRepoName string) + NotifyAliasRepository(doer *models.User, repo *models.Repository, oldAlias string) NotifyTransferRepository(doer *models.User, repo *models.Repository, oldOwnerName string) NotifyNewIssue(*models.Issue) diff --git a/modules/notification/base/null.go b/modules/notification/base/null.go index d2fd51d71..a74c47980 100644 --- a/modules/notification/base/null.go +++ b/modules/notification/base/null.go @@ -135,6 +135,10 @@ func (*NullNotifier) NotifyDeleteRef(doer *models.User, repo *models.Repository, func (*NullNotifier) NotifyRenameRepository(doer *models.User, repo *models.Repository, oldRepoName string) { } +func (a *NullNotifier) NotifyAliasRepository(doer *models.User, repo *models.Repository, oldAlias string) { + +} + // NotifyTransferRepository places a place holder function func (*NullNotifier) NotifyTransferRepository(doer *models.User, repo *models.Repository, oldOwnerName string) { } diff --git a/routers/repo/setting.go b/routers/repo/setting.go index cebaefdf2..5b057dbe5 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -6,6 +6,7 @@ package repo import ( + "code.gitea.io/gitea/modules/notification" "errors" "fmt" "io/ioutil" @@ -71,8 +72,10 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { } newAlias := form.Alias + var aliasChanged = false // Check if repository alias has been changed. - if repo.Alias != newAlias { + if strings.ToLower(repo.Alias) != strings.ToLower(newAlias) { + aliasChanged = true //check new alias is available or not if err := models.IsRepositoryAliasAvailable(ctx.Repo.Owner, newAlias); err != nil { ctx.Data["Err_Alias"] = true @@ -117,6 +120,10 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { log.Trace("Repository name changed: %s/%s -> %s", ctx.Repo.Owner.Name, repo.Name, newRepoName) } + //notify + if aliasChanged { + notification.NotifyRenameRepository(ctx.Repo.Owner, repo, repo.Alias) + } // In case it's just a case change. repo.Name = newRepoName @@ -125,6 +132,7 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { repo.Website = form.Website repo.IsTemplate = form.Template repo.Alias = newAlias + repo.LowerAlias = strings.ToLower(newAlias) // Visibility of forked repository is forced sync with base repository. if repo.IsFork { @@ -404,7 +412,7 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { ctx.Error(404) return } - if repo.Name != form.RepoName { + if repo.Alias != form.RepoName { ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_repo_name"), tplSettingsOptions, nil) return } @@ -431,7 +439,7 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { ctx.Error(404) return } - if repo.Name != form.RepoName { + if repo.Alias != form.RepoName { ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_repo_name"), tplSettingsOptions, nil) return } @@ -469,7 +477,7 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { ctx.Error(404) return } - if repo.Name != form.RepoName { + if repo.Alias != form.RepoName { ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_repo_name"), tplSettingsOptions, nil) return } @@ -489,7 +497,7 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { ctx.Error(404) return } - if repo.Name != form.RepoName { + if repo.Alias != form.RepoName { ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_repo_name"), tplSettingsOptions, nil) return } diff --git a/services/repository/transfer.go b/services/repository/transfer.go index d34c812b8..0173f81d1 100644 --- a/services/repository/transfer.go +++ b/services/repository/transfer.go @@ -55,7 +55,7 @@ func TransferOwnership(doer, newOwner *models.User, repo *models.Repository, tea // ChangeRepositoryName changes all corresponding setting from old repository name to new one. func ChangeRepositoryName(doer *models.User, repo *models.Repository, newRepoName string) error { - oldRepoName := repo.Name + //oldRepoName := repo.Name // Change repository directory name. We must lock the local copy of the // repo so that we can atomically rename the repo path and updates the @@ -68,7 +68,7 @@ func ChangeRepositoryName(doer *models.User, repo *models.Repository, newRepoNam } repoWorkingPool.CheckOut(com.ToStr(repo.ID)) - notification.NotifyRenameRepository(doer, repo, oldRepoName) + //notification.NotifyRenameRepository(doer, repo, oldRepoName) return nil } diff --git a/templates/repo/home.tmpl b/templates/repo/home.tmpl index 08bf3e825..c9edff0c3 100644 --- a/templates/repo/home.tmpl +++ b/templates/repo/home.tmpl @@ -256,11 +256,8 @@
-

简介 - -

+

简介

+

{{if .Repository.DescriptionHTML}} {{.Repository.DescriptionHTML}} @@ -286,14 +283,8 @@

- {{range .Topics}} - {{.Name}} - - {{end}}
diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl index ae688c628..f4127023c 100644 --- a/templates/repo/settings/options.tmpl +++ b/templates/repo/settings/options.tmpl @@ -509,7 +509,7 @@
@@ -541,7 +541,7 @@
@@ -568,7 +568,7 @@
{{.i18n.Tr "repo.settings.delete_notices_1" | Safe}}
- {{.i18n.Tr "repo.settings.delete_notices_2" .Repository.FullName | Safe}} + {{.i18n.Tr "repo.settings.delete_notices_2" .Repository.Alias | Safe}} {{if .Repository.NumForks}}
{{.i18n.Tr "repo.settings.delete_notices_fork_1"}} {{end}} @@ -579,7 +579,7 @@
@@ -603,7 +603,7 @@
{{.i18n.Tr "repo.settings.delete_notices_1" | Safe}}
- {{.i18n.Tr "repo.settings.wiki_delete_notices_1" .Repository.Name | Safe}} + {{.i18n.Tr "repo.settings.wiki_delete_notices_1" .Repository.Alias | Safe}}
{{.CsrfTokenHtml}} @@ -611,7 +611,7 @@
diff --git a/templates/user/dashboard/feeds.tmpl b/templates/user/dashboard/feeds.tmpl index 3eefca78c..f3794989c 100644 --- a/templates/user/dashboard/feeds.tmpl +++ b/templates/user/dashboard/feeds.tmpl @@ -21,55 +21,55 @@ {{$.i18n.Tr "action.commit_repo" .GetRepoLink $branchLink (Escape .GetBranch) .ShortRepoFullDisplayName | Str2html}} {{else if eq .GetOpType 6}} {{ $index := index .GetIssueInfos 0}} - {{$.i18n.Tr "action.create_issue" .GetRepoLink $index .ShortRepoPath | Str2html}} + {{$.i18n.Tr "action.create_issue" .GetRepoLink $index .ShortRepoFullDisplayName | Str2html}} {{else if eq .GetOpType 7}} {{ $index := index .GetIssueInfos 0}} - {{$.i18n.Tr "action.create_pull_request" .GetRepoLink $index .ShortRepoPath | Str2html}} + {{$.i18n.Tr "action.create_pull_request" .GetRepoLink $index .ShortRepoFullDisplayName | Str2html}} {{else if eq .GetOpType 8}} - {{$.i18n.Tr "action.transfer_repo" .GetContent .GetRepoLink .ShortRepoPath | Str2html}} + {{$.i18n.Tr "action.transfer_repo" .GetContent .GetRepoLink .ShortRepoFullDisplayName | Str2html}} {{else if eq .GetOpType 9}} {{ $branchLink := .GetBranch | EscapePound | Escape}} - {{$.i18n.Tr "action.push_tag" .GetRepoLink $branchLink .ShortRepoPath | Str2html}} + {{$.i18n.Tr "action.push_tag" .GetRepoLink $branchLink .ShortRepoFullDisplayName | Str2html}} {{else if eq .GetOpType 10}} {{ $index := index .GetIssueInfos 0}} - {{$.i18n.Tr "action.comment_issue" .GetRepoLink $index .ShortRepoPath | Str2html}} + {{$.i18n.Tr "action.comment_issue" .GetRepoLink $index .ShortRepoFullDisplayName | Str2html}} {{else if eq .GetOpType 11}} {{ $index := index .GetIssueInfos 0}} - {{$.i18n.Tr "action.merge_pull_request" .GetRepoLink $index .ShortRepoPath | Str2html}} + {{$.i18n.Tr "action.merge_pull_request" .GetRepoLink $index .ShortRepoFullDisplayName | Str2html}} {{else if eq .GetOpType 12}} {{ $index := index .GetIssueInfos 0}} - {{$.i18n.Tr "action.close_issue" .GetRepoLink $index .ShortRepoPath | Str2html}} + {{$.i18n.Tr "action.close_issue" .GetRepoLink $index .ShortRepoFullDisplayName | Str2html}} {{else if eq .GetOpType 13}} {{ $index := index .GetIssueInfos 0}} - {{$.i18n.Tr "action.reopen_issue" .GetRepoLink $index .ShortRepoPath | Str2html}} + {{$.i18n.Tr "action.reopen_issue" .GetRepoLink $index .ShortRepoFullDisplayName | Str2html}} {{else if eq .GetOpType 14}} {{ $index := index .GetIssueInfos 0}} - {{$.i18n.Tr "action.close_pull_request" .GetRepoLink $index .ShortRepoPath | Str2html}} + {{$.i18n.Tr "action.close_pull_request" .GetRepoLink $index .ShortRepoFullDisplayName | Str2html}} {{else if eq .GetOpType 15}} {{ $index := index .GetIssueInfos 0}} - {{$.i18n.Tr "action.reopen_pull_request" .GetRepoLink $index .ShortRepoPath | Str2html}} + {{$.i18n.Tr "action.reopen_pull_request" .GetRepoLink $index .ShortRepoFullDisplayName | Str2html}} {{else if eq .GetOpType 16}} {{ $index := index .GetIssueInfos 0}} - {{$.i18n.Tr "action.delete_tag" .GetRepoLink .GetBranch .ShortRepoPath | Str2html}} + {{$.i18n.Tr "action.delete_tag" .GetRepoLink .GetBranch .ShortRepoFullDisplayName | Str2html}} {{else if eq .GetOpType 17}} {{ $index := index .GetIssueInfos 0}} - {{$.i18n.Tr "action.delete_branch" .GetRepoLink .GetBranch .ShortRepoPath | Str2html}} + {{$.i18n.Tr "action.delete_branch" .GetRepoLink .GetBranch .ShortRepoFullDisplayName | Str2html}} {{else if eq .GetOpType 18}} {{ $branchLink := .GetBranch | EscapePound}} - {{$.i18n.Tr "action.mirror_sync_push" .GetRepoLink $branchLink .GetBranch .ShortRepoPath | Str2html}} + {{$.i18n.Tr "action.mirror_sync_push" .GetRepoLink $branchLink .GetBranch .ShortRepoFullDisplayName | Str2html}} {{else if eq .GetOpType 19}} - {{$.i18n.Tr "action.mirror_sync_create" .GetRepoLink .GetBranch .ShortRepoPath | Str2html}} + {{$.i18n.Tr "action.mirror_sync_create" .GetRepoLink .GetBranch .ShortRepoFullDisplayName | Str2html}} {{else if eq .GetOpType 20}} - {{$.i18n.Tr "action.mirror_sync_delete" .GetRepoLink .GetBranch .ShortRepoPath | Str2html}} + {{$.i18n.Tr "action.mirror_sync_delete" .GetRepoLink .GetBranch .ShortRepoFullDisplayName | Str2html}} {{else if eq .GetOpType 21}} {{ $index := index .GetIssueInfos 0}} - {{$.i18n.Tr "action.approve_pull_request" .GetRepoLink $index .ShortRepoPath | Str2html}} + {{$.i18n.Tr "action.approve_pull_request" .GetRepoLink $index .ShortRepoFullDisplayName | Str2html}} {{else if eq .GetOpType 22}} {{ $index := index .GetIssueInfos 0}} - {{$.i18n.Tr "action.reject_pull_request" .GetRepoLink $index .ShortRepoPath | Str2html}} + {{$.i18n.Tr "action.reject_pull_request" .GetRepoLink $index .ShortRepoFullDisplayName | Str2html}} {{else if eq .GetOpType 23}} {{ $index := index .GetIssueInfos 0}} - {{$.i18n.Tr "action.comment_pull" .GetRepoLink $index .ShortRepoPath | Str2html}} + {{$.i18n.Tr "action.comment_pull" .GetRepoLink $index .ShortRepoFullDisplayName | Str2html}} {{end}}

{{if or (eq .GetOpType 5) (eq .GetOpType 18)}} diff --git a/web_src/js/components/EditAboutInfo.vue b/web_src/js/components/EditAboutInfo.vue index eeb0ddaa8..425cf4bcc 100644 --- a/web_src/js/components/EditAboutInfo.vue +++ b/web_src/js/components/EditAboutInfo.vue @@ -52,6 +52,7 @@ export default { desc: '', index_web: '', repo_name_name: '', + alias:'' }, // rule1:[{min:3,max:5,message:'1',trigger:"blur"}], rule: { @@ -76,6 +77,7 @@ export default { getRepoName() { const el = this.url.split('/')[2]; this.info.repo_name = el; + this.info.alias = $('input#edit-alias').val() }, initForm(diaolog) { if (diaolog === false) { @@ -95,6 +97,7 @@ export default { data: this.qs.stringify({ _csrf: csrf, action: 'update', + alias:this.info.alias, repo_name: this.info.repo_name, description: this.info.desc, website: this.info.index_web