diff --git a/models/action.go b/models/action.go index ab7d576e8..9bf67b8b9 100755 --- a/models/action.go +++ b/models/action.go @@ -164,12 +164,24 @@ func (a *Action) GetRepoName() string { return a.Repo.Name } +// GetRepoName returns the name of the action repository. +func (a *Action) GetRepoDisplayName() string { + a.loadRepo() + return a.Repo.DisplayName() +} + // ShortRepoName returns the name of the action repository // trimmed to max 33 chars. func (a *Action) ShortRepoName() string { return base.EllipsisString(a.GetRepoName(), 33) } +// ShortRepoName returns the name of the action repository +// trimmed to max 33 chars. +func (a *Action) ShortRepoDisplayName() string { + return base.EllipsisString(a.GetRepoDisplayName(), 33) +} + // GetRepoPath returns the virtual path to the action repository. func (a *Action) GetRepoPath() string { return path.Join(a.GetRepoUserName(), a.GetRepoName()) @@ -181,6 +193,12 @@ func (a *Action) ShortRepoPath() string { return path.Join(a.ShortRepoUserName(), a.ShortRepoName()) } +// ShortRepoPath returns the virtual path to the action repository +// trimmed to max 20 + 1 + 33 chars. +func (a *Action) ShortRepoFullDisplayName() string { + return path.Join(a.ShortRepoUserName(), a.ShortRepoDisplayName()) +} + // GetRepoLink returns relative link to action repository. func (a *Action) GetRepoLink() string { if len(setting.AppSubURL) > 0 { diff --git a/models/repo.go b/models/repo.go index 8070d7442..7661f4dba 100755 --- a/models/repo.go +++ b/models/repo.go @@ -222,6 +222,7 @@ type Repository struct { Hot int64 `xorm:"-"` Active int64 `xorm:"-"` + Alias string } // SanitizedOriginalURL returns a sanitized OriginalURL @@ -232,6 +233,14 @@ func (repo *Repository) SanitizedOriginalURL() string { return util.SanitizeURLCredentials(repo.OriginalURL, false) } +// GetAlias returns a sanitized OriginalURL +func (repo *Repository) DisplayName() string { + if repo.Alias == "" { + return repo.Name + } + return repo.Alias +} + // ColorFormat returns a colored string to represent this repo func (repo *Repository) ColorFormat(s fmt.State) { var ownerName interface{} @@ -285,6 +294,11 @@ func (repo *Repository) FullName() string { return repo.OwnerName + "/" + repo.Name } +// FullDisplayName returns the repository full display name +func (repo *Repository) FullDisplayName() string { + return repo.OwnerName + "/" + repo.DisplayName() +} + // HTMLURL returns the repository HTML URL func (repo *Repository) HTMLURL() string { return setting.AppURL + repo.FullName() @@ -385,6 +399,7 @@ func (repo *Repository) innerAPIFormat(e Engine, mode AccessMode, isParent bool) Owner: repo.Owner.APIFormat(), Name: repo.Name, FullName: repo.FullName(), + FullDisplayName: repo.FullDisplayName(), Description: repo.Description, Private: repo.IsPrivate, Template: repo.IsTemplate, @@ -995,6 +1010,7 @@ func CheckCreateRepository(doer, u *User, name string) error { // CreateRepoOptions contains the create repository options type CreateRepoOptions struct { Name string + Alias string Description string OriginalURL string GitServiceType api.GitServiceType diff --git a/models/repo_generate.go b/models/repo_generate.go index 480683cd4..08bb1463d 100644 --- a/models/repo_generate.go +++ b/models/repo_generate.go @@ -19,6 +19,7 @@ import ( // GenerateRepoOptions contains the template units to generate type GenerateRepoOptions struct { Name string + Alias string Description string Private bool GitContent bool diff --git a/modules/auth/repo_form.go b/modules/auth/repo_form.go index 8061c6469..5c5d1ba5a 100755 --- a/modules/auth/repo_form.go +++ b/modules/auth/repo_form.go @@ -29,6 +29,7 @@ import ( type CreateRepoForm struct { UID int64 `binding:"Required"` RepoName string `binding:"Required;AlphaDashDot;MaxSize(100)"` + Alias string `binding:"Required;MaxSize(100)"` Private bool Description string `binding:"MaxSize(1024)"` DefaultBranch string `binding:"GitRefName;MaxSize(100)"` diff --git a/modules/repository/create.go b/modules/repository/create.go index d740c58b1..f5dfa63d6 100644 --- a/modules/repository/create.go +++ b/modules/repository/create.go @@ -28,6 +28,7 @@ func CreateRepository(doer, u *models.User, opts models.CreateRepoOptions) (_ *m Owner: u, OwnerName: u.Name, Name: opts.Name, + Alias: opts.Alias, LowerName: strings.ToLower(opts.Name), Description: opts.Description, OriginalURL: opts.OriginalURL, diff --git a/modules/repository/generate.go b/modules/repository/generate.go index 6d80488de..86c9a5c28 100644 --- a/modules/repository/generate.go +++ b/modules/repository/generate.go @@ -236,6 +236,7 @@ func GenerateRepository(ctx models.DBContext, doer, owner *models.User, template Owner: owner, OwnerName: owner.Name, Name: opts.Name, + Alias: opts.Alias, LowerName: strings.ToLower(opts.Name), Description: opts.Description, IsPrivate: opts.Private, diff --git a/modules/structs/repo.go b/modules/structs/repo.go index 70de9b746..2928b6123 100755 --- a/modules/structs/repo.go +++ b/modules/structs/repo.go @@ -46,31 +46,32 @@ type ExternalWiki struct { // Repository represents a repository type Repository struct { - ID int64 `json:"id"` - Owner *User `json:"owner"` - Name string `json:"name"` - FullName string `json:"full_name"` - Description string `json:"description"` - Empty bool `json:"empty"` - Private bool `json:"private"` - Fork bool `json:"fork"` - Template bool `json:"template"` - Parent *Repository `json:"parent"` - Mirror bool `json:"mirror"` - Size int `json:"size"` - HTMLURL string `json:"html_url"` - SSHURL string `json:"ssh_url"` - CloneURL string `json:"clone_url"` - OriginalURL string `json:"original_url"` - Website string `json:"website"` - Stars int `json:"stars_count"` - Forks int `json:"forks_count"` - Watchers int `json:"watchers_count"` - OpenIssues int `json:"open_issues_count"` - OpenPulls int `json:"open_pr_counter"` - Releases int `json:"release_counter"` - DefaultBranch string `json:"default_branch"` - Archived bool `json:"archived"` + ID int64 `json:"id"` + Owner *User `json:"owner"` + Name string `json:"name"` + FullName string `json:"full_name"` + FullDisplayName string `json:"full_display_name"` + Description string `json:"description"` + Empty bool `json:"empty"` + Private bool `json:"private"` + Fork bool `json:"fork"` + Template bool `json:"template"` + Parent *Repository `json:"parent"` + Mirror bool `json:"mirror"` + Size int `json:"size"` + HTMLURL string `json:"html_url"` + SSHURL string `json:"ssh_url"` + CloneURL string `json:"clone_url"` + OriginalURL string `json:"original_url"` + Website string `json:"website"` + Stars int `json:"stars_count"` + Forks int `json:"forks_count"` + Watchers int `json:"watchers_count"` + OpenIssues int `json:"open_issues_count"` + OpenPulls int `json:"open_pr_counter"` + Releases int `json:"release_counter"` + DefaultBranch string `json:"default_branch"` + Archived bool `json:"archived"` // swagger:strfmt date-time Created time.Time `json:"created_at"` // swagger:strfmt date-time diff --git a/routers/repo/repo.go b/routers/repo/repo.go index a182e9087..067a75c44 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -201,6 +201,7 @@ func CreatePost(ctx *context.Context, form auth.CreateRepoForm) { if form.RepoTemplate > 0 { opts := models.GenerateRepoOptions{ Name: form.RepoName, + Alias: form.Alias, Description: form.Description, Private: form.Private, GitContent: form.GitContent, @@ -235,6 +236,7 @@ func CreatePost(ctx *context.Context, form auth.CreateRepoForm) { } else { repo, err = repo_service.CreateRepository(ctx.User, ctxUser, models.CreateRepoOptions{ Name: form.RepoName, + Alias: form.Alias, Description: form.Description, Gitignores: form.Gitignores, IssueLabels: form.IssueLabels, diff --git a/templates/repo/header.tmpl b/templates/repo/header.tmpl index 138a323e1..2c54215d0 100755 --- a/templates/repo/header.tmpl +++ b/templates/repo/header.tmpl @@ -24,7 +24,7 @@ {{end}} {{.Owner.Name}}
/
- {{.Name}} + {{.DisplayName}} {{if .RelAvatarLink}} {{if .IsTemplate}} {{if .IsPrivate}} @@ -114,9 +114,9 @@ {{end}} - + {{end}} - + {{if .Permission.CanRead $.UnitTypeIssues}} @@ -152,7 +152,7 @@ {{if .Permission.CanRead $.UnitTypeCloudBrain}} - + {{.i18n.Tr "repo.cloudbrain"}} diff --git a/templates/user/dashboard/feeds.tmpl b/templates/user/dashboard/feeds.tmpl index a1b4218dc..3eefca78c 100644 --- a/templates/user/dashboard/feeds.tmpl +++ b/templates/user/dashboard/feeds.tmpl @@ -13,12 +13,12 @@ {{.ShortActUserName}} {{end}} {{if eq .GetOpType 1}} - {{$.i18n.Tr "action.create_repo" .GetRepoLink .ShortRepoPath | Str2html}} + {{$.i18n.Tr "action.create_repo" .GetRepoLink .ShortRepoFullDisplayName | Str2html}} {{else if eq .GetOpType 2}} - {{$.i18n.Tr "action.rename_repo" .GetContent .GetRepoLink .ShortRepoPath | Str2html}} + {{$.i18n.Tr "action.rename_repo" .GetContent .GetRepoLink .ShortRepoFullDisplayName | Str2html}} {{else if eq .GetOpType 5}} {{ $branchLink := .GetBranch | EscapePound | Escape}} - {{$.i18n.Tr "action.commit_repo" .GetRepoLink $branchLink (Escape .GetBranch) .ShortRepoPath | Str2html}} + {{$.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}} diff --git a/templates/user/dashboard/repolist.tmpl b/templates/user/dashboard/repolist.tmpl index dc1507403..5df52d77a 100644 --- a/templates/user/dashboard/repolist.tmpl +++ b/templates/user/dashboard/repolist.tmpl @@ -104,7 +104,7 @@
  • - ${repo.full_name} + ${repo.full_display_name} ${repo.stars_count} {{svg "octicon-star" 16}}