Skip to content

Commit

Permalink
Merge branch 'main' into various-small-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zeripath authored Dec 16, 2021
2 parents e639975 + 6e7d28c commit f5c33da
Show file tree
Hide file tree
Showing 25 changed files with 169 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
/.eslintrc linguist-language=YAML
/.stylelintrc linguist-language=YAML
/web_src/fomantic/build/** linguist-generated
Dockerfile.* linguist-language=Dockerfile
4 changes: 4 additions & 0 deletions custom/conf/app.example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1587,6 +1587,10 @@ PATH =
;AVATAR_MAX_WIDTH = 4096
;AVATAR_MAX_HEIGHT = 3072
;;
;; The multiplication factor for rendered avatar images.
;; Larger values result in finer rendering on HiDPI devices.
;AVATAR_RENDERED_SIZE_FACTOR = 3
;;
;; Maximum allowed file size for uploaded avatars.
;; This is to limit the amount of RAM used when resizing the image.
;AVATAR_MAX_FILE_SIZE = 1048576
Expand Down
1 change: 1 addition & 0 deletions docs/content/doc/advanced/config-cheat-sheet.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,7 @@ Define allowed algorithms and their minimum key length (use -1 to disable a type
- `AVATAR_MAX_WIDTH`: **4096**: Maximum avatar image width in pixels.
- `AVATAR_MAX_HEIGHT`: **3072**: Maximum avatar image height in pixels.
- `AVATAR_MAX_FILE_SIZE`: **1048576** (1Mb): Maximum avatar image file size in bytes.
- `AVATAR_RENDERED_SIZE_FACTOR`: **3**: The multiplication factor for rendered avatar images. Larger values result in finer rendering on HiDPI devices.

- `REPOSITORY_AVATAR_STORAGE_TYPE`: **default**: Storage type defined in `[storage.xxx]`. Default is `default` which will read `[storage]` if no section `[storage]` will be a type `local`.
- `REPOSITORY_AVATAR_UPLOAD_PATH`: **data/repo-avatars**: Path to store repository avatar image files.
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3a810dbf6b96afaa8c5f69a8b6ec1dabfca7368b
59e2c41e8f5140bb0182acebec17c8ad9831cc62
36 changes: 36 additions & 0 deletions integrations/nonascii_branches_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package integrations

import (
"net/http"
"net/url"
"path"
"testing"

Expand Down Expand Up @@ -159,6 +160,41 @@ func TestNonasciiBranches(t *testing.T) {
to: "tag/%D0%81/%E4%BA%BA",
status: http.StatusOK,
},
{
from: "Plus+Is+Not+Space/%25%252525mightnotplaywell",
to: "branch/Plus+Is+Not+Space/%25%252525mightnotplaywell",
status: http.StatusOK,
},
{
from: "Plus+Is+Not+Space/%25253Fisnotaquestion%25253F",
to: "branch/Plus+Is+Not+Space/%25253Fisnotaquestion%25253F",
status: http.StatusOK,
},
{
from: "Plus+Is+Not+Space/" + url.PathEscape("%3Fis?and#afile"),
to: "branch/Plus+Is+Not+Space/" + url.PathEscape("%3Fis?and#afile"),
status: http.StatusOK,
},
{
from: "Plus+Is+Not+Space/10%25.md",
to: "branch/Plus+Is+Not+Space/10%25.md",
status: http.StatusOK,
},
{
from: "Plus+Is+Not+Space/" + url.PathEscape("This+file%20has 1space"),
to: "branch/Plus+Is+Not+Space/" + url.PathEscape("This+file%20has 1space"),
status: http.StatusOK,
},
{
from: "Plus+Is+Not+Space/" + url.PathEscape("This+file%2520has 2 spaces"),
to: "branch/Plus+Is+Not+Space/" + url.PathEscape("This+file%2520has 2 spaces"),
status: http.StatusOK,
},
{
from: "Plus+Is+Not+Space/" + url.PathEscape("£15&$6.txt"),
to: "branch/Plus+Is+Not+Space/" + url.PathEscape("£15&$6.txt"),
status: http.StatusOK,
},
}

defer prepareTestEnv(t)()
Expand Down
3 changes: 0 additions & 3 deletions models/avatars/avatar.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ import (
// DefaultAvatarPixelSize is the default size in pixels of a rendered avatar
const DefaultAvatarPixelSize = 28

// AvatarRenderedSizeFactor is the factor by which the default size is increased for finer rendering
const AvatarRenderedSizeFactor = 4

// EmailHash represents a pre-generated hash map (mainly used by LibravatarURL, it queries email server's DNS records)
type EmailHash struct {
Hash string `xorm:"pk varchar(32)"`
Expand Down
10 changes: 10 additions & 0 deletions models/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,16 @@ func getTemplateRepo(e db.Engine, repo *Repository) (*Repository, error) {
return getRepositoryByID(e, repo.TemplateID)
}

// TemplateRepo returns the repository, which is template of this repository
func (repo *Repository) TemplateRepo() *Repository {
repo, err := GetTemplateRepo(repo)
if err != nil {
log.Error("TemplateRepo: %v", err)
return nil
}
return repo
}

func countRepositories(userID int64, private bool) int64 {
sess := db.GetEngine(db.DefaultContext).Where("id > 0")

Expand Down
4 changes: 4 additions & 0 deletions modules/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,10 @@ func Contexter() func(next http.Handler) http.Handler {
var locale = middleware.Locale(resp, req)
var startTime = time.Now()
var link = setting.AppSubURL + strings.TrimSuffix(req.URL.EscapedPath(), "/")

chiCtx := chi.RouteContext(req.Context())
chiCtx.RoutePath = req.URL.EscapedPath()

var ctx = Context{
Resp: NewResponse(resp),
Cache: mc.GetCache(),
Expand Down
3 changes: 2 additions & 1 deletion modules/repository/commits.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
)

Expand Down Expand Up @@ -141,7 +142,7 @@ func (pc *PushCommits) AvatarLink(email string) string {
return avatar
}

size := avatars.DefaultAvatarPixelSize * avatars.AvatarRenderedSizeFactor
size := avatars.DefaultAvatarPixelSize * setting.Avatar.RenderedSizeFactor

u, ok := pc.emailUsers[email]
if !ok {
Expand Down
4 changes: 2 additions & 2 deletions modules/repository/commits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ func TestPushCommits_AvatarLink(t *testing.T) {
}

assert.Equal(t,
"https://secure.gravatar.com/avatar/ab53a2911ddf9b4817ac01ddcd3d975f?d=identicon&s=112",
"https://secure.gravatar.com/avatar/ab53a2911ddf9b4817ac01ddcd3d975f?d=identicon&s=84",
pushCommits.AvatarLink("user2@example.com"))

assert.Equal(t,
"https://secure.gravatar.com/avatar/"+
fmt.Sprintf("%x", md5.Sum([]byte("nonexistent@example.com")))+
"?d=identicon&s=112",
"?d=identicon&s=84",
pushCommits.AvatarLink("nonexistent@example.com"))
}

Expand Down
15 changes: 9 additions & 6 deletions modules/setting/picture.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ var (
Avatar = struct {
Storage

MaxWidth int
MaxHeight int
MaxFileSize int64
MaxWidth int
MaxHeight int
MaxFileSize int64
RenderedSizeFactor int
}{
MaxWidth: 4096,
MaxHeight: 3072,
MaxFileSize: 1048576,
MaxWidth: 4096,
MaxHeight: 3072,
MaxFileSize: 1048576,
RenderedSizeFactor: 3,
}

GravatarSource string
Expand Down Expand Up @@ -55,6 +57,7 @@ func newPictureService() {
Avatar.MaxWidth = sec.Key("AVATAR_MAX_WIDTH").MustInt(4096)
Avatar.MaxHeight = sec.Key("AVATAR_MAX_HEIGHT").MustInt(3072)
Avatar.MaxFileSize = sec.Key("AVATAR_MAX_FILE_SIZE").MustInt64(1048576)
Avatar.RenderedSizeFactor = sec.Key("AVATAR_RENDERED_SIZE_FACTOR").MustInt(3)

switch source := sec.Key("GRAVATAR_SOURCE").MustString("gravatar"); source {
case "duoshuo":
Expand Down
8 changes: 4 additions & 4 deletions modules/templates/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,17 +557,17 @@ func Avatar(item interface{}, others ...interface{}) template.HTML {

switch t := item.(type) {
case *user_model.User:
src := t.AvatarLinkWithSize(size * avatars.AvatarRenderedSizeFactor)
src := t.AvatarLinkWithSize(size * setting.Avatar.RenderedSizeFactor)
if src != "" {
return AvatarHTML(src, size, class, t.DisplayName())
}
case *models.Collaborator:
src := t.AvatarLinkWithSize(size * avatars.AvatarRenderedSizeFactor)
src := t.AvatarLinkWithSize(size * setting.Avatar.RenderedSizeFactor)
if src != "" {
return AvatarHTML(src, size, class, t.DisplayName())
}
case *models.Organization:
src := t.AsUser().AvatarLinkWithSize(size * avatars.AvatarRenderedSizeFactor)
src := t.AsUser().AvatarLinkWithSize(size * setting.Avatar.RenderedSizeFactor)
if src != "" {
return AvatarHTML(src, size, class, t.AsUser().DisplayName())
}
Expand Down Expand Up @@ -596,7 +596,7 @@ func RepoAvatar(repo *repo_model.Repository, others ...interface{}) template.HTM
// AvatarByEmail renders avatars by email address. args: email, name, size (int), class (string)
func AvatarByEmail(email string, name string, others ...interface{}) template.HTML {
size, class := parseOthers(avatars.DefaultAvatarPixelSize, "ui avatar image", others...)
src := avatars.GenerateEmailAvatarFastLink(email, size*avatars.AvatarRenderedSizeFactor)
src := avatars.GenerateEmailAvatarFastLink(email, size*setting.Avatar.RenderedSizeFactor)

if src != "" {
return AvatarHTML(src, size, class, name)
Expand Down
6 changes: 6 additions & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1726,6 +1726,12 @@ settings.pulls.default_delete_branch_after_merge = Delete pull request branch af
settings.projects_desc = Enable Repository Projects
settings.admin_settings = Administrator Settings
settings.admin_enable_health_check = Enable Repository Health Checks (git fsck)
settings.admin_code_indexer = Code Indexer
settings.admin_stats_indexer = Code Statistics Indexer
settings.admin_indexer_commit_sha = Last Indexed SHA
settings.admin_indexer_unindexed = Unindexed
settings.reindex_button = Add to Reindex Queue
settings.reindex_requested=Reindex Requested
settings.admin_enable_close_issues_via_commit_in_any_branch = Close an issue via a commit made in a non default branch
settings.danger_zone = Danger Zone
settings.new_owner_has_same_repo = The new owner already has a repository with same name. Please choose another name.
Expand Down
47 changes: 47 additions & 0 deletions routers/web/repo/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/indexer/code"
"code.gitea.io/gitea/modules/indexer/stats"
"code.gitea.io/gitea/modules/lfs"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/repository"
Expand Down Expand Up @@ -67,6 +69,23 @@ func Settings(ctx *context.Context) {
signing, _ := asymkey_service.SigningKey(ctx.Repo.Repository.RepoPath())
ctx.Data["SigningKeyAvailable"] = len(signing) > 0
ctx.Data["SigningSettings"] = setting.Repository.Signing
ctx.Data["CodeIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled
if ctx.User.IsAdmin {
if setting.Indexer.RepoIndexerEnabled {
status, err := repo_model.GetIndexerStatus(ctx.Repo.Repository, repo_model.RepoIndexerTypeCode)
if err != nil {
ctx.ServerError("repo.indexer_status", err)
return
}
ctx.Data["CodeIndexerStatus"] = status
}
status, err := repo_model.GetIndexerStatus(ctx.Repo.Repository, repo_model.RepoIndexerTypeStats)
if err != nil {
ctx.ServerError("repo.indexer_status", err)
return
}
ctx.Data["StatsIndexerStatus"] = status
}
pushMirrors, err := repo_model.GetPushMirrorsByRepoID(ctx.Repo.Repository.ID)
if err != nil {
ctx.ServerError("GetPushMirrorsByRepoID", err)
Expand Down Expand Up @@ -515,6 +534,34 @@ func SettingsPost(ctx *context.Context) {
ctx.Flash.Success(ctx.Tr("repo.settings.update_settings_success"))
ctx.Redirect(ctx.Repo.RepoLink + "/settings")

case "admin_index":
if !ctx.User.IsAdmin {
ctx.Error(http.StatusForbidden)
return
}

switch form.RequestReindexType {
case "stats":
if err := stats.UpdateRepoIndexer(ctx.Repo.Repository); err != nil {
ctx.ServerError("UpdateStatsRepondexer", err)
return
}
case "code":
if !setting.Indexer.RepoIndexerEnabled {
ctx.Error(http.StatusForbidden)
return
}
code.UpdateRepoIndexer(ctx.Repo.Repository)
default:
ctx.NotFound("", nil)
return
}

log.Trace("Repository reindex for %s requested: %s/%s", form.RequestReindexType, ctx.Repo.Owner.Name, repo.Name)

ctx.Flash.Success(ctx.Tr("repo.settings.reindex_requested"))
ctx.Redirect(ctx.Repo.RepoLink + "/settings")

case "convert":
if !ctx.Repo.IsOwner() {
ctx.Error(http.StatusNotFound)
Expand Down
3 changes: 2 additions & 1 deletion services/forms/repo_form.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ type RepoSettingForm struct {
TrustModel string

// Admin settings
EnableHealthCheck bool
EnableHealthCheck bool
RequestReindexType string
}

// Validate validates the fields
Expand Down
41 changes: 40 additions & 1 deletion templates/repo/settings/options.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -558,11 +558,50 @@
</div>
</div>

<div class="ui divider"></div>
<div class="field">
<button class="ui green button">{{$.i18n.Tr "repo.settings.update_settings"}}</button>
</div>
</form>

<div class="ui divider"></div>
<form class="ui form" method="post">
{{.CsrfTokenHtml}}
<input type="hidden" name="action" value="admin_index">
{{if .CodeIndexerEnabled}}
<h4 class="ui header">{{.i18n.Tr "repo.settings.admin_code_indexer"}}</h4>
<div class="inline fields">
<label>{{.i18n.Tr "repo.settings.admin_indexer_commit_sha"}}</label>
<span class="field">
{{if .CodeIndexerStatus}}
<a rel="nofollow" class="ui sha label" href="{{.RepoLink}}/commit/{{.CodeIndexerStatus.CommitSha}}">
<span class="shortsha">{{ShortSha .CodeIndexerStatus.CommitSha}}</span>
</a>
{{else}}
<span>{{.i18n.Tr "repo.settings.admin_indexer_unindexed"}}</span>
{{end}}
</span>
<div class="field">
<button class="ui green button" name="request_reindex_type" value="code">{{$.i18n.Tr "repo.settings.reindex_button"}}</button>
</div>
</div>
{{end}}
<h4 class="ui header">{{.i18n.Tr "repo.settings.admin_stats_indexer"}}</h4>
<div class="inline fields">
<label>{{.i18n.Tr "repo.settings.admin_indexer_commit_sha"}}</label>
<span class="field">
{{if .StatsIndexerStatus}}
<a rel="nofollow" class="ui sha label" href="{{.RepoLink}}/commit/{{.StatsIndexerStatus.CommitSha}}">
<span class="shortsha">{{ShortSha .StatsIndexerStatus.CommitSha}}</span>
</a>
{{else}}
<span>{{.i18n.Tr "repo.settings.admin_indexer_unindexed"}}</span>
{{end}}
</span>
<div class="field">
<button class="ui green button" name="request_reindex_type" value="stats">{{$.i18n.Tr "repo.settings.reindex_button"}}</button>
</div>
</div>
</form>
</div>
{{end}}

Expand Down

0 comments on commit f5c33da

Please sign in to comment.