Skip to content

Commit 0ef3d06

Browse files
Merge remote-tracking branch 'origin' into feat-32257-add-comments-unchanged-lines-and-show
2 parents fe0efb8 + 2c8bdd2 commit 0ef3d06

File tree

128 files changed

+1333
-1029
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+1333
-1029
lines changed

.editorconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ insert_final_newline = false
1717

1818
[templates/swagger/v1_json.tmpl]
1919
indent_style = space
20+
insert_final_newline = false
2021

2122
[templates/user/auth/oidc_wellknown.tmpl]
2223
indent_style = space

.eslintrc.cjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ module.exports = {
336336
'@typescript-eslint/no-unsafe-unary-minus': [2],
337337
'@typescript-eslint/no-unused-expressions': [0],
338338
'@typescript-eslint/no-unused-vars': [2, {vars: 'all', args: 'all', caughtErrors: 'all', ignoreRestSiblings: false, argsIgnorePattern: '^_', varsIgnorePattern: '^_', caughtErrorsIgnorePattern: '^_', destructuredArrayIgnorePattern: '^_'}],
339-
'@typescript-eslint/no-use-before-define': [0],
339+
'@typescript-eslint/no-use-before-define': [2, {functions: false, classes: true, variables: true, allowNamedExports: true, typedefs: false, enums: false, ignoreTypeReferences: true}],
340340
'@typescript-eslint/no-useless-constructor': [0],
341341
'@typescript-eslint/no-useless-empty-export': [0],
342342
'@typescript-eslint/no-wrapper-object-types': [2],
@@ -693,7 +693,7 @@ module.exports = {
693693
'no-unused-labels': [2],
694694
'no-unused-private-class-members': [2],
695695
'no-unused-vars': [0], // handled by @typescript-eslint/no-unused-vars
696-
'no-use-before-define': [2, {functions: false, classes: true, variables: true, allowNamedExports: true}],
696+
'no-use-before-define': [0], // handled by @typescript-eslint/no-use-before-define
697697
'no-use-extend-native/no-use-extend-native': [2],
698698
'no-useless-backreference': [2],
699699
'no-useless-call': [2],

.github/labeler.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ modifies/internal:
4141
- ".dockerignore"
4242
- "docker/**"
4343
- ".editorconfig"
44-
- ".eslintrc.yaml"
44+
- ".eslintrc.cjs"
4545
- ".golangci.yml"
4646
- ".gitpod.yml"
4747
- ".markdownlint.yaml"
4848
- ".spectral.yaml"
4949
- "stylelint.config.js"
5050
- ".yamllint.yaml"
5151
- ".github/**"
52-
- ".gitea/"
52+
- ".gitea/**"
5353
- ".devcontainer/**"
5454
- "build.go"
5555
- "build/**"
@@ -73,9 +73,9 @@ modifies/go:
7373
modifies/frontend:
7474
- changed-files:
7575
- any-glob-to-any-file:
76-
- "**/*.js"
77-
- "**/*.ts"
78-
- "**/*.vue"
76+
- "*.js"
77+
- "*.ts"
78+
- "web_src/**"
7979

8080
docs-update-needed:
8181
- changed-files:

.github/workflows/files-changed.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,16 @@ jobs:
5151
- "options/locale/locale_en-US.ini"
5252
5353
frontend:
54-
- "**/*.js"
54+
- "*.js"
55+
- "*.ts"
5556
- "web_src/**"
57+
- "tools/*.js"
58+
- "tools/*.ts"
5659
- "assets/emoji.json"
5760
- "package.json"
5861
- "package-lock.json"
5962
- "Makefile"
60-
- ".eslintrc.yaml"
61-
- "stylelint.config.js"
63+
- ".eslintrc.cjs"
6264
- ".npmrc"
6365
6466
docs:
@@ -85,6 +87,7 @@ jobs:
8587
8688
swagger:
8789
- "templates/swagger/v1_json.tmpl"
90+
- "templates/swagger/v1_input.json"
8891
- "Makefile"
8992
- "package.json"
9093
- "package-lock.json"

.github/workflows/release-tag-version.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ jobs:
8888
# 1.2
8989
# 1.2.3
9090
tags: |
91+
type=semver,pattern={{version}}
9192
type=semver,pattern={{major}}
9293
type=semver,pattern={{major}}.{{minor}}
93-
type=semver,pattern={{version}}
9494
- name: Login to Docker Hub
9595
uses: docker/login-action@v3
9696
with:
@@ -126,9 +126,9 @@ jobs:
126126
# 1.2
127127
# 1.2.3
128128
tags: |
129+
type=semver,pattern={{version}}
129130
type=semver,pattern={{major}}
130131
type=semver,pattern={{major}}.{{minor}}
131-
type=semver,pattern={{version}}
132132
- name: Login to Docker Hub
133133
uses: docker/login-action@v3
134134
with:

Makefile

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,8 @@ ifdef DEPS_PLAYWRIGHT
165165
endif
166166

167167
SWAGGER_SPEC := templates/swagger/v1_json.tmpl
168-
SWAGGER_SPEC_S_TMPL := s|"basePath": *"/api/v1"|"basePath": "{{AppSubUrl \| JSEscape}}/api/v1"|g
169-
SWAGGER_SPEC_S_JSON := s|"basePath": *"{{AppSubUrl \| JSEscape}}/api/v1"|"basePath": "/api/v1"|g
168+
SWAGGER_SPEC_INPUT := templates/swagger/v1_input.json
170169
SWAGGER_EXCLUDE := code.gitea.io/sdk
171-
SWAGGER_NEWLINE_COMMAND := -e '$$a\'
172170

173171
TEST_MYSQL_HOST ?= mysql:3306
174172
TEST_MYSQL_DBNAME ?= testgitea
@@ -271,10 +269,8 @@ endif
271269
.PHONY: generate-swagger
272270
generate-swagger: $(SWAGGER_SPEC) ## generate the swagger spec from code comments
273271

274-
$(SWAGGER_SPEC): $(GO_SOURCES_NO_BINDATA)
275-
$(GO) run $(SWAGGER_PACKAGE) generate spec -x "$(SWAGGER_EXCLUDE)" -o './$(SWAGGER_SPEC)'
276-
$(SED_INPLACE) '$(SWAGGER_SPEC_S_TMPL)' './$(SWAGGER_SPEC)'
277-
$(SED_INPLACE) $(SWAGGER_NEWLINE_COMMAND) './$(SWAGGER_SPEC)'
272+
$(SWAGGER_SPEC): $(GO_SOURCES_NO_BINDATA) $(SWAGGER_SPEC_INPUT)
273+
$(GO) run $(SWAGGER_PACKAGE) generate spec --exclude "$(SWAGGER_EXCLUDE)" --input "$(SWAGGER_SPEC_INPUT)" --output './$(SWAGGER_SPEC)'
278274

279275
.PHONY: swagger-check
280276
swagger-check: generate-swagger
@@ -287,9 +283,11 @@ swagger-check: generate-swagger
287283

288284
.PHONY: swagger-validate
289285
swagger-validate: ## check if the swagger spec is valid
290-
$(SED_INPLACE) '$(SWAGGER_SPEC_S_JSON)' './$(SWAGGER_SPEC)'
286+
@# swagger "validate" requires that the "basePath" must start with a slash, but we are using Golang template "{{...}}"
287+
@$(SED_INPLACE) -E -e 's|"basePath":( *)"(.*)"|"basePath":\1"/\2"|g' './$(SWAGGER_SPEC)' # add a prefix slash to basePath
288+
@# FIXME: there are some warnings
291289
$(GO) run $(SWAGGER_PACKAGE) validate './$(SWAGGER_SPEC)'
292-
$(SED_INPLACE) '$(SWAGGER_SPEC_S_TMPL)' './$(SWAGGER_SPEC)'
290+
@$(SED_INPLACE) -E -e 's|"basePath":( *)"/(.*)"|"basePath":\1"\2"|g' './$(SWAGGER_SPEC)' # remove the prefix slash from basePath
293291

294292
.PHONY: checks
295293
checks: checks-frontend checks-backend ## run various consistency checks
@@ -380,6 +378,7 @@ lint-go-gopls: ## lint go files with gopls
380378

381379
.PHONY: lint-editorconfig
382380
lint-editorconfig:
381+
@echo "Running editorconfig check..."
383382
@$(GO) run $(EDITORCONFIG_CHECKER_PACKAGE) $(EDITORCONFIG_FILES)
384383

385384
.PHONY: lint-actions
@@ -471,7 +470,9 @@ tidy-check: tidy
471470
go-licenses: $(GO_LICENSE_FILE) ## regenerate go licenses
472471

473472
$(GO_LICENSE_FILE): go.mod go.sum
474-
-$(GO) run $(GO_LICENSES_PACKAGE) save . --force --save_path=$(GO_LICENSE_TMP_DIR) 2>/dev/null
473+
@rm -rf $(GO_LICENSE_FILE)
474+
$(GO) install $(GO_LICENSES_PACKAGE)
475+
-GOOS=linux CGO_ENABLED=1 go-licenses save . --force --save_path=$(GO_LICENSE_TMP_DIR) 2>/dev/null
475476
$(GO) run build/generate-go-licenses.go $(GO_LICENSE_TMP_DIR) $(GO_LICENSE_FILE)
476477
@rm -rf $(GO_LICENSE_TMP_DIR)
477478

cmd/web_acme.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ func runACME(listenAddr string, m http.Handler) error {
5454
altTLSALPNPort = p
5555
}
5656

57-
// FIXME: this path is not right, it uses "AppWorkPath" incorrectly, and writes the data into "AppWorkPath/https"
58-
// Ideally it should migrate to AppDataPath write to "AppDataPath/https"
59-
certmagic.Default.Storage = &certmagic.FileStorage{Path: setting.AcmeLiveDirectory}
60-
magic := certmagic.NewDefault()
6157
// Try to use private CA root if provided, otherwise defaults to system's trust
6258
var certPool *x509.CertPool
6359
if setting.AcmeCARoot != "" {
@@ -67,7 +63,13 @@ func runACME(listenAddr string, m http.Handler) error {
6763
log.Warn("Failed to parse CA Root certificate, using default CA trust: %v", err)
6864
}
6965
}
70-
myACME := certmagic.NewACMEIssuer(magic, certmagic.ACMEIssuer{
66+
// FIXME: this path is not right, it uses "AppWorkPath" incorrectly, and writes the data into "AppWorkPath/https"
67+
// Ideally it should migrate to AppDataPath write to "AppDataPath/https"
68+
// And one more thing, no idea why we should set the global default variables here
69+
// But it seems that the current ACME code needs these global variables to make renew work.
70+
// Otherwise, "renew" will use incorrect storage path
71+
certmagic.Default.Storage = &certmagic.FileStorage{Path: setting.AcmeLiveDirectory}
72+
certmagic.DefaultACME = certmagic.ACMEIssuer{
7173
CA: setting.AcmeURL,
7274
TrustedRoots: certPool,
7375
Email: setting.AcmeEmail,
@@ -77,8 +79,10 @@ func runACME(listenAddr string, m http.Handler) error {
7779
ListenHost: setting.HTTPAddr,
7880
AltTLSALPNPort: altTLSALPNPort,
7981
AltHTTPPort: altHTTPPort,
80-
})
82+
}
8183

84+
magic := certmagic.NewDefault()
85+
myACME := certmagic.NewACMEIssuer(magic, certmagic.DefaultACME)
8286
magic.Issuers = []certmagic.Issuer{myACME}
8387

8488
// this obtains certificates or renews them if necessary

go.mod

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ go 1.24
88
godebug x509negativeserial=1
99

1010
require (
11-
code.gitea.io/actions-proto-go v0.4.0
11+
code.gitea.io/actions-proto-go v0.4.1
1212
code.gitea.io/gitea-vet v0.2.3
1313
code.gitea.io/sdk/gitea v0.20.0
1414
codeberg.org/gusted/mcaptcha v0.0.0-20220723083913-4f3072e1d570
@@ -24,7 +24,7 @@ require (
2424
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.17.0
2525
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.6.0
2626
github.com/Azure/go-ntlmssp v0.0.0-20221128193559-754e69321358
27-
github.com/ProtonMail/go-crypto v1.1.5
27+
github.com/ProtonMail/go-crypto v1.1.6
2828
github.com/PuerkitoBio/goquery v1.10.2
2929
github.com/SaveTheRbtz/zstd-seekable-format-go/pkg v0.7.3
3030
github.com/alecthomas/chroma/v2 v2.15.0
@@ -117,10 +117,10 @@ require (
117117
github.com/yuin/goldmark-highlighting/v2 v2.0.0-20230729083705-37449abec8cc
118118
github.com/yuin/goldmark-meta v1.1.0
119119
gitlab.com/gitlab-org/api/client-go v0.123.0
120-
golang.org/x/crypto v0.33.0
120+
golang.org/x/crypto v0.35.0
121121
golang.org/x/image v0.24.0
122122
golang.org/x/net v0.35.0
123-
golang.org/x/oauth2 v0.26.0
123+
golang.org/x/oauth2 v0.27.0
124124
golang.org/x/sync v0.11.0
125125
golang.org/x/sys v0.30.0
126126
golang.org/x/text v0.22.0
@@ -318,7 +318,7 @@ replace github.com/hashicorp/go-version => github.com/6543/go-version v1.3.1
318318

319319
replace github.com/shurcooL/vfsgen => github.com/lunny/vfsgen v0.0.0-20220105142115-2c99e1ffdfa0
320320

321-
replace github.com/nektos/act => gitea.com/gitea/act v0.261.3
321+
replace github.com/nektos/act => gitea.com/gitea/act v0.261.4
322322

323323
// TODO: the only difference is in `PutObject`: the fork doesn't use `NewVerifyingReader(r, sha256.New(), oid, expectedSize)`, need to figure out why
324324
replace github.com/charmbracelet/git-lfs-transfer => gitea.com/gitea/git-lfs-transfer v0.2.0

go.sum

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cloud.google.com/go/compute/metadata v0.6.0 h1:A6hENjEsCDtC1k8byVsgwvVcioamEHvZ4j01OwKxG9I=
22
cloud.google.com/go/compute/metadata v0.6.0/go.mod h1:FjyFAW1MW0C203CEOMDTu3Dk1FlqW3Rga40jzHL4hfg=
3-
code.gitea.io/actions-proto-go v0.4.0 h1:OsPBPhodXuQnsspG1sQ4eRE1PeoZyofd7+i73zCwnsU=
4-
code.gitea.io/actions-proto-go v0.4.0/go.mod h1:mn7Wkqz6JbnTOHQpot3yDeHx+O5C9EGhMEE+htvHBas=
3+
code.gitea.io/actions-proto-go v0.4.1 h1:l0EYhjsgpUe/1VABo2eK7zcoNX2W44WOnb0MSLrKfls=
4+
code.gitea.io/actions-proto-go v0.4.1/go.mod h1:mn7Wkqz6JbnTOHQpot3yDeHx+O5C9EGhMEE+htvHBas=
55
code.gitea.io/gitea-vet v0.2.3 h1:gdFmm6WOTM65rE8FUBTRzeQZYzXePKSSB1+r574hWwI=
66
code.gitea.io/gitea-vet v0.2.3/go.mod h1:zcNbT/aJEmivCAhfmkHOlT645KNOf9W2KnkLgFjGGfE=
77
code.gitea.io/sdk/gitea v0.20.0 h1:Zm/QDwwZK1awoM4AxdjeAQbxolzx2rIP8dDfmKu+KoU=
@@ -16,8 +16,8 @@ filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
1616
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
1717
git.sr.ht/~mariusor/go-xsd-duration v0.0.0-20220703122237-02e73435a078 h1:cliQ4HHsCo6xi2oWZYKWW4bly/Ory9FuTpFPRxj/mAg=
1818
git.sr.ht/~mariusor/go-xsd-duration v0.0.0-20220703122237-02e73435a078/go.mod h1:g/V2Hjas6Z1UHUp4yIx6bATpNzJ7DYtD0FG3+xARWxs=
19-
gitea.com/gitea/act v0.261.3 h1:BhiYpGJQKGq0XMYYICCYAN4KnsEWHyLbA6dxhZwFcV4=
20-
gitea.com/gitea/act v0.261.3/go.mod h1:Pg5C9kQY1CEA3QjthjhlrqOC/QOT5NyWNjOjRHw23Ok=
19+
gitea.com/gitea/act v0.261.4 h1:Tf9eLlvsYFtKcpuxlMvf9yT3g4Hshb2Beqw6C1STuH8=
20+
gitea.com/gitea/act v0.261.4/go.mod h1:Pg5C9kQY1CEA3QjthjhlrqOC/QOT5NyWNjOjRHw23Ok=
2121
gitea.com/gitea/git-lfs-transfer v0.2.0 h1:baHaNoBSRaeq/xKayEXwiDQtlIjps4Ac/Ll4KqLMB40=
2222
gitea.com/gitea/git-lfs-transfer v0.2.0/go.mod h1:UrXUCm3xLQkq15fu7qlXHUMlrhdlXHoi13KH2Dfiits=
2323
gitea.com/go-chi/binding v0.0.0-20240430071103-39a851e106ed h1:EZZBtilMLSZNWtHHcgq2mt6NSGhJSZBuduAlinMEmso=
@@ -71,8 +71,8 @@ github.com/Masterminds/sprig/v3 v3.3.0/go.mod h1:Zy1iXRYNqNLUolqCpL4uhk6SHUMAOSC
7171
github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY=
7272
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
7373
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
74-
github.com/ProtonMail/go-crypto v1.1.5 h1:eoAQfK2dwL+tFSFpr7TbOaPNUbPiJj4fLYwwGE1FQO4=
75-
github.com/ProtonMail/go-crypto v1.1.5/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE=
74+
github.com/ProtonMail/go-crypto v1.1.6 h1:ZcV+Ropw6Qn0AX9brlQLAUXfqLBc7Bl+f/DmNxpLfdw=
75+
github.com/ProtonMail/go-crypto v1.1.6/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE=
7676
github.com/PuerkitoBio/goquery v1.10.2 h1:7fh2BdHcG6VFZsK7toXBT/Bh1z5Wmy8Q9MV9HqT2AM8=
7777
github.com/PuerkitoBio/goquery v1.10.2/go.mod h1:0guWGjcLu9AYC7C1GHnpysHy056u9aEkUHwhdnePMCU=
7878
github.com/RoaringBitmap/roaring v0.4.23/go.mod h1:D0gp8kJQgE1A4LQ5wFLggQEyvDi06Mq5mKs52e1TwOo=
@@ -831,8 +831,9 @@ golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliY
831831
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
832832
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
833833
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
834-
golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus=
835834
golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M=
835+
golang.org/x/crypto v0.35.0 h1:b15kiHdrGCHrP6LvwaQ3c03kgNhhiMgvlhxHQhmg2Xs=
836+
golang.org/x/crypto v0.35.0/go.mod h1:dy7dXNW32cAb/6/PRuTNsix8T+vJAqvuIy5Bli/x0YQ=
836837
golang.org/x/exp v0.0.0-20250218142911-aa4b98e5adaa h1:t2QcU6V556bFjYgu4L6C+6VrCPyJZ+eyRsABUPs1mz4=
837838
golang.org/x/exp v0.0.0-20250218142911-aa4b98e5adaa/go.mod h1:BHOTPb3L19zxehTsLoJXVaTktb06DFgmdW6Wb9s8jqk=
838839
golang.org/x/image v0.24.0 h1:AN7zRgVsbvmTfNyqIbbOraYL8mSwcKncEj8ofjgzcMQ=
@@ -868,8 +869,8 @@ golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
868869
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
869870
golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8=
870871
golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk=
871-
golang.org/x/oauth2 v0.26.0 h1:afQXWNNaeC4nvZ0Ed9XvCCzXM6UHJG7iCg0W4fPqSBE=
872-
golang.org/x/oauth2 v0.26.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
872+
golang.org/x/oauth2 v0.27.0 h1:da9Vo7/tDv5RH/7nZDz1eMGS/q1Vv1N/7FCrBhI9I3M=
873+
golang.org/x/oauth2 v0.27.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8=
873874
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
874875
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
875876
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=

models/activities/action.go

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,24 @@ func ActivityReadable(user, doer *user_model.User) bool {
454454
doer != nil && (doer.IsAdmin || user.ID == doer.ID)
455455
}
456456

457+
func FeedDateCond(opts GetFeedsOptions) builder.Cond {
458+
cond := builder.NewCond()
459+
if opts.Date == "" {
460+
return cond
461+
}
462+
463+
dateLow, err := time.ParseInLocation("2006-01-02", opts.Date, setting.DefaultUILocation)
464+
if err != nil {
465+
log.Warn("Unable to parse %s, filter not applied: %v", opts.Date, err)
466+
} else {
467+
dateHigh := dateLow.Add(86399000000000) // 23h59m59s
468+
469+
cond = cond.And(builder.Gte{"`action`.created_unix": dateLow.Unix()})
470+
cond = cond.And(builder.Lte{"`action`.created_unix": dateHigh.Unix()})
471+
}
472+
return cond
473+
}
474+
457475
func ActivityQueryCondition(ctx context.Context, opts GetFeedsOptions) (builder.Cond, error) {
458476
cond := builder.NewCond()
459477

@@ -534,17 +552,7 @@ func ActivityQueryCondition(ctx context.Context, opts GetFeedsOptions) (builder.
534552
cond = cond.And(builder.Eq{"is_deleted": false})
535553
}
536554

537-
if opts.Date != "" {
538-
dateLow, err := time.ParseInLocation("2006-01-02", opts.Date, setting.DefaultUILocation)
539-
if err != nil {
540-
log.Warn("Unable to parse %s, filter not applied: %v", opts.Date, err)
541-
} else {
542-
dateHigh := dateLow.Add(86399000000000) // 23h59m59s
543-
544-
cond = cond.And(builder.Gte{"`action`.created_unix": dateLow.Unix()})
545-
cond = cond.And(builder.Lte{"`action`.created_unix": dateHigh.Unix()})
546-
}
547-
}
555+
cond = cond.And(FeedDateCond(opts))
548556

549557
return cond, nil
550558
}

0 commit comments

Comments
 (0)