Skip to content

Fix some trivial problems (#34579) #34585

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion models/activities/user_heatmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func getUserHeatmapData(ctx context.Context, user *user_model.User, team *organi
Select(groupBy+" AS timestamp, count(user_id) as contributions").
Table("action").
Where(cond).
And("created_unix > ?", timeutil.TimeStampNow()-31536000).
And("created_unix > ?", timeutil.TimeStampNow()-(366+7)*86400). // (366+7) days to include the first week for the heatmap
GroupBy(groupByName).
OrderBy("timestamp").
Find(&hdata)
Expand Down
14 changes: 11 additions & 3 deletions modules/git/languagestats/language_stats_nogogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,17 @@ func GetLanguageStats(repo *git.Repository, commitID string) (map[string]int64,
}

isVendored := optional.None[bool]()
isGenerated := optional.None[bool]()
isDocumentation := optional.None[bool]()
isDetectable := optional.None[bool]()

attrs, err := checker.CheckPath(f.Name())
attrLinguistGenerated := optional.None[bool]()
if err == nil {
if isVendored = attrs.GetVendored(); isVendored.ValueOrDefault(false) {
continue
}

if isGenerated = attrs.GetGenerated(); isGenerated.ValueOrDefault(false) {
if attrLinguistGenerated = attrs.GetGenerated(); attrLinguistGenerated.ValueOrDefault(false) {
continue
}

Expand Down Expand Up @@ -169,7 +169,15 @@ func GetLanguageStats(repo *git.Repository, commitID string) (map[string]int64,
return nil, err
}
}
if !isGenerated.Has() && enry.IsGenerated(f.Name(), content) {

// if "generated" attribute is set, use it, otherwise use enry.IsGenerated to guess
var isGenerated bool
if attrLinguistGenerated.Has() {
isGenerated = attrLinguistGenerated.Value()
} else {
isGenerated = enry.IsGenerated(f.Name(), content)
}
if isGenerated {
continue
}

Expand Down
5 changes: 4 additions & 1 deletion modules/web/routing/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ func logPrinter(logger log.Logger) func(trigger Event, record *requestRecord) {
status = v.WrittenStatus()
}
logf := logInfo
if strings.HasPrefix(req.RequestURI, "/assets/") {
// lower the log level for some specific requests, in most cases these logs are not useful
if strings.HasPrefix(req.RequestURI, "/assets/") /* static assets */ ||
req.RequestURI == "/user/events" /* Server-Sent Events (SSE) handler */ ||
req.RequestURI == "/api/actions/runner.v1.RunnerService/FetchTask" /* Actions Runner polling */ {
logf = logTrace
}
message := completedMessage
Expand Down
2 changes: 1 addition & 1 deletion routers/api/packages/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ func serveBlob(ctx *context.Context, pfd *packages_model.PackageFileDescriptor)
if u != nil {
headers.Status = http.StatusTemporaryRedirect
headers.Location = u.String()

headers.ContentLength = 0 // do not set Content-Length for redirect responses
setResponseHeaders(ctx.Resp, headers)
return
}
Expand Down
6 changes: 2 additions & 4 deletions services/repository/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@ type expansion struct {
var defaultTransformers = []transformer{
{Name: "SNAKE", Transform: xstrings.ToSnakeCase},
{Name: "KEBAB", Transform: xstrings.ToKebabCase},
{Name: "CAMEL", Transform: func(str string) string {
return xstrings.FirstRuneToLower(xstrings.ToCamelCase(str))
}},
{Name: "PASCAL", Transform: xstrings.ToCamelCase},
{Name: "CAMEL", Transform: xstrings.ToCamelCase},
{Name: "PASCAL", Transform: xstrings.ToPascalCase},
{Name: "LOWER", Transform: strings.ToLower},
{Name: "UPPER", Transform: strings.ToUpper},
{Name: "TITLE", Transform: util.ToTitleCase},
Expand Down
24 changes: 24 additions & 0 deletions services/repository/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

var giteaTemplate = []byte(`
Expand Down Expand Up @@ -65,3 +66,26 @@ func TestFileNameSanitize(t *testing.T) {
assert.Equal(t, "_", fileNameSanitize("\u0000"))
assert.Equal(t, "目标", fileNameSanitize("目标"))
}

func TestTransformers(t *testing.T) {
cases := []struct {
name string
expected string
}{
{"SNAKE", "abc_def_xyz"},
{"KEBAB", "abc-def-xyz"},
{"CAMEL", "abcDefXyz"},
{"PASCAL", "AbcDefXyz"},
{"LOWER", "abc_def-xyz"},
{"UPPER", "ABC_DEF-XYZ"},
{"TITLE", "Abc_def-Xyz"},
}

input := "Abc_Def-XYZ"
assert.Len(t, defaultTransformers, len(cases))
for i, c := range cases {
tf := defaultTransformers[i]
require.Equal(t, c.name, tf.Name)
assert.Equal(t, c.expected, tf.Transform(input), "case %s", c.name)
}
}
2 changes: 1 addition & 1 deletion templates/repo/empty.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<h3>{{ctx.Locale.Tr "repo.create_new_repo_command"}}</h3>
<div class="markup">
<pre><code>touch README.md
git init
git init{{if ne .Repository.ObjectFormatName "sha1"}} --object-format={{.Repository.ObjectFormatName}}{{end}}{{/* for sha256 repo, it needs to set "object-format" explicitly*/}}
{{if ne .Repository.DefaultBranch "master"}}git checkout -b {{.Repository.DefaultBranch}}{{end}}
git add README.md
git commit -m "first commit"
Expand Down
3 changes: 2 additions & 1 deletion web_src/js/components/RepoActionView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,8 @@ export default defineComponent({
});
</script>
<template>
<div class="ui container action-view-container">
<!-- make the view container full width to make users easier to read logs -->
<div class="ui fluid container">
<div class="action-view-header">
<div class="action-info-summary">
<div class="action-info-summary-title">
Expand Down