@@ -409,6 +409,7 @@ func (repo *Repository) innerAPIFormat(e Engine, mode AccessMode, isParent bool) | |||
ID: repo.ID, | |||
Owner: repo.Owner.APIFormat(), | |||
Name: repo.Name, | |||
Alias: repo.Alias, | |||
FullName: repo.FullName(), | |||
FullDisplayName: repo.FullDisplayName(), | |||
Description: repo.Description, | |||
@@ -1956,6 +1957,26 @@ func getRepositoryByOwnerAndName(e Engine, ownerName, repoName string) (*Reposit | |||
return &repo, nil | |||
} | |||
// GetRepositoryByOwnerAndAlias returns the repository by given ownername and reponame. | |||
func GetRepositoryByOwnerAndAlias(ownerName, alias string) (*Repository, error) { | |||
return getRepositoryByOwnerAndAlias(x, ownerName, alias) | |||
} | |||
func getRepositoryByOwnerAndAlias(e Engine, ownerName, alias string) (*Repository, error) { | |||
var repo Repository | |||
has, err := e.Table("repository").Select("repository.*"). | |||
Join("INNER", "`user`", "`user`.id = repository.owner_id"). | |||
Where("repository.lower_alias = ?", strings.ToLower(alias)). | |||
And("`user`.lower_name = ?", strings.ToLower(ownerName)). | |||
Get(&repo) | |||
if err != nil { | |||
return nil, err | |||
} else if !has { | |||
return nil, ErrRepoNotExist{0, 0, ownerName, alias} | |||
} | |||
return &repo, nil | |||
} | |||
// GetRepositoryByName returns the repository by given name under user if exists. | |||
func GetRepositoryByName(ownerID int64, name string) (*Repository, error) { | |||
repo := &Repository{ | |||
@@ -49,6 +49,7 @@ type Repository struct { | |||
ID int64 `json:"id"` | |||
Owner *User `json:"owner"` | |||
Name string `json:"name"` | |||
Alias string `json:"alias"` | |||
FullName string `json:"full_name"` | |||
FullDisplayName string `json:"full_display_name"` | |||
Description string `json:"description"` | |||
@@ -64,18 +64,18 @@ socket.onmessage = function (e) { | |||
var currentTime = new Date().getTime(); | |||
for(var i = 0; i < messageQueue.length; i++){ | |||
var record = messageQueue[i]; | |||
var recordPrefix = getMsg(record); | |||
var actionName = getAction(record.OpType,isZh); | |||
if(record.OpType == "6" || record.OpType == "10" || record.OpType == "12" || record.OpType == "13"){ | |||
html += recordPrefix + actionName; | |||
html += " <a href=\"" + getIssueLink(record) + "\" rel=\"nofollow\">" + getIssueText(record) + "</a>" | |||
html += " <a href=\"" + getIssueLink(record) + "\" rel=\"nofollow\">" + getIssueText(record) + "</a>" | |||
} | |||
else if(record.OpType == "7" || record.OpType == "11" || record.OpType == "14" || record.OpType == "15" || record.OpType == "22" | |||
|| record.OpType == "23"){ | |||
html += recordPrefix + actionName; | |||
html += " <a href=\"" + getPRLink(record) + "\" rel=\"nofollow\">" + getPRText(record) + "</a>" | |||
html += " <a href=\"" + getPRLink(record) + "\" rel=\"nofollow\">" + getPRText(record) + "</a>" | |||
} | |||
else if(record.OpType == "1"){ | |||
html += recordPrefix + actionName; | |||
@@ -120,7 +120,7 @@ function getMsg(record){ | |||
html += "<div class=\"swiper-slide item\">"; | |||
html += " <img class=\"ui avatar image\" src=\"/user/avatar/" + record.ActUser.Name + "/-1\" alt=\"\">" | |||
html += " <div class=\"middle aligned content nowrap\">" | |||
html += " <a href=\"/" + record.ActUser.Name + "\" title=\"\">" + record.ActUser.Name + "</a>" | |||
html += " <a href=\"/" + record.ActUser.Name + "\" title=\"\">" + record.ActUser.Name + "</a>" | |||
return html; | |||
} | |||
@@ -133,7 +133,7 @@ function getRepotext(record){ | |||
} | |||
function getRepoLink(record){ | |||
return record.Repo.OwnerName + "/" + record.Repo.Name; | |||
} | |||
function getTime(UpdatedUnix,currentTime){ | |||
@@ -143,7 +143,7 @@ function getTime(UpdatedUnix,currentTime){ | |||
if( timeEscSecond < 0){ | |||
timeEscSecond = 1; | |||
} | |||
var hours= Math.floor(timeEscSecond / 3600); | |||
//计算相差分钟数 | |||
var leave2 = Math.floor(timeEscSecond % (3600)); //计算小时数后剩余的秒数 | |||
@@ -172,11 +172,11 @@ function getPRText(record){ | |||
}else{ | |||
return record.Repo.OwnerName + "/" + record.Repo.Name + "#" + getIssueId(record); | |||
} | |||
} | |||
function getIssueLink(record){ | |||
return "/" + record.Repo.OwnerName + "/" + record.Repo.Name + "/issues/" + getIssueId(record); | |||
} | |||
@@ -202,7 +202,7 @@ function getIssueText(record){ | |||
}else{ | |||
return record.Repo.OwnerName + "/" + record.Repo.Name + "#" + getIssueId(record); | |||
} | |||
} | |||
/* | |||
@@ -354,7 +354,7 @@ function displayRepo(json){ | |||
html += " <i class=\"ri-star-line\"></i>" + record["NumStars"] + "<i class=\"ri-git-branch-line am-ml-10\"></i>" + record["NumForks"]; | |||
html += " </span>"; | |||
html += " <img class=\"left floated mini ui image\" src=\"" + record["Avatar"] + "\">"; | |||
html += " <a class=\"header nowrap\" href=\"/" + record["OwnerName"] + "/" + record["Name"] + "\">" + record["Name"] +"</a>"; | |||
html += " <a class=\"header nowrap\" href=\"/" + record["OwnerName"] + "/" + record["Name"] + "\">" + record["Alias"] +"</a>"; | |||
html += " <div class=\"description nowrap-2\">" + record["Description"] + " </div>"; | |||
html += " <div class=\"ui tags nowrap am-mt-10\">" | |||
if(record["Topics"] != null){ | |||
@@ -408,4 +408,4 @@ function displayOrg(json){ | |||
} | |||
} | |||
orgDiv.innerHTML = html; | |||
} | |||
} |
@@ -150,7 +150,7 @@ func TeamsRepoAction(ctx *context.Context) { | |||
case "add": | |||
repoName := path.Base(ctx.Query("repo_name")) | |||
var repo *models.Repository | |||
repo, err = models.GetRepositoryByName(ctx.Org.Organization.ID, repoName) | |||
repo, err = models.GetRepositoryByOwnerAndAlias(ctx.Org.Organization.Name, repoName) | |||
if err != nil { | |||
if models.IsErrRepoNotExist(err) { | |||
ctx.Flash.Error(ctx.Tr("org.teams.add_nonexistent_repo")) | |||
@@ -13,6 +13,7 @@ import ( | |||
"path" | |||
"regexp" | |||
"strings" | |||
"unicode/utf8" | |||
"code.gitea.io/gitea/models" | |||
"code.gitea.io/gitea/modules/auth" | |||
@@ -566,7 +567,7 @@ func CheckName(ctx *context.Context) { | |||
var r = make(map[string]string, 1) | |||
q := ctx.Query("q") | |||
owner := ctx.Query("owner") | |||
if q == "" || owner == "" || len(q) > 100 || !validation.ValidAlphaDashDotChinese(q) { | |||
if q == "" || owner == "" || utf8.RuneCountInString(q) > 100 || !validation.ValidAlphaDashDotChinese(q) { | |||
r["name"] = "" | |||
ctx.JSON(200, r) | |||
return | |||
@@ -122,7 +122,7 @@ func GetRecommendRepoFromPromote(filename string) ([]map[string]interface{}, err | |||
} else { | |||
ownerName := strings.Trim(repoName[0:tmpIndex], " ") | |||
repoName := strings.Trim(repoName[tmpIndex+1:], " ") | |||
repo, err := models.GetRepositoryByOwnerAndName(ownerName, repoName) | |||
repo, err := models.GetRepositoryByOwnerAndAlias(ownerName, repoName) | |||
if err == nil { | |||
repoMap := make(map[string]interface{}) | |||
repoMap["ID"] = fmt.Sprint(repo.ID) | |||
@@ -36,7 +36,7 @@ | |||
<span class="text gold">{{svg "octicon-lock" 16}}</span> | |||
{{end}} | |||
</td> | |||
<td><a href="{{AppSubUrl}}/{{.Owner.Name}}/{{.Name}}">{{.Name}}</a></td> | |||
<td><a href="{{AppSubUrl}}/{{.Owner.Name}}/{{.Name}}">{{.Alias}}</a></td> | |||
<td><i class="fa fa{{if .IsPrivate}}-check{{end}}-square-o"></i></td> | |||
<td>{{.NumWatches}}</td> | |||
<td>{{.NumStars}}</td> | |||
@@ -50,7 +50,7 @@ | |||
{{else}} | |||
{{svg "octicon-repo" 16}} | |||
{{end}} | |||
<strong>{{$.Org.Name}}/{{.Name}}</strong> | |||
<strong>{{$.Org.Name}}/{{.Alias}}</strong> | |||
</a> | |||
</div> | |||
{{else}} | |||
@@ -2411,8 +2411,8 @@ function searchRepositories() { | |||
const items = []; | |||
$.each(response.data, (_i, item) => { | |||
items.push({ | |||
title: item.full_name.split('/')[1], | |||
description: item.full_name | |||
title: item.full_display_name.split('/')[1], | |||
description: item.full_display_name | |||
}); | |||
}); | |||
@@ -2677,7 +2677,7 @@ function initTemplateSearch() { | |||
// Parse the response from the api to work with our dropdown | |||
$.each(response.data, (_r, repo) => { | |||
filteredResponse.results.push({ | |||
name: htmlEncode(repo.full_name), | |||
name: htmlEncode(repo.full_display_name), | |||
value: repo.id | |||
}); | |||
}); | |||