Merge branch 'main' into lunny/commit_status_webhook
1
.github/workflows/files-changed.yml
vendored
@ -48,6 +48,7 @@ jobs:
|
|||||||
- "Makefile"
|
- "Makefile"
|
||||||
- ".golangci.yml"
|
- ".golangci.yml"
|
||||||
- ".editorconfig"
|
- ".editorconfig"
|
||||||
|
- "options/locale/locale_en-US.ini"
|
||||||
|
|
||||||
frontend:
|
frontend:
|
||||||
- "**/*.js"
|
- "**/*.js"
|
||||||
|
18
.github/workflows/pull-db-tests.yml
vendored
@ -49,7 +49,10 @@ jobs:
|
|||||||
- run: make backend
|
- run: make backend
|
||||||
env:
|
env:
|
||||||
TAGS: bindata
|
TAGS: bindata
|
||||||
- run: make test-pgsql-migration test-pgsql
|
- name: run migration tests
|
||||||
|
run: make test-pgsql-migration
|
||||||
|
- name: run tests
|
||||||
|
run: make test-pgsql
|
||||||
timeout-minutes: 50
|
timeout-minutes: 50
|
||||||
env:
|
env:
|
||||||
TAGS: bindata gogit
|
TAGS: bindata gogit
|
||||||
@ -72,7 +75,10 @@ jobs:
|
|||||||
- run: make backend
|
- run: make backend
|
||||||
env:
|
env:
|
||||||
TAGS: bindata gogit sqlite sqlite_unlock_notify
|
TAGS: bindata gogit sqlite sqlite_unlock_notify
|
||||||
- run: make test-sqlite-migration test-sqlite
|
- name: run migration tests
|
||||||
|
run: make test-sqlite-migration
|
||||||
|
- name: run tests
|
||||||
|
run: make test-sqlite
|
||||||
timeout-minutes: 50
|
timeout-minutes: 50
|
||||||
env:
|
env:
|
||||||
TAGS: bindata gogit sqlite sqlite_unlock_notify
|
TAGS: bindata gogit sqlite sqlite_unlock_notify
|
||||||
@ -175,8 +181,10 @@ jobs:
|
|||||||
- run: make backend
|
- run: make backend
|
||||||
env:
|
env:
|
||||||
TAGS: bindata
|
TAGS: bindata
|
||||||
|
- name: run migration tests
|
||||||
|
run: make test-mysql-migration
|
||||||
- name: run tests
|
- name: run tests
|
||||||
run: make test-mysql-migration integration-test-coverage
|
run: make integration-test-coverage
|
||||||
env:
|
env:
|
||||||
TAGS: bindata
|
TAGS: bindata
|
||||||
RACE_ENABLED: true
|
RACE_ENABLED: true
|
||||||
@ -208,7 +216,9 @@ jobs:
|
|||||||
- run: make backend
|
- run: make backend
|
||||||
env:
|
env:
|
||||||
TAGS: bindata
|
TAGS: bindata
|
||||||
- run: make test-mssql-migration test-mssql
|
- run: make test-mssql-migration
|
||||||
|
- name: run tests
|
||||||
|
run: make test-mssql
|
||||||
timeout-minutes: 50
|
timeout-minutes: 50
|
||||||
env:
|
env:
|
||||||
TAGS: bindata
|
TAGS: bindata
|
||||||
|
@ -464,7 +464,7 @@ We assume in good faith that the information you provide is legally binding.
|
|||||||
We adopted a release schedule to streamline the process of working on, finishing, and issuing releases. \
|
We adopted a release schedule to streamline the process of working on, finishing, and issuing releases. \
|
||||||
The overall goal is to make a major release every three or four months, which breaks down into two or three months of general development followed by one month of testing and polishing known as the release freeze. \
|
The overall goal is to make a major release every three or four months, which breaks down into two or three months of general development followed by one month of testing and polishing known as the release freeze. \
|
||||||
All the feature pull requests should be
|
All the feature pull requests should be
|
||||||
merged before feature freeze. And, during the frozen period, a corresponding
|
merged before feature freeze. All feature pull requests haven't been merged before this feature freeze will be moved to next milestone, please notice our feature freeze announcement on discord. And, during the frozen period, a corresponding
|
||||||
release branch is open for fixes backported from main branch. Release candidates
|
release branch is open for fixes backported from main branch. Release candidates
|
||||||
are made during this period for user testing to
|
are made during this period for user testing to
|
||||||
obtain a final version that is maintained in this branch.
|
obtain a final version that is maintained in this branch.
|
||||||
|
22
Makefile
@ -115,6 +115,7 @@ LINUX_ARCHS ?= linux/amd64,linux/386,linux/arm-5,linux/arm-6,linux/arm64
|
|||||||
|
|
||||||
GO_PACKAGES ?= $(filter-out code.gitea.io/gitea/tests/integration/migration-test code.gitea.io/gitea/tests code.gitea.io/gitea/tests/integration code.gitea.io/gitea/tests/e2e,$(shell $(GO) list ./... | grep -v /vendor/))
|
GO_PACKAGES ?= $(filter-out code.gitea.io/gitea/tests/integration/migration-test code.gitea.io/gitea/tests code.gitea.io/gitea/tests/integration code.gitea.io/gitea/tests/e2e,$(shell $(GO) list ./... | grep -v /vendor/))
|
||||||
GO_TEST_PACKAGES ?= $(filter-out $(shell $(GO) list code.gitea.io/gitea/models/migrations/...) code.gitea.io/gitea/tests/integration/migration-test code.gitea.io/gitea/tests code.gitea.io/gitea/tests/integration code.gitea.io/gitea/tests/e2e,$(shell $(GO) list ./... | grep -v /vendor/))
|
GO_TEST_PACKAGES ?= $(filter-out $(shell $(GO) list code.gitea.io/gitea/models/migrations/...) code.gitea.io/gitea/tests/integration/migration-test code.gitea.io/gitea/tests code.gitea.io/gitea/tests/integration code.gitea.io/gitea/tests/e2e,$(shell $(GO) list ./... | grep -v /vendor/))
|
||||||
|
MIGRATE_TEST_PACKAGES ?= $(shell $(GO) list code.gitea.io/gitea/models/migrations/...)
|
||||||
|
|
||||||
FOMANTIC_WORK_DIR := web_src/fomantic
|
FOMANTIC_WORK_DIR := web_src/fomantic
|
||||||
|
|
||||||
@ -147,6 +148,7 @@ GO_DIRS := build cmd models modules routers services tests
|
|||||||
WEB_DIRS := web_src/js web_src/css
|
WEB_DIRS := web_src/js web_src/css
|
||||||
|
|
||||||
SPELLCHECK_FILES := $(GO_DIRS) $(WEB_DIRS) docs/content templates options/locale/locale_en-US.ini .github
|
SPELLCHECK_FILES := $(GO_DIRS) $(WEB_DIRS) docs/content templates options/locale/locale_en-US.ini .github
|
||||||
|
EDITORCONFIG_FILES := templates .github/workflows options/locale/locale_en-US.ini
|
||||||
|
|
||||||
GO_SOURCES := $(wildcard *.go)
|
GO_SOURCES := $(wildcard *.go)
|
||||||
GO_SOURCES += $(shell find $(GO_DIRS) -type f -name "*.go" ! -path modules/options/bindata.go ! -path modules/public/bindata.go ! -path modules/templates/bindata.go)
|
GO_SOURCES += $(shell find $(GO_DIRS) -type f -name "*.go" ! -path modules/options/bindata.go ! -path modules/public/bindata.go ! -path modules/templates/bindata.go)
|
||||||
@ -426,7 +428,7 @@ lint-go-vet:
|
|||||||
|
|
||||||
.PHONY: lint-editorconfig
|
.PHONY: lint-editorconfig
|
||||||
lint-editorconfig:
|
lint-editorconfig:
|
||||||
$(GO) run $(EDITORCONFIG_CHECKER_PACKAGE) templates .github/workflows
|
@$(GO) run $(EDITORCONFIG_CHECKER_PACKAGE) $(EDITORCONFIG_FILES)
|
||||||
|
|
||||||
.PHONY: lint-actions
|
.PHONY: lint-actions
|
||||||
lint-actions:
|
lint-actions:
|
||||||
@ -709,9 +711,7 @@ migrations.sqlite.test: $(GO_SOURCES) generate-ini-sqlite
|
|||||||
|
|
||||||
.PHONY: migrations.individual.mysql.test
|
.PHONY: migrations.individual.mysql.test
|
||||||
migrations.individual.mysql.test: $(GO_SOURCES)
|
migrations.individual.mysql.test: $(GO_SOURCES)
|
||||||
for pkg in $(shell $(GO) list code.gitea.io/gitea/models/migrations/...); do \
|
GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini $(GO) test $(GOTESTFLAGS) -tags='$(TEST_TAGS)' -p 1 $(MIGRATE_TEST_PACKAGES)
|
||||||
GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' $$pkg; \
|
|
||||||
done
|
|
||||||
|
|
||||||
.PHONY: migrations.individual.sqlite.test\#%
|
.PHONY: migrations.individual.sqlite.test\#%
|
||||||
migrations.individual.sqlite.test\#%: $(GO_SOURCES) generate-ini-sqlite
|
migrations.individual.sqlite.test\#%: $(GO_SOURCES) generate-ini-sqlite
|
||||||
@ -719,20 +719,15 @@ migrations.individual.sqlite.test\#%: $(GO_SOURCES) generate-ini-sqlite
|
|||||||
|
|
||||||
.PHONY: migrations.individual.pgsql.test
|
.PHONY: migrations.individual.pgsql.test
|
||||||
migrations.individual.pgsql.test: $(GO_SOURCES)
|
migrations.individual.pgsql.test: $(GO_SOURCES)
|
||||||
for pkg in $(shell $(GO) list code.gitea.io/gitea/models/migrations/...); do \
|
GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini $(GO) test $(GOTESTFLAGS) -tags='$(TEST_TAGS)' -p 1 $(MIGRATE_TEST_PACKAGES)
|
||||||
GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' $$pkg; \
|
|
||||||
done
|
|
||||||
|
|
||||||
.PHONY: migrations.individual.pgsql.test\#%
|
.PHONY: migrations.individual.pgsql.test\#%
|
||||||
migrations.individual.pgsql.test\#%: $(GO_SOURCES) generate-ini-pgsql
|
migrations.individual.pgsql.test\#%: $(GO_SOURCES) generate-ini-pgsql
|
||||||
GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' code.gitea.io/gitea/models/migrations/$*
|
GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' code.gitea.io/gitea/models/migrations/$*
|
||||||
|
|
||||||
|
|
||||||
.PHONY: migrations.individual.mssql.test
|
.PHONY: migrations.individual.mssql.test
|
||||||
migrations.individual.mssql.test: $(GO_SOURCES) generate-ini-mssql
|
migrations.individual.mssql.test: $(GO_SOURCES) generate-ini-mssql
|
||||||
for pkg in $(shell $(GO) list code.gitea.io/gitea/models/migrations/...); do \
|
GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mssql.ini $(GO) test $(GOTESTFLAGS) -tags='$(TEST_TAGS)' -p 1 $(MIGRATE_TEST_PACKAGES)
|
||||||
GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mssql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' $$pkg -test.failfast; \
|
|
||||||
done
|
|
||||||
|
|
||||||
.PHONY: migrations.individual.mssql.test\#%
|
.PHONY: migrations.individual.mssql.test\#%
|
||||||
migrations.individual.mssql.test\#%: $(GO_SOURCES) generate-ini-mssql
|
migrations.individual.mssql.test\#%: $(GO_SOURCES) generate-ini-mssql
|
||||||
@ -740,9 +735,7 @@ migrations.individual.mssql.test\#%: $(GO_SOURCES) generate-ini-mssql
|
|||||||
|
|
||||||
.PHONY: migrations.individual.sqlite.test
|
.PHONY: migrations.individual.sqlite.test
|
||||||
migrations.individual.sqlite.test: $(GO_SOURCES) generate-ini-sqlite
|
migrations.individual.sqlite.test: $(GO_SOURCES) generate-ini-sqlite
|
||||||
for pkg in $(shell $(GO) list code.gitea.io/gitea/models/migrations/...); do \
|
GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini $(GO) test $(GOTESTFLAGS) -tags='$(TEST_TAGS)' -p 1 $(MIGRATE_TEST_PACKAGES)
|
||||||
GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' $$pkg; \
|
|
||||||
done
|
|
||||||
|
|
||||||
.PHONY: migrations.individual.sqlite.test\#%
|
.PHONY: migrations.individual.sqlite.test\#%
|
||||||
migrations.individual.sqlite.test\#%: $(GO_SOURCES) generate-ini-sqlite
|
migrations.individual.sqlite.test\#%: $(GO_SOURCES) generate-ini-sqlite
|
||||||
@ -908,6 +901,7 @@ fomantic:
|
|||||||
cd $(FOMANTIC_WORK_DIR) && npm install --no-save
|
cd $(FOMANTIC_WORK_DIR) && npm install --no-save
|
||||||
cp -f $(FOMANTIC_WORK_DIR)/theme.config.less $(FOMANTIC_WORK_DIR)/node_modules/fomantic-ui/src/theme.config
|
cp -f $(FOMANTIC_WORK_DIR)/theme.config.less $(FOMANTIC_WORK_DIR)/node_modules/fomantic-ui/src/theme.config
|
||||||
cp -rf $(FOMANTIC_WORK_DIR)/_site $(FOMANTIC_WORK_DIR)/node_modules/fomantic-ui/src/
|
cp -rf $(FOMANTIC_WORK_DIR)/_site $(FOMANTIC_WORK_DIR)/node_modules/fomantic-ui/src/
|
||||||
|
$(SED_INPLACE) -e 's/ overrideBrowserslist\r/ overrideBrowserslist: ["defaults"]\r/g' $(FOMANTIC_WORK_DIR)/node_modules/fomantic-ui/tasks/config/tasks.js
|
||||||
cd $(FOMANTIC_WORK_DIR) && npx gulp -f node_modules/fomantic-ui/gulpfile.js build
|
cd $(FOMANTIC_WORK_DIR) && npx gulp -f node_modules/fomantic-ui/gulpfile.js build
|
||||||
# fomantic uses "touchstart" as click event for some browsers, it's not ideal, so we force fomantic to always use "click" as click event
|
# fomantic uses "touchstart" as click event for some browsers, it's not ideal, so we force fomantic to always use "click" as click event
|
||||||
$(SED_INPLACE) -e 's/clickEvent[ \t]*=/clickEvent = "click", unstableClickEvent =/g' $(FOMANTIC_WORK_DIR)/build/semantic.js
|
$(SED_INPLACE) -e 's/clickEvent[ \t]*=/clickEvent = "click", unstableClickEvent =/g' $(FOMANTIC_WORK_DIR)/build/semantic.js
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
asymkey_model "code.gitea.io/gitea/models/asymkey"
|
|
||||||
"code.gitea.io/gitea/modules/graceful"
|
"code.gitea.io/gitea/modules/graceful"
|
||||||
|
asymkey_service "code.gitea.io/gitea/services/asymkey"
|
||||||
repo_service "code.gitea.io/gitea/services/repository"
|
repo_service "code.gitea.io/gitea/services/repository"
|
||||||
|
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
@ -42,5 +42,5 @@ func runRegenerateKeys(_ *cli.Context) error {
|
|||||||
if err := initDB(ctx); err != nil {
|
if err := initDB(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return asymkey_model.RewriteAllPublicKeys(ctx)
|
return asymkey_service.RewriteAllPublicKeys(ctx)
|
||||||
}
|
}
|
||||||
|
@ -224,7 +224,7 @@ Please check [Gitea's logs](administration/logging-config.md) for error messages
|
|||||||
{{if not (eq .Body "")}}
|
{{if not (eq .Body "")}}
|
||||||
<h3>Message content</h3>
|
<h3>Message content</h3>
|
||||||
<hr>
|
<hr>
|
||||||
{{.Body | SanitizeHTML}}
|
{{.Body}}
|
||||||
{{end}}
|
{{end}}
|
||||||
</p>
|
</p>
|
||||||
<hr>
|
<hr>
|
||||||
|
@ -207,7 +207,7 @@ _主题_ 和 _邮件正文_ 由 [Golang的模板引擎](https://go.dev/pkg/text/
|
|||||||
{{if not (eq .Body "")}}
|
{{if not (eq .Body "")}}
|
||||||
<h3>消息内容:</h3>
|
<h3>消息内容:</h3>
|
||||||
<hr>
|
<hr>
|
||||||
{{.Body | SanitizeHTML}}
|
{{.Body}}
|
||||||
{{end}}
|
{{end}}
|
||||||
</p>
|
</p>
|
||||||
<hr>
|
<hr>
|
||||||
|
@ -47,7 +47,7 @@ We recommend [Google HTML/CSS Style Guide](https://google.github.io/styleguide/h
|
|||||||
9. Avoid unnecessary `!important` in CSS, add comments to explain why it's necessary if it can't be avoided.
|
9. Avoid unnecessary `!important` in CSS, add comments to explain why it's necessary if it can't be avoided.
|
||||||
10. Avoid mixing different events in one event listener, prefer to use individual event listeners for every event.
|
10. Avoid mixing different events in one event listener, prefer to use individual event listeners for every event.
|
||||||
11. Custom event names are recommended to use `ce-` prefix.
|
11. Custom event names are recommended to use `ce-` prefix.
|
||||||
12. Gitea's tailwind-style CSS classes use `gt-` prefix (`gt-relative`), while Gitea's own private framework-level CSS classes use `g-` prefix (`g-modal-confirm`).
|
12. Prefer using Tailwind CSS which is available via `tw-` prefix, e.g. `tw-relative`. Gitea's helper CSS classes use `gt-` prefix (`gt-df`), while Gitea's own private framework-level CSS classes use `g-` prefix (`g-modal-confirm`).
|
||||||
13. Avoid inline scripts & styles as much as possible, it's recommended to put JS code into JS files and use CSS classes. If inline scripts & styles are unavoidable, explain the reason why it can't be avoided.
|
13. Avoid inline scripts & styles as much as possible, it's recommended to put JS code into JS files and use CSS classes. If inline scripts & styles are unavoidable, explain the reason why it can't be avoided.
|
||||||
|
|
||||||
### Accessibility / ARIA
|
### Accessibility / ARIA
|
||||||
|
@ -47,7 +47,7 @@ HTML 页面由[Go HTML Template](https://pkg.go.dev/html/template)渲染。
|
|||||||
9. 避免在 CSS 中使用不必要的`!important`,如果无法避免,添加注释解释为什么需要它。
|
9. 避免在 CSS 中使用不必要的`!important`,如果无法避免,添加注释解释为什么需要它。
|
||||||
10. 避免在一个事件监听器中混合不同的事件,优先为每个事件使用独立的事件监听器。
|
10. 避免在一个事件监听器中混合不同的事件,优先为每个事件使用独立的事件监听器。
|
||||||
11. 推荐使用自定义事件名称前缀`ce-`。
|
11. 推荐使用自定义事件名称前缀`ce-`。
|
||||||
12. Gitea 的 tailwind-style CSS 类使用`gt-`前缀(`gt-relative`),而 Gitea 自身的私有框架级 CSS 类使用`g-`前缀(`g-modal-confirm`)。
|
12. 建议使用 Tailwind CSS,它可以通过 `tw-` 前缀获得,例如 `tw-relative`. Gitea 自身的助手类 CSS 使用 `gt-` 前缀(`gt-df`),Gitea 自身的私有框架级 CSS 类使用 `g-` 前缀(`g-modal-confirm`)。
|
||||||
13. 尽量避免内联脚本和样式,建议将JS代码放入JS文件中并使用CSS类。如果内联脚本和样式不可避免,请解释无法避免的原因。
|
13. 尽量避免内联脚本和样式,建议将JS代码放入JS文件中并使用CSS类。如果内联脚本和样式不可避免,请解释无法避免的原因。
|
||||||
|
|
||||||
### 可访问性 / ARIA
|
### 可访问性 / ARIA
|
||||||
|
12
go.mod
@ -49,7 +49,7 @@ require (
|
|||||||
github.com/go-ldap/ldap/v3 v3.4.6
|
github.com/go-ldap/ldap/v3 v3.4.6
|
||||||
github.com/go-sql-driver/mysql v1.7.1
|
github.com/go-sql-driver/mysql v1.7.1
|
||||||
github.com/go-swagger/go-swagger v0.30.5
|
github.com/go-swagger/go-swagger v0.30.5
|
||||||
github.com/go-testfixtures/testfixtures/v3 v3.9.0
|
github.com/go-testfixtures/testfixtures/v3 v3.10.0
|
||||||
github.com/go-webauthn/webauthn v0.10.0
|
github.com/go-webauthn/webauthn v0.10.0
|
||||||
github.com/gobwas/glob v0.2.3
|
github.com/gobwas/glob v0.2.3
|
||||||
github.com/gogs/chardet v0.0.0-20211120154057-b7413eaefb8f
|
github.com/gogs/chardet v0.0.0-20211120154057-b7413eaefb8f
|
||||||
@ -57,7 +57,7 @@ require (
|
|||||||
github.com/golang-jwt/jwt/v5 v5.2.0
|
github.com/golang-jwt/jwt/v5 v5.2.0
|
||||||
github.com/google/go-github/v57 v57.0.0
|
github.com/google/go-github/v57 v57.0.0
|
||||||
github.com/google/pprof v0.0.0-20240117000934-35fc243c5815
|
github.com/google/pprof v0.0.0-20240117000934-35fc243c5815
|
||||||
github.com/google/uuid v1.5.0
|
github.com/google/uuid v1.6.0
|
||||||
github.com/gorilla/feeds v1.1.2
|
github.com/gorilla/feeds v1.1.2
|
||||||
github.com/gorilla/sessions v1.2.2
|
github.com/gorilla/sessions v1.2.2
|
||||||
github.com/hashicorp/go-version v1.6.0
|
github.com/hashicorp/go-version v1.6.0
|
||||||
@ -73,7 +73,7 @@ require (
|
|||||||
github.com/lib/pq v1.10.9
|
github.com/lib/pq v1.10.9
|
||||||
github.com/markbates/goth v1.78.0
|
github.com/markbates/goth v1.78.0
|
||||||
github.com/mattn/go-isatty v0.0.20
|
github.com/mattn/go-isatty v0.0.20
|
||||||
github.com/mattn/go-sqlite3 v1.14.19
|
github.com/mattn/go-sqlite3 v1.14.22
|
||||||
github.com/meilisearch/meilisearch-go v0.26.1
|
github.com/meilisearch/meilisearch-go v0.26.1
|
||||||
github.com/mholt/archiver/v3 v3.5.1
|
github.com/mholt/archiver/v3 v3.5.1
|
||||||
github.com/microcosm-cc/bluemonday v1.0.26
|
github.com/microcosm-cc/bluemonday v1.0.26
|
||||||
@ -113,7 +113,7 @@ require (
|
|||||||
golang.org/x/text v0.14.0
|
golang.org/x/text v0.14.0
|
||||||
golang.org/x/tools v0.17.0
|
golang.org/x/tools v0.17.0
|
||||||
google.golang.org/grpc v1.60.1
|
google.golang.org/grpc v1.60.1
|
||||||
google.golang.org/protobuf v1.32.0
|
google.golang.org/protobuf v1.33.0
|
||||||
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
|
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
|
||||||
gopkg.in/ini.v1 v1.67.0
|
gopkg.in/ini.v1 v1.67.0
|
||||||
gopkg.in/yaml.v3 v3.0.1
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
@ -129,7 +129,7 @@ require (
|
|||||||
dario.cat/mergo v1.0.0 // indirect
|
dario.cat/mergo v1.0.0 // indirect
|
||||||
git.sr.ht/~mariusor/go-xsd-duration v0.0.0-20220703122237-02e73435a078 // indirect
|
git.sr.ht/~mariusor/go-xsd-duration v0.0.0-20220703122237-02e73435a078 // indirect
|
||||||
github.com/ClickHouse/ch-go v0.61.1 // indirect
|
github.com/ClickHouse/ch-go v0.61.1 // indirect
|
||||||
github.com/ClickHouse/clickhouse-go/v2 v2.17.1 // indirect
|
github.com/ClickHouse/clickhouse-go/v2 v2.18.0 // indirect
|
||||||
github.com/DataDog/zstd v1.5.5 // indirect
|
github.com/DataDog/zstd v1.5.5 // indirect
|
||||||
github.com/Masterminds/goutils v1.1.1 // indirect
|
github.com/Masterminds/goutils v1.1.1 // indirect
|
||||||
github.com/Masterminds/semver/v3 v3.2.1 // indirect
|
github.com/Masterminds/semver/v3 v3.2.1 // indirect
|
||||||
@ -241,7 +241,7 @@ require (
|
|||||||
github.com/oklog/ulid v1.3.1 // indirect
|
github.com/oklog/ulid v1.3.1 // indirect
|
||||||
github.com/olekukonko/tablewriter v0.0.5 // indirect
|
github.com/olekukonko/tablewriter v0.0.5 // indirect
|
||||||
github.com/onsi/ginkgo v1.16.5 // indirect
|
github.com/onsi/ginkgo v1.16.5 // indirect
|
||||||
github.com/paulmach/orb v0.11.0 // indirect
|
github.com/paulmach/orb v0.11.1 // indirect
|
||||||
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
|
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
|
||||||
github.com/pierrec/lz4/v4 v4.1.21 // indirect
|
github.com/pierrec/lz4/v4 v4.1.21 // indirect
|
||||||
github.com/pjbgf/sha1cd v0.3.0 // indirect
|
github.com/pjbgf/sha1cd v0.3.0 // indirect
|
||||||
|
24
go.sum
@ -78,8 +78,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
|
|||||||
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||||
github.com/ClickHouse/ch-go v0.61.1 h1:j5rx3qnvcnYjhnP1IdXE/vdIRQiqgwAzyqOaasA6QCw=
|
github.com/ClickHouse/ch-go v0.61.1 h1:j5rx3qnvcnYjhnP1IdXE/vdIRQiqgwAzyqOaasA6QCw=
|
||||||
github.com/ClickHouse/ch-go v0.61.1/go.mod h1:myxt/JZgy2BYHFGQqzmaIpbfr5CMbs3YHVULaWQj5YU=
|
github.com/ClickHouse/ch-go v0.61.1/go.mod h1:myxt/JZgy2BYHFGQqzmaIpbfr5CMbs3YHVULaWQj5YU=
|
||||||
github.com/ClickHouse/clickhouse-go/v2 v2.17.1 h1:ZCmAYWpu75IyEi7+Yrs/uaAjiCGY5wfW5kXo64exkX4=
|
github.com/ClickHouse/clickhouse-go/v2 v2.18.0 h1:O1LicIeg2JS2V29fKRH4+yT3f6jvvcJBm506dpVQ4mQ=
|
||||||
github.com/ClickHouse/clickhouse-go/v2 v2.17.1/go.mod h1:rkGTvFDTLqLIm0ma+13xmcCfr/08Gvs7KmFt1tgiWHQ=
|
github.com/ClickHouse/clickhouse-go/v2 v2.18.0/go.mod h1:ztQvX6wm7kAbhJslS87EXEhOVNY/TObXwyURnGju5FQ=
|
||||||
github.com/DataDog/zstd v1.4.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
|
github.com/DataDog/zstd v1.4.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
|
||||||
github.com/DataDog/zstd v1.5.5 h1:oWf5W7GtOLgp6bciQYDmhHHjdhYkALu6S/5Ni9ZgSvQ=
|
github.com/DataDog/zstd v1.5.5 h1:oWf5W7GtOLgp6bciQYDmhHHjdhYkALu6S/5Ni9ZgSvQ=
|
||||||
github.com/DataDog/zstd v1.5.5/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw=
|
github.com/DataDog/zstd v1.5.5/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw=
|
||||||
@ -384,8 +384,8 @@ github.com/go-swagger/scan-repo-boundary v0.0.0-20180623220736-973b3573c013/go.m
|
|||||||
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
|
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
|
||||||
github.com/go-test/deep v1.1.0 h1:WOcxcdHcvdgThNXjw0t76K42FXTU7HpNQWHpA2HHNlg=
|
github.com/go-test/deep v1.1.0 h1:WOcxcdHcvdgThNXjw0t76K42FXTU7HpNQWHpA2HHNlg=
|
||||||
github.com/go-test/deep v1.1.0/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
|
github.com/go-test/deep v1.1.0/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
|
||||||
github.com/go-testfixtures/testfixtures/v3 v3.9.0 h1:938g5V+GWLVejm3Hc+nWCuEXRlcglZDDlN/t1gWzcSY=
|
github.com/go-testfixtures/testfixtures/v3 v3.10.0 h1:BrBwN7AuC+74g5qtk9D59TLGOaEa8Bw1WmIsf+SyzWc=
|
||||||
github.com/go-testfixtures/testfixtures/v3 v3.9.0/go.mod h1:cdsKD2ApFBjdog9jRsz6EJqF+LClq/hrwE9K/1Dzo4s=
|
github.com/go-testfixtures/testfixtures/v3 v3.10.0/go.mod h1:z8RoleoNtibi6Ar8ziCW7e6PQ+jWiqbUWvuv8AMe4lo=
|
||||||
github.com/go-webauthn/webauthn v0.10.0 h1:yuW2e1tXnRAwAvKrR4q4LQmc6XtCMH639/ypZGhZCwk=
|
github.com/go-webauthn/webauthn v0.10.0 h1:yuW2e1tXnRAwAvKrR4q4LQmc6XtCMH639/ypZGhZCwk=
|
||||||
github.com/go-webauthn/webauthn v0.10.0/go.mod h1:l0NiauXhL6usIKqNLCUM3Qir43GK7ORg8ggold0Uv/Y=
|
github.com/go-webauthn/webauthn v0.10.0/go.mod h1:l0NiauXhL6usIKqNLCUM3Qir43GK7ORg8ggold0Uv/Y=
|
||||||
github.com/go-webauthn/x v0.1.6 h1:QNAX+AWeqRt9loE8mULeWJCqhVG5D/jvdmJ47fIWCkQ=
|
github.com/go-webauthn/x v0.1.6 h1:QNAX+AWeqRt9loE8mULeWJCqhVG5D/jvdmJ47fIWCkQ=
|
||||||
@ -488,8 +488,8 @@ github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm4
|
|||||||
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
|
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
|
||||||
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
|
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
|
||||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||||
@ -643,8 +643,8 @@ github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m
|
|||||||
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
|
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
|
||||||
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||||
github.com/mattn/go-sqlite3 v1.11.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
|
github.com/mattn/go-sqlite3 v1.11.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
|
||||||
github.com/mattn/go-sqlite3 v1.14.19 h1:fhGleo2h1p8tVChob4I9HpmVFIAkKGpiukdrgQbWfGI=
|
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
|
||||||
github.com/mattn/go-sqlite3 v1.14.19/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
|
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
|
||||||
github.com/meilisearch/meilisearch-go v0.26.1 h1:3bmo2uLijX7kvBmiZ9LupVfC95TFcRJDgrRTzbOoE4A=
|
github.com/meilisearch/meilisearch-go v0.26.1 h1:3bmo2uLijX7kvBmiZ9LupVfC95TFcRJDgrRTzbOoE4A=
|
||||||
github.com/meilisearch/meilisearch-go v0.26.1/go.mod h1:SxuSqDcPBIykjWz1PX+KzsYzArNLSCadQodWs8extS0=
|
github.com/meilisearch/meilisearch-go v0.26.1/go.mod h1:SxuSqDcPBIykjWz1PX+KzsYzArNLSCadQodWs8extS0=
|
||||||
github.com/mholt/acmez v1.2.0 h1:1hhLxSgY5FvH5HCnGUuwbKY2VQVo8IU7rxXKSnZ7F30=
|
github.com/mholt/acmez v1.2.0 h1:1hhLxSgY5FvH5HCnGUuwbKY2VQVo8IU7rxXKSnZ7F30=
|
||||||
@ -718,8 +718,8 @@ github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8
|
|||||||
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
|
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
|
||||||
github.com/opencontainers/image-spec v1.1.0-rc6 h1:XDqvyKsJEbRtATzkgItUqBA7QHk58yxX1Ov9HERHNqU=
|
github.com/opencontainers/image-spec v1.1.0-rc6 h1:XDqvyKsJEbRtATzkgItUqBA7QHk58yxX1Ov9HERHNqU=
|
||||||
github.com/opencontainers/image-spec v1.1.0-rc6/go.mod h1:W4s4sFTMaBeK1BQLXbG4AdM2szdn85PY75RI83NrTrM=
|
github.com/opencontainers/image-spec v1.1.0-rc6/go.mod h1:W4s4sFTMaBeK1BQLXbG4AdM2szdn85PY75RI83NrTrM=
|
||||||
github.com/paulmach/orb v0.11.0 h1:JfVXJUBeH9ifc/OrhBY0lL16QsmPgpCHMlqSSYhcgAA=
|
github.com/paulmach/orb v0.11.1 h1:3koVegMC4X/WeiXYz9iswopaTwMem53NzTJuTF20JzU=
|
||||||
github.com/paulmach/orb v0.11.0/go.mod h1:5mULz1xQfs3bmQm63QEJA6lNGujuRafwA5S/EnuLaLU=
|
github.com/paulmach/orb v0.11.1/go.mod h1:5mULz1xQfs3bmQm63QEJA6lNGujuRafwA5S/EnuLaLU=
|
||||||
github.com/paulmach/protoscan v0.2.1/go.mod h1:SpcSwydNLrxUGSDvXvO0P7g7AuhJ7lcKfDlhJCDw2gY=
|
github.com/paulmach/protoscan v0.2.1/go.mod h1:SpcSwydNLrxUGSDvXvO0P7g7AuhJ7lcKfDlhJCDw2gY=
|
||||||
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
|
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
|
||||||
github.com/pelletier/go-toml v1.8.1/go.mod h1:T2/BmBdy8dvIRq1a/8aqjN41wvWlN4lrapLU/GW4pbc=
|
github.com/pelletier/go-toml v1.8.1/go.mod h1:T2/BmBdy8dvIRq1a/8aqjN41wvWlN4lrapLU/GW4pbc=
|
||||||
@ -1308,8 +1308,8 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba
|
|||||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||||
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||||
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
|
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
|
||||||
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
|
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
|
||||||
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc h1:2gGKlE2+asNV9m7xrywl36YYNnBG5ZQ0r/BOOxqPpmk=
|
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc h1:2gGKlE2+asNV9m7xrywl36YYNnBG5ZQ0r/BOOxqPpmk=
|
||||||
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc/go.mod h1:m7x9LTH6d71AHyAX77c9yqWCCa3UKHcVEj9y7hAtKDk=
|
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc/go.mod h1:m7x9LTH6d71AHyAX77c9yqWCCa3UKHcVEj9y7hAtKDk=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
@ -393,10 +393,14 @@ func (a *Action) GetCreate() time.Time {
|
|||||||
return a.CreatedUnix.AsTime()
|
return a.CreatedUnix.AsTime()
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetIssueInfos returns a list of issues associated with
|
// GetIssueInfos returns a list of associated information with the action.
|
||||||
// the action.
|
|
||||||
func (a *Action) GetIssueInfos() []string {
|
func (a *Action) GetIssueInfos() []string {
|
||||||
return strings.SplitN(a.Content, "|", 3)
|
// make sure it always returns 3 elements, because there are some access to the a[1] and a[2] without checking the length
|
||||||
|
ret := strings.SplitN(a.Content, "|", 3)
|
||||||
|
for len(ret) < 3 {
|
||||||
|
ret = append(ret, "")
|
||||||
|
}
|
||||||
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetIssueTitle returns the title of first issue associated with the action.
|
// GetIssueTitle returns the title of first issue associated with the action.
|
||||||
|
@ -12,7 +12,6 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
|
||||||
|
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
@ -44,6 +43,12 @@ const (
|
|||||||
|
|
||||||
var sshOpLocker sync.Mutex
|
var sshOpLocker sync.Mutex
|
||||||
|
|
||||||
|
func WithSSHOpLocker(f func() error) error {
|
||||||
|
sshOpLocker.Lock()
|
||||||
|
defer sshOpLocker.Unlock()
|
||||||
|
return f()
|
||||||
|
}
|
||||||
|
|
||||||
// AuthorizedStringForKey creates the authorized keys string appropriate for the provided key
|
// AuthorizedStringForKey creates the authorized keys string appropriate for the provided key
|
||||||
func AuthorizedStringForKey(key *PublicKey) string {
|
func AuthorizedStringForKey(key *PublicKey) string {
|
||||||
sb := &strings.Builder{}
|
sb := &strings.Builder{}
|
||||||
@ -114,65 +119,6 @@ func appendAuthorizedKeysToFile(keys ...*PublicKey) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RewriteAllPublicKeys removes any authorized key and rewrite all keys from database again.
|
|
||||||
// Note: db.GetEngine(ctx).Iterate does not get latest data after insert/delete, so we have to call this function
|
|
||||||
// outside any session scope independently.
|
|
||||||
func RewriteAllPublicKeys(ctx context.Context) error {
|
|
||||||
// Don't rewrite key if internal server
|
|
||||||
if setting.SSH.StartBuiltinServer || !setting.SSH.CreateAuthorizedKeysFile {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
sshOpLocker.Lock()
|
|
||||||
defer sshOpLocker.Unlock()
|
|
||||||
|
|
||||||
if setting.SSH.RootPath != "" {
|
|
||||||
// First of ensure that the RootPath is present, and if not make it with 0700 permissions
|
|
||||||
// This of course doesn't guarantee that this is the right directory for authorized_keys
|
|
||||||
// but at least if it's supposed to be this directory and it doesn't exist and we're the
|
|
||||||
// right user it will at least be created properly.
|
|
||||||
err := os.MkdirAll(setting.SSH.RootPath, 0o700)
|
|
||||||
if err != nil {
|
|
||||||
log.Error("Unable to MkdirAll(%s): %v", setting.SSH.RootPath, err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fPath := filepath.Join(setting.SSH.RootPath, "authorized_keys")
|
|
||||||
tmpPath := fPath + ".tmp"
|
|
||||||
t, err := os.OpenFile(tmpPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o600)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer func() {
|
|
||||||
t.Close()
|
|
||||||
if err := util.Remove(tmpPath); err != nil {
|
|
||||||
log.Warn("Unable to remove temporary authorized keys file: %s: Error: %v", tmpPath, err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
if setting.SSH.AuthorizedKeysBackup {
|
|
||||||
isExist, err := util.IsExist(fPath)
|
|
||||||
if err != nil {
|
|
||||||
log.Error("Unable to check if %s exists. Error: %v", fPath, err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if isExist {
|
|
||||||
bakPath := fmt.Sprintf("%s_%d.gitea_bak", fPath, time.Now().Unix())
|
|
||||||
if err = util.CopyFile(fPath, bakPath); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := RegeneratePublicKeys(ctx, t); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
t.Close()
|
|
||||||
return util.Rename(tmpPath, fPath)
|
|
||||||
}
|
|
||||||
|
|
||||||
// RegeneratePublicKeys regenerates the authorized_keys file
|
// RegeneratePublicKeys regenerates the authorized_keys file
|
||||||
func RegeneratePublicKeys(ctx context.Context, t io.StringWriter) error {
|
func RegeneratePublicKeys(ctx context.Context, t io.StringWriter) error {
|
||||||
if err := db.GetEngine(ctx).Where("type != ?", KeyTypePrincipal).Iterate(new(PublicKey), func(idx int, bean any) (err error) {
|
if err := db.GetEngine(ctx).Where("type != ?", KeyTypePrincipal).Iterate(new(PublicKey), func(idx int, bean any) (err error) {
|
||||||
|
@ -9,51 +9,11 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
"code.gitea.io/gitea/models/perm"
|
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
"code.gitea.io/gitea/modules/util"
|
"code.gitea.io/gitea/modules/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
// AddPrincipalKey adds new principal to database and authorized_principals file.
|
|
||||||
func AddPrincipalKey(ctx context.Context, ownerID int64, content string, authSourceID int64) (*PublicKey, error) {
|
|
||||||
dbCtx, committer, err := db.TxContext(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer committer.Close()
|
|
||||||
|
|
||||||
// Principals cannot be duplicated.
|
|
||||||
has, err := db.GetEngine(dbCtx).
|
|
||||||
Where("content = ? AND type = ?", content, KeyTypePrincipal).
|
|
||||||
Get(new(PublicKey))
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
} else if has {
|
|
||||||
return nil, ErrKeyAlreadyExist{0, "", content}
|
|
||||||
}
|
|
||||||
|
|
||||||
key := &PublicKey{
|
|
||||||
OwnerID: ownerID,
|
|
||||||
Name: content,
|
|
||||||
Content: content,
|
|
||||||
Mode: perm.AccessModeWrite,
|
|
||||||
Type: KeyTypePrincipal,
|
|
||||||
LoginSourceID: authSourceID,
|
|
||||||
}
|
|
||||||
if err = db.Insert(dbCtx, key); err != nil {
|
|
||||||
return nil, fmt.Errorf("addKey: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = committer.Commit(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
committer.Close()
|
|
||||||
|
|
||||||
return key, RewriteAllPrincipalKeys(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
// CheckPrincipalKeyString strips spaces and returns an error if the given principal contains newlines
|
// CheckPrincipalKeyString strips spaces and returns an error if the given principal contains newlines
|
||||||
func CheckPrincipalKeyString(ctx context.Context, user *user_model.User, content string) (_ string, err error) {
|
func CheckPrincipalKeyString(ctx context.Context, user *user_model.User, content string) (_ string, err error) {
|
||||||
if setting.SSH.Disabled {
|
if setting.SSH.Disabled {
|
||||||
|
@ -166,8 +166,7 @@ func preprocessDatabaseCollation(x *xorm.Engine) {
|
|||||||
|
|
||||||
// try to alter database collation to expected if the database is empty, it might fail in some cases (and it isn't necessary to succeed)
|
// try to alter database collation to expected if the database is empty, it might fail in some cases (and it isn't necessary to succeed)
|
||||||
// at the moment, there is no "altering" solution for MSSQL, site admin should manually change the database collation
|
// at the moment, there is no "altering" solution for MSSQL, site admin should manually change the database collation
|
||||||
// and there is a bug https://github.com/go-testfixtures/testfixtures/pull/182 mssql: Invalid object name 'information_schema.tables'.
|
if !r.CollationEquals(r.DatabaseCollation, r.ExpectedCollation) && r.ExistingTableNumber == 0 {
|
||||||
if !r.CollationEquals(r.DatabaseCollation, r.ExpectedCollation) && r.ExistingTableNumber == 0 && x.Dialect().URI().DBType == schemas.MYSQL {
|
|
||||||
if err = alterDatabaseCollation(x, r.ExpectedCollation); err != nil {
|
if err = alterDatabaseCollation(x, r.ExpectedCollation); err != nil {
|
||||||
log.Error("Failed to change database collation to %q: %v", r.ExpectedCollation, err)
|
log.Error("Failed to change database collation to %q: %v", r.ExpectedCollation, err)
|
||||||
} else {
|
} else {
|
||||||
|
@ -3,3 +3,35 @@
|
|||||||
hook_id: 1
|
hook_id: 1
|
||||||
uuid: uuid1
|
uuid: uuid1
|
||||||
is_delivered: true
|
is_delivered: true
|
||||||
|
is_succeed: false
|
||||||
|
request_content: >
|
||||||
|
{
|
||||||
|
"url": "/matrix-delivered",
|
||||||
|
"http_method":"PUT",
|
||||||
|
"headers": {
|
||||||
|
"X-Head": "42"
|
||||||
|
},
|
||||||
|
"body": "{}"
|
||||||
|
}
|
||||||
|
|
||||||
|
-
|
||||||
|
id: 2
|
||||||
|
hook_id: 1
|
||||||
|
uuid: uuid2
|
||||||
|
is_delivered: false
|
||||||
|
|
||||||
|
-
|
||||||
|
id: 3
|
||||||
|
hook_id: 1
|
||||||
|
uuid: uuid3
|
||||||
|
is_delivered: true
|
||||||
|
is_succeed: true
|
||||||
|
payload_content: '{"key":"value"}' # legacy task, payload saved in payload_content (and not in request_content)
|
||||||
|
request_content: >
|
||||||
|
{
|
||||||
|
"url": "/matrix-success",
|
||||||
|
"http_method":"PUT",
|
||||||
|
"headers": {
|
||||||
|
"X-Head": "42"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -520,7 +520,6 @@
|
|||||||
id: 75
|
id: 75
|
||||||
repo_id: 1
|
repo_id: 1
|
||||||
type: 8
|
type: 8
|
||||||
config: "{\"ProjectsMode\":\"all\"}"
|
|
||||||
created_unix: 946684810
|
created_unix: 946684810
|
||||||
|
|
||||||
-
|
-
|
||||||
|
@ -158,6 +158,11 @@ func GetBranch(ctx context.Context, repoID int64, branchName string) (*Branch, e
|
|||||||
return &branch, nil
|
return &branch, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetBranches(ctx context.Context, repoID int64, branchNames []string) ([]*Branch, error) {
|
||||||
|
branches := make([]*Branch, 0, len(branchNames))
|
||||||
|
return branches, db.GetEngine(ctx).Where("repo_id=?", repoID).In("name", branchNames).Find(&branches)
|
||||||
|
}
|
||||||
|
|
||||||
func AddBranches(ctx context.Context, branches []*Branch) error {
|
func AddBranches(ctx context.Context, branches []*Branch) error {
|
||||||
for _, branch := range branches {
|
for _, branch := range branches {
|
||||||
if _, err := db.GetEngine(ctx).Insert(branch); err != nil {
|
if _, err := db.GetEngine(ctx).Insert(branch); err != nil {
|
||||||
|
@ -36,12 +36,14 @@ func Test_DropTableColumns(t *testing.T) {
|
|||||||
"updated_unix",
|
"updated_unix",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
x.SetMapper(names.GonicMapper{})
|
||||||
|
|
||||||
for i := range columns {
|
for i := range columns {
|
||||||
x.SetMapper(names.GonicMapper{})
|
|
||||||
if err := x.Sync(new(DropTest)); err != nil {
|
if err := x.Sync(new(DropTest)); err != nil {
|
||||||
t.Errorf("unable to create DropTest table: %v", err)
|
t.Errorf("unable to create DropTest table: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
sess := x.NewSession()
|
sess := x.NewSession()
|
||||||
if err := sess.Begin(); err != nil {
|
if err := sess.Begin(); err != nil {
|
||||||
sess.Close()
|
sess.Close()
|
||||||
@ -64,7 +66,6 @@ func Test_DropTableColumns(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
for j := range columns[i+1:] {
|
for j := range columns[i+1:] {
|
||||||
x.SetMapper(names.GonicMapper{})
|
|
||||||
if err := x.Sync(new(DropTest)); err != nil {
|
if err := x.Sync(new(DropTest)); err != nil {
|
||||||
t.Errorf("unable to create DropTest table: %v", err)
|
t.Errorf("unable to create DropTest table: %v", err)
|
||||||
return
|
return
|
||||||
|
@ -0,0 +1,4 @@
|
|||||||
|
-
|
||||||
|
id: 1
|
||||||
|
repo_id: 1
|
||||||
|
index: 1
|
@ -0,0 +1,11 @@
|
|||||||
|
-
|
||||||
|
id: 1
|
||||||
|
uuid: a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11
|
||||||
|
issue_id: 1
|
||||||
|
release_id: 0
|
||||||
|
|
||||||
|
-
|
||||||
|
id: 2
|
||||||
|
uuid: a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a12
|
||||||
|
issue_id: 0
|
||||||
|
release_id: 1
|
@ -0,0 +1,3 @@
|
|||||||
|
-
|
||||||
|
id: 1
|
||||||
|
repo_id: 1
|
@ -0,0 +1,3 @@
|
|||||||
|
-
|
||||||
|
id: 1
|
||||||
|
repo_id: 1
|
@ -0,0 +1,3 @@
|
|||||||
|
-
|
||||||
|
id: 1
|
||||||
|
commit_sha: 19fe5caf872476db265596eaac1dc35ad1c6422d
|
@ -0,0 +1,3 @@
|
|||||||
|
-
|
||||||
|
id: 1
|
||||||
|
context_hash: 19fe5caf872476db265596eaac1dc35ad1c6422d
|
@ -0,0 +1,5 @@
|
|||||||
|
-
|
||||||
|
id: 1
|
||||||
|
commit_sha: 19fe5caf872476db265596eaac1dc35ad1c6422d
|
||||||
|
merge_base: 19fe5caf872476db265596eaac1dc35ad1c6422d
|
||||||
|
merged_commit_id: 19fe5caf872476db265596eaac1dc35ad1c6422d
|
@ -0,0 +1,3 @@
|
|||||||
|
-
|
||||||
|
id: 1
|
||||||
|
sha1: 19fe5caf872476db265596eaac1dc35ad1c6422d
|
@ -0,0 +1,3 @@
|
|||||||
|
-
|
||||||
|
id: 1
|
||||||
|
commit_id: 19fe5caf872476db265596eaac1dc35ad1c6422d
|
@ -0,0 +1,3 @@
|
|||||||
|
-
|
||||||
|
id: 1
|
||||||
|
commit_sha: 19fe5caf872476db265596eaac1dc35ad1c6422d
|
@ -0,0 +1,3 @@
|
|||||||
|
-
|
||||||
|
id: 1
|
||||||
|
commit_sha: 19fe5caf872476db265596eaac1dc35ad1c6422d
|
@ -0,0 +1,4 @@
|
|||||||
|
-
|
||||||
|
id: 1
|
||||||
|
description: the badge
|
||||||
|
image_url: https://gitea.com/myimage.png
|
@ -562,6 +562,10 @@ var migrations = []Migration{
|
|||||||
NewMigration("Use Slug instead of ID for Badges", v1_22.UseSlugInsteadOfIDForBadges),
|
NewMigration("Use Slug instead of ID for Badges", v1_22.UseSlugInsteadOfIDForBadges),
|
||||||
// v288 -> v289
|
// v288 -> v289
|
||||||
NewMigration("Add user_blocking table", v1_22.AddUserBlockingTable),
|
NewMigration("Add user_blocking table", v1_22.AddUserBlockingTable),
|
||||||
|
// v289 -> v290
|
||||||
|
NewMigration("Add default_wiki_branch to repository table", v1_22.AddDefaultWikiBranch),
|
||||||
|
// v290 -> v291
|
||||||
|
NewMigration("Add PayloadVersion to HookTask", v1_22.AddPayloadVersionToHookTaskTable),
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCurrentDBVersion returns the current db version
|
// GetCurrentDBVersion returns the current db version
|
||||||
|
@ -15,7 +15,6 @@ func Test_AddRepoIDForAttachment(t *testing.T) {
|
|||||||
type Attachment struct {
|
type Attachment struct {
|
||||||
ID int64 `xorm:"pk autoincr"`
|
ID int64 `xorm:"pk autoincr"`
|
||||||
UUID string `xorm:"uuid UNIQUE"`
|
UUID string `xorm:"uuid UNIQUE"`
|
||||||
RepoID int64 `xorm:"INDEX"` // this should not be zero
|
|
||||||
IssueID int64 `xorm:"INDEX"` // maybe zero when creating
|
IssueID int64 `xorm:"INDEX"` // maybe zero when creating
|
||||||
ReleaseID int64 `xorm:"INDEX"` // maybe zero when creating
|
ReleaseID int64 `xorm:"INDEX"` // maybe zero when creating
|
||||||
UploaderID int64 `xorm:"INDEX DEFAULT 0"`
|
UploaderID int64 `xorm:"INDEX DEFAULT 0"`
|
||||||
@ -44,12 +43,21 @@ func Test_AddRepoIDForAttachment(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var issueAttachments []*Attachment
|
type NewAttachment struct {
|
||||||
err := x.Where("issue_id > 0").Find(&issueAttachments)
|
ID int64 `xorm:"pk autoincr"`
|
||||||
|
UUID string `xorm:"uuid UNIQUE"`
|
||||||
|
RepoID int64 `xorm:"INDEX"` // this should not be zero
|
||||||
|
IssueID int64 `xorm:"INDEX"` // maybe zero when creating
|
||||||
|
ReleaseID int64 `xorm:"INDEX"` // maybe zero when creating
|
||||||
|
UploaderID int64 `xorm:"INDEX DEFAULT 0"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var issueAttachments []*NewAttachment
|
||||||
|
err := x.Table("attachment").Where("issue_id > 0").Find(&issueAttachments)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
for _, attach := range issueAttachments {
|
for _, attach := range issueAttachments {
|
||||||
assert.Greater(t, attach.RepoID, 0)
|
assert.Greater(t, attach.RepoID, int64(0))
|
||||||
assert.Greater(t, attach.IssueID, 0)
|
assert.Greater(t, attach.IssueID, int64(0))
|
||||||
var issue Issue
|
var issue Issue
|
||||||
has, err := x.ID(attach.IssueID).Get(&issue)
|
has, err := x.ID(attach.IssueID).Get(&issue)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
@ -57,12 +65,12 @@ func Test_AddRepoIDForAttachment(t *testing.T) {
|
|||||||
assert.EqualValues(t, attach.RepoID, issue.RepoID)
|
assert.EqualValues(t, attach.RepoID, issue.RepoID)
|
||||||
}
|
}
|
||||||
|
|
||||||
var releaseAttachments []*Attachment
|
var releaseAttachments []*NewAttachment
|
||||||
err = x.Where("release_id > 0").Find(&releaseAttachments)
|
err = x.Table("attachment").Where("release_id > 0").Find(&releaseAttachments)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
for _, attach := range releaseAttachments {
|
for _, attach := range releaseAttachments {
|
||||||
assert.Greater(t, attach.RepoID, 0)
|
assert.Greater(t, attach.RepoID, int64(0))
|
||||||
assert.Greater(t, attach.IssueID, 0)
|
assert.Greater(t, attach.ReleaseID, int64(0))
|
||||||
var release Release
|
var release Release
|
||||||
has, err := x.ID(attach.ReleaseID).Get(&release)
|
has, err := x.ID(attach.ReleaseID).Get(&release)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
@ -4,7 +4,10 @@
|
|||||||
package v1_22 //nolint
|
package v1_22 //nolint
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"xorm.io/xorm"
|
"xorm.io/xorm"
|
||||||
|
"xorm.io/xorm/schemas"
|
||||||
)
|
)
|
||||||
|
|
||||||
func AddCombinedIndexToIssueUser(x *xorm.Engine) error {
|
func AddCombinedIndexToIssueUser(x *xorm.Engine) error {
|
||||||
@ -20,8 +23,18 @@ func AddCombinedIndexToIssueUser(x *xorm.Engine) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, issueUser := range duplicatedIssueUsers {
|
for _, issueUser := range duplicatedIssueUsers {
|
||||||
if _, err := x.Exec("delete from issue_user where id in (SELECT id FROM issue_user WHERE issue_id = ? and uid = ? limit ?)", issueUser.IssueID, issueUser.UID, issueUser.Cnt-1); err != nil {
|
if x.Dialect().URI().DBType == schemas.MSSQL {
|
||||||
return err
|
if _, err := x.Exec(fmt.Sprintf("delete from issue_user where id in (SELECT top %d id FROM issue_user WHERE issue_id = ? and uid = ?)", issueUser.Cnt-1), issueUser.IssueID, issueUser.UID); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
var ids []int64
|
||||||
|
if err := x.SQL("SELECT id FROM issue_user WHERE issue_id = ? and uid = ? limit ?", issueUser.IssueID, issueUser.UID, issueUser.Cnt-1).Find(&ids); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if _, err := x.Table("issue_user").In("id", ids).Delete(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,9 +36,9 @@ func expandHashReferencesToSha256(x *xorm.Engine) error {
|
|||||||
if setting.Database.Type.IsMSSQL() {
|
if setting.Database.Type.IsMSSQL() {
|
||||||
// drop indexes that need to be re-created afterwards
|
// drop indexes that need to be re-created afterwards
|
||||||
droppedIndexes := []string{
|
droppedIndexes := []string{
|
||||||
"DROP INDEX commit_status.IDX_commit_status_context_hash",
|
"DROP INDEX IF EXISTS [IDX_commit_status_context_hash] ON [commit_status]",
|
||||||
"DROP INDEX review_state.UQE_review_state_pull_commit_user",
|
"DROP INDEX IF EXISTS [UQE_review_state_pull_commit_user] ON [review_state]",
|
||||||
"DROP INDEX repo_archiver.UQE_repo_archiver_s",
|
"DROP INDEX IF EXISTS [UQE_repo_archiver_s] ON [repo_archiver]",
|
||||||
}
|
}
|
||||||
for _, s := range droppedIndexes {
|
for _, s := range droppedIndexes {
|
||||||
_, err := db.Exec(s)
|
_, err := db.Exec(s)
|
||||||
@ -53,7 +53,7 @@ func expandHashReferencesToSha256(x *xorm.Engine) error {
|
|||||||
if setting.Database.Type.IsMySQL() {
|
if setting.Database.Type.IsMySQL() {
|
||||||
_, err = db.Exec(fmt.Sprintf("ALTER TABLE `%s` MODIFY COLUMN `%s` VARCHAR(64)", alts[0], alts[1]))
|
_, err = db.Exec(fmt.Sprintf("ALTER TABLE `%s` MODIFY COLUMN `%s` VARCHAR(64)", alts[0], alts[1]))
|
||||||
} else if setting.Database.Type.IsMSSQL() {
|
} else if setting.Database.Type.IsMSSQL() {
|
||||||
_, err = db.Exec(fmt.Sprintf("ALTER TABLE `%s` ALTER COLUMN `%s` VARCHAR(64)", alts[0], alts[1]))
|
_, err = db.Exec(fmt.Sprintf("ALTER TABLE [%s] ALTER COLUMN [%s] VARCHAR(64)", alts[0], alts[1]))
|
||||||
} else {
|
} else {
|
||||||
_, err = db.Exec(fmt.Sprintf("ALTER TABLE `%s` ALTER COLUMN `%s` TYPE VARCHAR(64)", alts[0], alts[1]))
|
_, err = db.Exec(fmt.Sprintf("ALTER TABLE `%s` ALTER COLUMN `%s` TYPE VARCHAR(64)", alts[0], alts[1]))
|
||||||
}
|
}
|
||||||
|
@ -17,14 +17,72 @@ func PrepareOldRepository(t *testing.T) (*xorm.Engine, func()) {
|
|||||||
ID int64 `xorm:"pk autoincr"`
|
ID int64 `xorm:"pk autoincr"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CommitStatus struct {
|
||||||
|
ID int64
|
||||||
|
ContextHash string
|
||||||
|
}
|
||||||
|
|
||||||
|
type RepoArchiver struct {
|
||||||
|
ID int64
|
||||||
|
RepoID int64
|
||||||
|
Type int
|
||||||
|
CommitID string
|
||||||
|
}
|
||||||
|
|
||||||
|
type ReviewState struct {
|
||||||
|
ID int64
|
||||||
|
CommitSHA string
|
||||||
|
UserID int64
|
||||||
|
PullID int64
|
||||||
|
}
|
||||||
|
|
||||||
|
type Comment struct {
|
||||||
|
ID int64
|
||||||
|
CommitSHA string
|
||||||
|
}
|
||||||
|
|
||||||
|
type PullRequest struct {
|
||||||
|
ID int64
|
||||||
|
CommitSHA string
|
||||||
|
MergeBase string
|
||||||
|
MergedCommitID string
|
||||||
|
}
|
||||||
|
|
||||||
|
type Release struct {
|
||||||
|
ID int64
|
||||||
|
Sha1 string
|
||||||
|
}
|
||||||
|
|
||||||
|
type RepoIndexerStatus struct {
|
||||||
|
ID int64
|
||||||
|
CommitSHA string
|
||||||
|
}
|
||||||
|
|
||||||
|
type Review struct {
|
||||||
|
ID int64
|
||||||
|
CommitID string
|
||||||
|
}
|
||||||
|
|
||||||
// Prepare and load the testing database
|
// Prepare and load the testing database
|
||||||
return base.PrepareTestEnv(t, 0, new(Repository))
|
return base.PrepareTestEnv(t, 0,
|
||||||
|
new(Repository),
|
||||||
|
new(CommitStatus),
|
||||||
|
new(RepoArchiver),
|
||||||
|
new(ReviewState),
|
||||||
|
new(Review),
|
||||||
|
new(Comment),
|
||||||
|
new(PullRequest),
|
||||||
|
new(Release),
|
||||||
|
new(RepoIndexerStatus),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_RepositoryFormat(t *testing.T) {
|
func Test_RepositoryFormat(t *testing.T) {
|
||||||
x, deferable := PrepareOldRepository(t)
|
x, deferable := PrepareOldRepository(t)
|
||||||
defer deferable()
|
defer deferable()
|
||||||
|
|
||||||
|
assert.NoError(t, AdjustDBForSha256(x))
|
||||||
|
|
||||||
type Repository struct {
|
type Repository struct {
|
||||||
ID int64 `xorm:"pk autoincr"`
|
ID int64 `xorm:"pk autoincr"`
|
||||||
ObjectFormatName string `xorg:"not null default('sha1')"`
|
ObjectFormatName string `xorg:"not null default('sha1')"`
|
||||||
@ -37,12 +95,10 @@ func Test_RepositoryFormat(t *testing.T) {
|
|||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.EqualValues(t, 4, count)
|
assert.EqualValues(t, 4, count)
|
||||||
|
|
||||||
assert.NoError(t, AdjustDBForSha256(x))
|
|
||||||
|
|
||||||
repo.ID = 20
|
|
||||||
repo.ObjectFormatName = "sha256"
|
repo.ObjectFormatName = "sha256"
|
||||||
_, err = x.Insert(repo)
|
_, err = x.Insert(repo)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
id := repo.ID
|
||||||
|
|
||||||
count, err = x.Count(new(Repository))
|
count, err = x.Count(new(Repository))
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
@ -55,7 +111,7 @@ func Test_RepositoryFormat(t *testing.T) {
|
|||||||
assert.EqualValues(t, "sha1", repo.ObjectFormatName)
|
assert.EqualValues(t, "sha1", repo.ObjectFormatName)
|
||||||
|
|
||||||
repo = new(Repository)
|
repo = new(Repository)
|
||||||
ok, err = x.ID(20).Get(repo)
|
ok, err = x.ID(id).Get(repo)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.EqualValues(t, true, ok)
|
assert.EqualValues(t, true, ok)
|
||||||
assert.EqualValues(t, "sha256", repo.ObjectFormatName)
|
assert.EqualValues(t, "sha256", repo.ObjectFormatName)
|
||||||
|
@ -20,20 +20,20 @@ func Test_UpdateBadgeColName(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Prepare and load the testing database
|
// Prepare and load the testing database
|
||||||
x, deferable := base.PrepareTestEnv(t, 0, new(BadgeUnique), new(Badge))
|
x, deferable := base.PrepareTestEnv(t, 0, new(Badge))
|
||||||
defer deferable()
|
defer deferable()
|
||||||
if x == nil || t.Failed() {
|
if x == nil || t.Failed() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
oldBadges := []Badge{
|
oldBadges := []*Badge{
|
||||||
{ID: 1, Description: "Test Badge 1", ImageURL: "https://example.com/badge1.png"},
|
{Description: "Test Badge 1", ImageURL: "https://example.com/badge1.png"},
|
||||||
{ID: 2, Description: "Test Badge 2", ImageURL: "https://example.com/badge2.png"},
|
{Description: "Test Badge 2", ImageURL: "https://example.com/badge2.png"},
|
||||||
{ID: 3, Description: "Test Badge 3", ImageURL: "https://example.com/badge3.png"},
|
{Description: "Test Badge 3", ImageURL: "https://example.com/badge3.png"},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, badge := range oldBadges {
|
for _, badge := range oldBadges {
|
||||||
_, err := x.Insert(&badge)
|
_, err := x.Insert(badge)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ func Test_UpdateBadgeColName(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i, e := range oldBadges {
|
for i, e := range oldBadges {
|
||||||
got := got[i]
|
got := got[i+1] // 1 is in the badge.yml
|
||||||
assert.Equal(t, e.ID, got.ID)
|
assert.Equal(t, e.ID, got.ID)
|
||||||
assert.Equal(t, fmt.Sprintf("%d", e.ID), got.Slug)
|
assert.Equal(t, fmt.Sprintf("%d", e.ID), got.Slug)
|
||||||
}
|
}
|
||||||
|
18
models/migrations/v1_22/v289.go
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
// Copyright 2024 The Gitea Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
package v1_22 //nolint
|
||||||
|
|
||||||
|
import "xorm.io/xorm"
|
||||||
|
|
||||||
|
func AddDefaultWikiBranch(x *xorm.Engine) error {
|
||||||
|
type Repository struct {
|
||||||
|
ID int64
|
||||||
|
DefaultWikiBranch string
|
||||||
|
}
|
||||||
|
if err := x.Sync(&Repository{}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err := x.Exec("UPDATE `repository` SET default_wiki_branch = 'master' WHERE (default_wiki_branch IS NULL) OR (default_wiki_branch = '')")
|
||||||
|
return err
|
||||||
|
}
|
17
models/migrations/v1_22/v290.go
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
// Copyright 2024 The Gitea Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
package v1_22 //nolint
|
||||||
|
|
||||||
|
import (
|
||||||
|
"xorm.io/xorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type HookTask struct {
|
||||||
|
PayloadVersion int `xorm:"DEFAULT 1"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func AddPayloadVersionToHookTaskTable(x *xorm.Engine) error {
|
||||||
|
// create missing column
|
||||||
|
return x.Sync(new(HookTask))
|
||||||
|
}
|
@ -232,7 +232,7 @@ func UpdateBoard(ctx context.Context, board *Board) error {
|
|||||||
func (p *Project) GetBoards(ctx context.Context) (BoardList, error) {
|
func (p *Project) GetBoards(ctx context.Context) (BoardList, error) {
|
||||||
boards := make([]*Board, 0, 5)
|
boards := make([]*Board, 0, 5)
|
||||||
|
|
||||||
if err := db.GetEngine(ctx).Where("project_id=? AND `default`=?", p.ID, false).OrderBy("Sorting").Find(&boards); err != nil {
|
if err := db.GetEngine(ctx).Where("project_id=? AND `default`=?", p.ID, false).OrderBy("sorting").Find(&boards); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,6 +136,7 @@ type Repository struct {
|
|||||||
OriginalServiceType api.GitServiceType `xorm:"index"`
|
OriginalServiceType api.GitServiceType `xorm:"index"`
|
||||||
OriginalURL string `xorm:"VARCHAR(2048)"`
|
OriginalURL string `xorm:"VARCHAR(2048)"`
|
||||||
DefaultBranch string
|
DefaultBranch string
|
||||||
|
DefaultWikiBranch string
|
||||||
|
|
||||||
NumWatches int
|
NumWatches int
|
||||||
NumStars int
|
NumStars int
|
||||||
@ -285,6 +286,9 @@ func (repo *Repository) AfterLoad() {
|
|||||||
repo.NumOpenMilestones = repo.NumMilestones - repo.NumClosedMilestones
|
repo.NumOpenMilestones = repo.NumMilestones - repo.NumClosedMilestones
|
||||||
repo.NumOpenProjects = repo.NumProjects - repo.NumClosedProjects
|
repo.NumOpenProjects = repo.NumProjects - repo.NumClosedProjects
|
||||||
repo.NumOpenActionRuns = repo.NumActionRuns - repo.NumClosedActionRuns
|
repo.NumOpenActionRuns = repo.NumActionRuns - repo.NumClosedActionRuns
|
||||||
|
if repo.DefaultWikiBranch == "" {
|
||||||
|
repo.DefaultWikiBranch = setting.Repository.DefaultBranch
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadAttributes loads attributes of the repository.
|
// LoadAttributes loads attributes of the repository.
|
||||||
@ -412,9 +416,11 @@ func (repo *Repository) MustGetUnit(ctx context.Context, tp unit.Type) *RepoUnit
|
|||||||
Config: new(ActionsConfig),
|
Config: new(ActionsConfig),
|
||||||
}
|
}
|
||||||
} else if tp == unit.TypeProjects {
|
} else if tp == unit.TypeProjects {
|
||||||
|
cfg := new(ProjectsConfig)
|
||||||
|
cfg.ProjectsMode = ProjectsModeNone
|
||||||
return &RepoUnit{
|
return &RepoUnit{
|
||||||
Type: tp,
|
Type: tp,
|
||||||
Config: new(ProjectsConfig),
|
Config: cfg,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,7 +236,7 @@ func (cfg *ProjectsConfig) GetProjectsMode() ProjectsMode {
|
|||||||
return cfg.ProjectsMode
|
return cfg.ProjectsMode
|
||||||
}
|
}
|
||||||
|
|
||||||
return ProjectsModeNone
|
return ProjectsModeAll
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cfg *ProjectsConfig) IsProjectsAllowed(m ProjectsMode) bool {
|
func (cfg *ProjectsConfig) IsProjectsAllowed(m ProjectsMode) bool {
|
||||||
|
@ -154,37 +154,18 @@ func UpdateEmailAddress(ctx context.Context, email *EmailAddress) error {
|
|||||||
|
|
||||||
var emailRegexp = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+-/=?^_`{|}~]*@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$")
|
var emailRegexp = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+-/=?^_`{|}~]*@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$")
|
||||||
|
|
||||||
// ValidateEmail check if email is a allowed address
|
// ValidateEmail check if email is a valid & allowed address
|
||||||
func ValidateEmail(email string) error {
|
func ValidateEmail(email string) error {
|
||||||
if len(email) == 0 {
|
if err := validateEmailBasic(email); err != nil {
|
||||||
return ErrEmailInvalid{email}
|
return err
|
||||||
}
|
}
|
||||||
|
return validateEmailDomain(email)
|
||||||
|
}
|
||||||
|
|
||||||
if !emailRegexp.MatchString(email) {
|
// ValidateEmailForAdmin check if email is a valid address when admins manually add or edit users
|
||||||
return ErrEmailCharIsNotSupported{email}
|
func ValidateEmailForAdmin(email string) error {
|
||||||
}
|
return validateEmailBasic(email)
|
||||||
|
// In this case we do not need to check the email domain
|
||||||
if email[0] == '-' {
|
|
||||||
return ErrEmailInvalid{email}
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err := mail.ParseAddress(email); err != nil {
|
|
||||||
return ErrEmailInvalid{email}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if there is no allow list, then check email against block list
|
|
||||||
if len(setting.Service.EmailDomainAllowList) == 0 &&
|
|
||||||
validation.IsEmailDomainListed(setting.Service.EmailDomainBlockList, email) {
|
|
||||||
return ErrEmailInvalid{email}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if there is an allow list, then check email against allow list
|
|
||||||
if len(setting.Service.EmailDomainAllowList) > 0 &&
|
|
||||||
!validation.IsEmailDomainListed(setting.Service.EmailDomainAllowList, email) {
|
|
||||||
return ErrEmailInvalid{email}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetEmailAddressByEmail(ctx context.Context, email string) (*EmailAddress, error) {
|
func GetEmailAddressByEmail(ctx context.Context, email string) (*EmailAddress, error) {
|
||||||
@ -534,3 +515,41 @@ func ActivateUserEmail(ctx context.Context, userID int64, email string, activate
|
|||||||
|
|
||||||
return committer.Commit()
|
return committer.Commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// validateEmailBasic checks whether the email complies with the rules
|
||||||
|
func validateEmailBasic(email string) error {
|
||||||
|
if len(email) == 0 {
|
||||||
|
return ErrEmailInvalid{email}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !emailRegexp.MatchString(email) {
|
||||||
|
return ErrEmailCharIsNotSupported{email}
|
||||||
|
}
|
||||||
|
|
||||||
|
if email[0] == '-' {
|
||||||
|
return ErrEmailInvalid{email}
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := mail.ParseAddress(email); err != nil {
|
||||||
|
return ErrEmailInvalid{email}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// validateEmailDomain checks whether the email domain is allowed or blocked
|
||||||
|
func validateEmailDomain(email string) error {
|
||||||
|
// if there is no allow list, then check email against block list
|
||||||
|
if len(setting.Service.EmailDomainAllowList) == 0 &&
|
||||||
|
validation.IsEmailDomainListed(setting.Service.EmailDomainBlockList, email) {
|
||||||
|
return ErrEmailInvalid{email}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if there is an allow list, then check email against allow list
|
||||||
|
if len(setting.Service.EmailDomainAllowList) > 0 &&
|
||||||
|
!validation.IsEmailDomainListed(setting.Service.EmailDomainAllowList, email) {
|
||||||
|
return ErrEmailInvalid{email}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -586,6 +586,16 @@ type CreateUserOverwriteOptions struct {
|
|||||||
|
|
||||||
// CreateUser creates record of a new user.
|
// CreateUser creates record of a new user.
|
||||||
func CreateUser(ctx context.Context, u *User, overwriteDefault ...*CreateUserOverwriteOptions) (err error) {
|
func CreateUser(ctx context.Context, u *User, overwriteDefault ...*CreateUserOverwriteOptions) (err error) {
|
||||||
|
return createUser(ctx, u, false, overwriteDefault...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AdminCreateUser is used by admins to manually create users
|
||||||
|
func AdminCreateUser(ctx context.Context, u *User, overwriteDefault ...*CreateUserOverwriteOptions) (err error) {
|
||||||
|
return createUser(ctx, u, true, overwriteDefault...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// createUser creates record of a new user.
|
||||||
|
func createUser(ctx context.Context, u *User, createdByAdmin bool, overwriteDefault ...*CreateUserOverwriteOptions) (err error) {
|
||||||
if err = IsUsableUsername(u.Name); err != nil {
|
if err = IsUsableUsername(u.Name); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -639,8 +649,14 @@ func CreateUser(ctx context.Context, u *User, overwriteDefault ...*CreateUserOve
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ValidateEmail(u.Email); err != nil {
|
if createdByAdmin {
|
||||||
return err
|
if err := ValidateEmailForAdmin(u.Email); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if err := ValidateEmail(u.Email); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, committer, err := db.TxContext(ctx)
|
ctx, committer, err := db.TxContext(ctx)
|
||||||
|
@ -5,13 +5,13 @@ package webhook
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
"code.gitea.io/gitea/modules/json"
|
"code.gitea.io/gitea/modules/json"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
api "code.gitea.io/gitea/modules/structs"
|
|
||||||
"code.gitea.io/gitea/modules/timeutil"
|
"code.gitea.io/gitea/modules/timeutil"
|
||||||
webhook_module "code.gitea.io/gitea/modules/webhook"
|
webhook_module "code.gitea.io/gitea/modules/webhook"
|
||||||
|
|
||||||
@ -31,6 +31,7 @@ type HookRequest struct {
|
|||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
HTTPMethod string `json:"http_method"`
|
HTTPMethod string `json:"http_method"`
|
||||||
Headers map[string]string `json:"headers"`
|
Headers map[string]string `json:"headers"`
|
||||||
|
Body string `json:"body"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// HookResponse represents hook task response information.
|
// HookResponse represents hook task response information.
|
||||||
@ -45,11 +46,15 @@ type HookTask struct {
|
|||||||
ID int64 `xorm:"pk autoincr"`
|
ID int64 `xorm:"pk autoincr"`
|
||||||
HookID int64 `xorm:"index"`
|
HookID int64 `xorm:"index"`
|
||||||
UUID string `xorm:"unique"`
|
UUID string `xorm:"unique"`
|
||||||
api.Payloader `xorm:"-"`
|
|
||||||
PayloadContent string `xorm:"LONGTEXT"`
|
PayloadContent string `xorm:"LONGTEXT"`
|
||||||
EventType webhook_module.HookEventType
|
// PayloadVersion number to allow for smooth version upgrades:
|
||||||
IsDelivered bool
|
// - PayloadVersion 1: PayloadContent contains the JSON as sent to the URL
|
||||||
Delivered timeutil.TimeStampNano
|
// - PayloadVersion 2: PayloadContent contains the original event
|
||||||
|
PayloadVersion int `xorm:"DEFAULT 1"`
|
||||||
|
|
||||||
|
EventType webhook_module.HookEventType
|
||||||
|
IsDelivered bool
|
||||||
|
Delivered timeutil.TimeStampNano
|
||||||
|
|
||||||
// History info.
|
// History info.
|
||||||
IsSucceed bool
|
IsSucceed bool
|
||||||
@ -115,16 +120,12 @@ func HookTasks(ctx context.Context, hookID int64, page int) ([]*HookTask, error)
|
|||||||
// it handles conversion from Payload to PayloadContent.
|
// it handles conversion from Payload to PayloadContent.
|
||||||
func CreateHookTask(ctx context.Context, t *HookTask) (*HookTask, error) {
|
func CreateHookTask(ctx context.Context, t *HookTask) (*HookTask, error) {
|
||||||
t.UUID = gouuid.New().String()
|
t.UUID = gouuid.New().String()
|
||||||
if t.Payloader != nil {
|
|
||||||
data, err := t.Payloader.JSONPayload()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
t.PayloadContent = string(data)
|
|
||||||
}
|
|
||||||
if t.Delivered == 0 {
|
if t.Delivered == 0 {
|
||||||
t.Delivered = timeutil.TimeStampNanoNow()
|
t.Delivered = timeutil.TimeStampNanoNow()
|
||||||
}
|
}
|
||||||
|
if t.PayloadVersion == 0 {
|
||||||
|
return nil, errors.New("missing HookTask.PayloadVersion")
|
||||||
|
}
|
||||||
return t, db.Insert(ctx, t)
|
return t, db.Insert(ctx, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,6 +166,7 @@ func ReplayHookTask(ctx context.Context, hookID int64, uuid string) (*HookTask,
|
|||||||
HookID: task.HookID,
|
HookID: task.HookID,
|
||||||
PayloadContent: task.PayloadContent,
|
PayloadContent: task.PayloadContent,
|
||||||
EventType: task.EventType,
|
EventType: task.EventType,
|
||||||
|
PayloadVersion: task.PayloadVersion,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,6 @@ import (
|
|||||||
"code.gitea.io/gitea/models/unittest"
|
"code.gitea.io/gitea/models/unittest"
|
||||||
"code.gitea.io/gitea/modules/json"
|
"code.gitea.io/gitea/modules/json"
|
||||||
"code.gitea.io/gitea/modules/optional"
|
"code.gitea.io/gitea/modules/optional"
|
||||||
api "code.gitea.io/gitea/modules/structs"
|
|
||||||
"code.gitea.io/gitea/modules/timeutil"
|
"code.gitea.io/gitea/modules/timeutil"
|
||||||
webhook_module "code.gitea.io/gitea/modules/webhook"
|
webhook_module "code.gitea.io/gitea/modules/webhook"
|
||||||
|
|
||||||
@ -35,8 +34,10 @@ func TestWebhook_History(t *testing.T) {
|
|||||||
webhook := unittest.AssertExistsAndLoadBean(t, &Webhook{ID: 1})
|
webhook := unittest.AssertExistsAndLoadBean(t, &Webhook{ID: 1})
|
||||||
tasks, err := webhook.History(db.DefaultContext, 0)
|
tasks, err := webhook.History(db.DefaultContext, 0)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
if assert.Len(t, tasks, 1) {
|
if assert.Len(t, tasks, 3) {
|
||||||
assert.Equal(t, int64(1), tasks[0].ID)
|
assert.Equal(t, int64(3), tasks[0].ID)
|
||||||
|
assert.Equal(t, int64(2), tasks[1].ID)
|
||||||
|
assert.Equal(t, int64(1), tasks[2].ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
webhook = unittest.AssertExistsAndLoadBean(t, &Webhook{ID: 2})
|
webhook = unittest.AssertExistsAndLoadBean(t, &Webhook{ID: 2})
|
||||||
@ -197,8 +198,10 @@ func TestHookTasks(t *testing.T) {
|
|||||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||||
hookTasks, err := HookTasks(db.DefaultContext, 1, 1)
|
hookTasks, err := HookTasks(db.DefaultContext, 1, 1)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
if assert.Len(t, hookTasks, 1) {
|
if assert.Len(t, hookTasks, 3) {
|
||||||
assert.Equal(t, int64(1), hookTasks[0].ID)
|
assert.Equal(t, int64(3), hookTasks[0].ID)
|
||||||
|
assert.Equal(t, int64(2), hookTasks[1].ID)
|
||||||
|
assert.Equal(t, int64(1), hookTasks[2].ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
hookTasks, err = HookTasks(db.DefaultContext, unittest.NonexistentID, 1)
|
hookTasks, err = HookTasks(db.DefaultContext, unittest.NonexistentID, 1)
|
||||||
@ -209,8 +212,8 @@ func TestHookTasks(t *testing.T) {
|
|||||||
func TestCreateHookTask(t *testing.T) {
|
func TestCreateHookTask(t *testing.T) {
|
||||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||||
hookTask := &HookTask{
|
hookTask := &HookTask{
|
||||||
HookID: 3,
|
HookID: 3,
|
||||||
Payloader: &api.PushPayload{},
|
PayloadVersion: 2,
|
||||||
}
|
}
|
||||||
unittest.AssertNotExistsBean(t, hookTask)
|
unittest.AssertNotExistsBean(t, hookTask)
|
||||||
_, err := CreateHookTask(db.DefaultContext, hookTask)
|
_, err := CreateHookTask(db.DefaultContext, hookTask)
|
||||||
@ -232,10 +235,10 @@ func TestUpdateHookTask(t *testing.T) {
|
|||||||
func TestCleanupHookTaskTable_PerWebhook_DeletesDelivered(t *testing.T) {
|
func TestCleanupHookTaskTable_PerWebhook_DeletesDelivered(t *testing.T) {
|
||||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||||
hookTask := &HookTask{
|
hookTask := &HookTask{
|
||||||
HookID: 3,
|
HookID: 3,
|
||||||
Payloader: &api.PushPayload{},
|
IsDelivered: true,
|
||||||
IsDelivered: true,
|
Delivered: timeutil.TimeStampNanoNow(),
|
||||||
Delivered: timeutil.TimeStampNanoNow(),
|
PayloadVersion: 2,
|
||||||
}
|
}
|
||||||
unittest.AssertNotExistsBean(t, hookTask)
|
unittest.AssertNotExistsBean(t, hookTask)
|
||||||
_, err := CreateHookTask(db.DefaultContext, hookTask)
|
_, err := CreateHookTask(db.DefaultContext, hookTask)
|
||||||
@ -249,9 +252,9 @@ func TestCleanupHookTaskTable_PerWebhook_DeletesDelivered(t *testing.T) {
|
|||||||
func TestCleanupHookTaskTable_PerWebhook_LeavesUndelivered(t *testing.T) {
|
func TestCleanupHookTaskTable_PerWebhook_LeavesUndelivered(t *testing.T) {
|
||||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||||
hookTask := &HookTask{
|
hookTask := &HookTask{
|
||||||
HookID: 4,
|
HookID: 4,
|
||||||
Payloader: &api.PushPayload{},
|
IsDelivered: false,
|
||||||
IsDelivered: false,
|
PayloadVersion: 2,
|
||||||
}
|
}
|
||||||
unittest.AssertNotExistsBean(t, hookTask)
|
unittest.AssertNotExistsBean(t, hookTask)
|
||||||
_, err := CreateHookTask(db.DefaultContext, hookTask)
|
_, err := CreateHookTask(db.DefaultContext, hookTask)
|
||||||
@ -265,10 +268,10 @@ func TestCleanupHookTaskTable_PerWebhook_LeavesUndelivered(t *testing.T) {
|
|||||||
func TestCleanupHookTaskTable_PerWebhook_LeavesMostRecentTask(t *testing.T) {
|
func TestCleanupHookTaskTable_PerWebhook_LeavesMostRecentTask(t *testing.T) {
|
||||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||||
hookTask := &HookTask{
|
hookTask := &HookTask{
|
||||||
HookID: 4,
|
HookID: 4,
|
||||||
Payloader: &api.PushPayload{},
|
IsDelivered: true,
|
||||||
IsDelivered: true,
|
Delivered: timeutil.TimeStampNanoNow(),
|
||||||
Delivered: timeutil.TimeStampNanoNow(),
|
PayloadVersion: 2,
|
||||||
}
|
}
|
||||||
unittest.AssertNotExistsBean(t, hookTask)
|
unittest.AssertNotExistsBean(t, hookTask)
|
||||||
_, err := CreateHookTask(db.DefaultContext, hookTask)
|
_, err := CreateHookTask(db.DefaultContext, hookTask)
|
||||||
@ -282,10 +285,10 @@ func TestCleanupHookTaskTable_PerWebhook_LeavesMostRecentTask(t *testing.T) {
|
|||||||
func TestCleanupHookTaskTable_OlderThan_DeletesDelivered(t *testing.T) {
|
func TestCleanupHookTaskTable_OlderThan_DeletesDelivered(t *testing.T) {
|
||||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||||
hookTask := &HookTask{
|
hookTask := &HookTask{
|
||||||
HookID: 3,
|
HookID: 3,
|
||||||
Payloader: &api.PushPayload{},
|
IsDelivered: true,
|
||||||
IsDelivered: true,
|
Delivered: timeutil.TimeStampNano(time.Now().AddDate(0, 0, -8).UnixNano()),
|
||||||
Delivered: timeutil.TimeStampNano(time.Now().AddDate(0, 0, -8).UnixNano()),
|
PayloadVersion: 2,
|
||||||
}
|
}
|
||||||
unittest.AssertNotExistsBean(t, hookTask)
|
unittest.AssertNotExistsBean(t, hookTask)
|
||||||
_, err := CreateHookTask(db.DefaultContext, hookTask)
|
_, err := CreateHookTask(db.DefaultContext, hookTask)
|
||||||
@ -299,9 +302,9 @@ func TestCleanupHookTaskTable_OlderThan_DeletesDelivered(t *testing.T) {
|
|||||||
func TestCleanupHookTaskTable_OlderThan_LeavesUndelivered(t *testing.T) {
|
func TestCleanupHookTaskTable_OlderThan_LeavesUndelivered(t *testing.T) {
|
||||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||||
hookTask := &HookTask{
|
hookTask := &HookTask{
|
||||||
HookID: 4,
|
HookID: 4,
|
||||||
Payloader: &api.PushPayload{},
|
IsDelivered: false,
|
||||||
IsDelivered: false,
|
PayloadVersion: 2,
|
||||||
}
|
}
|
||||||
unittest.AssertNotExistsBean(t, hookTask)
|
unittest.AssertNotExistsBean(t, hookTask)
|
||||||
_, err := CreateHookTask(db.DefaultContext, hookTask)
|
_, err := CreateHookTask(db.DefaultContext, hookTask)
|
||||||
@ -315,10 +318,10 @@ func TestCleanupHookTaskTable_OlderThan_LeavesUndelivered(t *testing.T) {
|
|||||||
func TestCleanupHookTaskTable_OlderThan_LeavesTaskEarlierThanAgeToDelete(t *testing.T) {
|
func TestCleanupHookTaskTable_OlderThan_LeavesTaskEarlierThanAgeToDelete(t *testing.T) {
|
||||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||||
hookTask := &HookTask{
|
hookTask := &HookTask{
|
||||||
HookID: 4,
|
HookID: 4,
|
||||||
Payloader: &api.PushPayload{},
|
IsDelivered: true,
|
||||||
IsDelivered: true,
|
Delivered: timeutil.TimeStampNano(time.Now().AddDate(0, 0, -6).UnixNano()),
|
||||||
Delivered: timeutil.TimeStampNano(time.Now().AddDate(0, 0, -6).UnixNano()),
|
PayloadVersion: 2,
|
||||||
}
|
}
|
||||||
unittest.AssertNotExistsBean(t, hookTask)
|
unittest.AssertNotExistsBean(t, hookTask)
|
||||||
_, err := CreateHookTask(db.DefaultContext, hookTask)
|
_, err := CreateHookTask(db.DefaultContext, hookTask)
|
||||||
|
@ -4,85 +4,12 @@
|
|||||||
package base
|
package base
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/big"
|
"golang.org/x/text/collate"
|
||||||
"unicode/utf8"
|
"golang.org/x/text/language"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NaturalSortLess compares two strings so that they could be sorted in natural order
|
// NaturalSortLess compares two strings so that they could be sorted in natural order
|
||||||
func NaturalSortLess(s1, s2 string) bool {
|
func NaturalSortLess(s1, s2 string) bool {
|
||||||
var i1, i2 int
|
c := collate.New(language.English, collate.Numeric)
|
||||||
for {
|
return c.CompareString(s1, s2) < 0
|
||||||
rune1, j1, end1 := getNextRune(s1, i1)
|
|
||||||
rune2, j2, end2 := getNextRune(s2, i2)
|
|
||||||
if end1 || end2 {
|
|
||||||
return end1 != end2 && end1
|
|
||||||
}
|
|
||||||
dec1 := isDecimal(rune1)
|
|
||||||
dec2 := isDecimal(rune2)
|
|
||||||
var less, equal bool
|
|
||||||
if dec1 && dec2 {
|
|
||||||
i1, i2, less, equal = compareByNumbers(s1, i1, s2, i2)
|
|
||||||
} else if !dec1 && !dec2 {
|
|
||||||
equal = rune1 == rune2
|
|
||||||
less = rune1 < rune2
|
|
||||||
i1 = j1
|
|
||||||
i2 = j2
|
|
||||||
} else {
|
|
||||||
return rune1 < rune2
|
|
||||||
}
|
|
||||||
if !equal {
|
|
||||||
return less
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func getNextRune(str string, pos int) (rune, int, bool) {
|
|
||||||
if pos < len(str) {
|
|
||||||
r, w := utf8.DecodeRuneInString(str[pos:])
|
|
||||||
// Fallback to ascii
|
|
||||||
if r == utf8.RuneError {
|
|
||||||
r = rune(str[pos])
|
|
||||||
w = 1
|
|
||||||
}
|
|
||||||
return r, pos + w, false
|
|
||||||
}
|
|
||||||
return 0, pos, true
|
|
||||||
}
|
|
||||||
|
|
||||||
func isDecimal(r rune) bool {
|
|
||||||
return '0' <= r && r <= '9'
|
|
||||||
}
|
|
||||||
|
|
||||||
func compareByNumbers(str1 string, pos1 int, str2 string, pos2 int) (i1, i2 int, less, equal bool) {
|
|
||||||
d1, d2 := true, true
|
|
||||||
var dec1, dec2 string
|
|
||||||
for d1 || d2 {
|
|
||||||
if d1 {
|
|
||||||
r, j, end := getNextRune(str1, pos1)
|
|
||||||
if !end && isDecimal(r) {
|
|
||||||
dec1 += string(r)
|
|
||||||
pos1 = j
|
|
||||||
} else {
|
|
||||||
d1 = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if d2 {
|
|
||||||
r, j, end := getNextRune(str2, pos2)
|
|
||||||
if !end && isDecimal(r) {
|
|
||||||
dec2 += string(r)
|
|
||||||
pos2 = j
|
|
||||||
} else {
|
|
||||||
d2 = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
less, equal = compareBigNumbers(dec1, dec2)
|
|
||||||
return pos1, pos2, less, equal
|
|
||||||
}
|
|
||||||
|
|
||||||
func compareBigNumbers(dec1, dec2 string) (less, equal bool) {
|
|
||||||
d1, _ := big.NewInt(0).SetString(dec1, 10)
|
|
||||||
d2, _ := big.NewInt(0).SetString(dec2, 10)
|
|
||||||
cmp := d1.Cmp(d2)
|
|
||||||
return cmp < 0, cmp == 0
|
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
|
|
||||||
func TestNaturalSortLess(t *testing.T) {
|
func TestNaturalSortLess(t *testing.T) {
|
||||||
test := func(s1, s2 string, less bool) {
|
test := func(s1, s2 string, less bool) {
|
||||||
assert.Equal(t, less, NaturalSortLess(s1, s2))
|
assert.Equal(t, less, NaturalSortLess(s1, s2), "s1=%q, s2=%q", s1, s2)
|
||||||
}
|
}
|
||||||
test("v1.20.0", "v1.2.0", false)
|
test("v1.20.0", "v1.2.0", false)
|
||||||
test("v1.20.0", "v1.29.0", true)
|
test("v1.20.0", "v1.29.0", true)
|
||||||
@ -20,4 +20,11 @@ func TestNaturalSortLess(t *testing.T) {
|
|||||||
test("a-1-a", "a-1-b", true)
|
test("a-1-a", "a-1-b", true)
|
||||||
test("2", "12", true)
|
test("2", "12", true)
|
||||||
test("a", "ab", true)
|
test("a", "ab", true)
|
||||||
|
|
||||||
|
test("A", "b", true)
|
||||||
|
test("a", "B", true)
|
||||||
|
|
||||||
|
test("cafe", "café", true)
|
||||||
|
test("café", "cafe", false)
|
||||||
|
test("caff", "café", false)
|
||||||
}
|
}
|
||||||
|
@ -8,11 +8,11 @@ package git
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
gitealog "code.gitea.io/gitea/modules/log"
|
gitealog "code.gitea.io/gitea/modules/log"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
"code.gitea.io/gitea/modules/util"
|
||||||
|
|
||||||
"github.com/go-git/go-billy/v5"
|
"github.com/go-git/go-billy/v5"
|
||||||
"github.com/go-git/go-billy/v5/osfs"
|
"github.com/go-git/go-billy/v5/osfs"
|
||||||
@ -52,7 +52,7 @@ func OpenRepository(ctx context.Context, repoPath string) (*Repository, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else if !isDir(repoPath) {
|
} else if !isDir(repoPath) {
|
||||||
return nil, errors.New("no such file or directory")
|
return nil, util.NewNotExistErrorf("no such file or directory")
|
||||||
}
|
}
|
||||||
|
|
||||||
fs := osfs.New(repoPath)
|
fs := osfs.New(repoPath)
|
||||||
|
@ -9,10 +9,10 @@ package git
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
|
"code.gitea.io/gitea/modules/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -54,7 +54,7 @@ func OpenRepository(ctx context.Context, repoPath string) (*Repository, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else if !isDir(repoPath) {
|
} else if !isDir(repoPath) {
|
||||||
return nil, errors.New("no such file or directory")
|
return nil, util.NewNotExistErrorf("no such file or directory")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now because of some insanity with git cat-file not immediately failing if not run in a valid git directory we need to run git rev-parse first!
|
// Now because of some insanity with git cat-file not immediately failing if not run in a valid git directory we need to run git rev-parse first!
|
||||||
|
@ -59,7 +59,15 @@ func (g *Manager) start() {
|
|||||||
go func() {
|
go func() {
|
||||||
defer close(startupDone)
|
defer close(startupDone)
|
||||||
// Wait till we're done getting all the listeners and then close the unused ones
|
// Wait till we're done getting all the listeners and then close the unused ones
|
||||||
g.createServerWaitGroup.Wait()
|
func() {
|
||||||
|
// FIXME: there is a fundamental design problem of the "manager" and the "wait group".
|
||||||
|
// If nothing has started, the "Wait" just panics: sync: WaitGroup is reused before previous Wait has returned
|
||||||
|
// There is no clear solution besides a complete rewriting of the "manager"
|
||||||
|
defer func() {
|
||||||
|
_ = recover()
|
||||||
|
}()
|
||||||
|
g.createServerWaitGroup.Wait()
|
||||||
|
}()
|
||||||
// Ignore the error here there's not much we can do with it, they're logged in the CloseProvidedListeners function
|
// Ignore the error here there's not much we can do with it, they're logged in the CloseProvidedListeners function
|
||||||
_ = CloseProvidedListeners()
|
_ = CloseProvidedListeners()
|
||||||
g.notify(readyMsg)
|
g.notify(readyMsg)
|
||||||
|
@ -150,7 +150,15 @@ func (g *Manager) awaitServer(limit time.Duration) bool {
|
|||||||
c := make(chan struct{})
|
c := make(chan struct{})
|
||||||
go func() {
|
go func() {
|
||||||
defer close(c)
|
defer close(c)
|
||||||
g.createServerWaitGroup.Wait()
|
func() {
|
||||||
|
// FIXME: there is a fundamental design problem of the "manager" and the "wait group".
|
||||||
|
// If nothing has started, the "Wait" just panics: sync: WaitGroup is reused before previous Wait has returned
|
||||||
|
// There is no clear solution besides a complete rewriting of the "manager"
|
||||||
|
defer func() {
|
||||||
|
_ = recover()
|
||||||
|
}()
|
||||||
|
g.createServerWaitGroup.Wait()
|
||||||
|
}()
|
||||||
}()
|
}()
|
||||||
if limit > 0 {
|
if limit > 0 {
|
||||||
select {
|
select {
|
||||||
|
@ -16,14 +16,18 @@ import (
|
|||||||
|
|
||||||
// Result a search result to display
|
// Result a search result to display
|
||||||
type Result struct {
|
type Result struct {
|
||||||
RepoID int64
|
RepoID int64
|
||||||
Filename string
|
Filename string
|
||||||
CommitID string
|
CommitID string
|
||||||
UpdatedUnix timeutil.TimeStamp
|
UpdatedUnix timeutil.TimeStamp
|
||||||
Language string
|
Language string
|
||||||
Color string
|
Color string
|
||||||
LineNumbers []int
|
Lines []ResultLine
|
||||||
FormattedLines template.HTML
|
}
|
||||||
|
|
||||||
|
type ResultLine struct {
|
||||||
|
Num int
|
||||||
|
FormattedContent template.HTML
|
||||||
}
|
}
|
||||||
|
|
||||||
type SearchResultLanguages = internal.SearchResultLanguages
|
type SearchResultLanguages = internal.SearchResultLanguages
|
||||||
@ -70,7 +74,7 @@ func searchResult(result *internal.SearchResult, startIndex, endIndex int) (*Res
|
|||||||
var formattedLinesBuffer bytes.Buffer
|
var formattedLinesBuffer bytes.Buffer
|
||||||
|
|
||||||
contentLines := strings.SplitAfter(result.Content[startIndex:endIndex], "\n")
|
contentLines := strings.SplitAfter(result.Content[startIndex:endIndex], "\n")
|
||||||
lineNumbers := make([]int, len(contentLines))
|
lines := make([]ResultLine, 0, len(contentLines))
|
||||||
index := startIndex
|
index := startIndex
|
||||||
for i, line := range contentLines {
|
for i, line := range contentLines {
|
||||||
var err error
|
var err error
|
||||||
@ -93,21 +97,29 @@ func searchResult(result *internal.SearchResult, startIndex, endIndex int) (*Res
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
lineNumbers[i] = startLineNum + i
|
lines = append(lines, ResultLine{Num: startLineNum + i})
|
||||||
index += len(line)
|
index += len(line)
|
||||||
}
|
}
|
||||||
|
|
||||||
highlighted, _ := highlight.Code(result.Filename, "", formattedLinesBuffer.String())
|
// we should highlight the whole code block first, otherwise it doesn't work well with multiple line highlighting
|
||||||
|
hl, _ := highlight.Code(result.Filename, "", formattedLinesBuffer.String())
|
||||||
|
highlightedLines := strings.Split(string(hl), "\n")
|
||||||
|
|
||||||
|
// The lines outputted by highlight.Code might not match the original lines, because "highlight" removes the last `\n`
|
||||||
|
lines = lines[:min(len(highlightedLines), len(lines))]
|
||||||
|
highlightedLines = highlightedLines[:len(lines)]
|
||||||
|
for i := 0; i < len(lines); i++ {
|
||||||
|
lines[i].FormattedContent = template.HTML(highlightedLines[i])
|
||||||
|
}
|
||||||
|
|
||||||
return &Result{
|
return &Result{
|
||||||
RepoID: result.RepoID,
|
RepoID: result.RepoID,
|
||||||
Filename: result.Filename,
|
Filename: result.Filename,
|
||||||
CommitID: result.CommitID,
|
CommitID: result.CommitID,
|
||||||
UpdatedUnix: result.UpdatedUnix,
|
UpdatedUnix: result.UpdatedUnix,
|
||||||
Language: result.Language,
|
Language: result.Language,
|
||||||
Color: result.Color,
|
Color: result.Color,
|
||||||
LineNumbers: lineNumbers,
|
Lines: lines,
|
||||||
FormattedLines: highlighted,
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,14 +208,8 @@ func SafeHTML(s any) template.HTML {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SanitizeHTML sanitizes the input by pre-defined markdown rules
|
// SanitizeHTML sanitizes the input by pre-defined markdown rules
|
||||||
func SanitizeHTML(s any) template.HTML {
|
func SanitizeHTML(s string) template.HTML {
|
||||||
switch v := s.(type) {
|
return template.HTML(markup.Sanitize(s))
|
||||||
case string:
|
|
||||||
return template.HTML(markup.Sanitize(v))
|
|
||||||
case template.HTML:
|
|
||||||
return template.HTML(markup.Sanitize(string(v)))
|
|
||||||
}
|
|
||||||
panic(fmt.Sprintf("unexpected type %T", s))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func HTMLEscape(s any) template.HTML {
|
func HTMLEscape(s any) template.HTML {
|
||||||
|
@ -64,5 +64,4 @@ func TestHTMLFormat(t *testing.T) {
|
|||||||
|
|
||||||
func TestSanitizeHTML(t *testing.T) {
|
func TestSanitizeHTML(t *testing.T) {
|
||||||
assert.Equal(t, template.HTML(`<a href="/" rel="nofollow">link</a> xss <div>inline</div>`), SanitizeHTML(`<a href="/">link</a> <a href="javascript:">xss</a> <div style="dangerous">inline</div>`))
|
assert.Equal(t, template.HTML(`<a href="/" rel="nofollow">link</a> xss <div>inline</div>`), SanitizeHTML(`<a href="/">link</a> <a href="javascript:">xss</a> <div style="dangerous">inline</div>`))
|
||||||
assert.Equal(t, template.HTML(`<a href="/" rel="nofollow">link</a> xss <div>inline</div>`), SanitizeHTML(template.HTML(`<a href="/">link</a> <a href="javascript:">xss</a> <div style="dangerous">inline</div>`)))
|
|
||||||
}
|
}
|
||||||
|
@ -320,6 +320,7 @@ env_config_keys = Environment Configuration
|
|||||||
env_config_keys_prompt = The following environment variables will also be applied to your configuration file:
|
env_config_keys_prompt = The following environment variables will also be applied to your configuration file:
|
||||||
|
|
||||||
[home]
|
[home]
|
||||||
|
nav_menu = Navigation Menu
|
||||||
uname_holder = Username or Email Address
|
uname_holder = Username or Email Address
|
||||||
password_holder = Password
|
password_holder = Password
|
||||||
switch_dashboard_context = Switch Dashboard Context
|
switch_dashboard_context = Switch Dashboard Context
|
||||||
@ -654,7 +655,7 @@ block.note.title = Optional note:
|
|||||||
block.note.info = The note is not visible to the blocked user.
|
block.note.info = The note is not visible to the blocked user.
|
||||||
block.note.edit = Edit note
|
block.note.edit = Edit note
|
||||||
block.list = Blocked users
|
block.list = Blocked users
|
||||||
block.list.none = You have not blocked any users.
|
block.list.none = You have not blocked any users.
|
||||||
|
|
||||||
[settings]
|
[settings]
|
||||||
profile = Profile
|
profile = Profile
|
||||||
@ -2091,6 +2092,8 @@ settings.branches.add_new_rule = Add New Rule
|
|||||||
settings.advanced_settings = Advanced Settings
|
settings.advanced_settings = Advanced Settings
|
||||||
settings.wiki_desc = Enable Repository Wiki
|
settings.wiki_desc = Enable Repository Wiki
|
||||||
settings.use_internal_wiki = Use Built-In Wiki
|
settings.use_internal_wiki = Use Built-In Wiki
|
||||||
|
settings.default_wiki_branch_name = Default Wiki Branch Name
|
||||||
|
settings.failed_to_change_default_wiki_branch = Failed to change the default wiki branch.
|
||||||
settings.use_external_wiki = Use External Wiki
|
settings.use_external_wiki = Use External Wiki
|
||||||
settings.external_wiki_url = External Wiki URL
|
settings.external_wiki_url = External Wiki URL
|
||||||
settings.external_wiki_url_error = The external wiki URL is not a valid URL.
|
settings.external_wiki_url_error = The external wiki URL is not a valid URL.
|
||||||
@ -2640,6 +2643,7 @@ find_file.no_matching = No matching file found
|
|||||||
error.csv.too_large = Can't render this file because it is too large.
|
error.csv.too_large = Can't render this file because it is too large.
|
||||||
error.csv.unexpected = Can't render this file because it contains an unexpected character in line %d and column %d.
|
error.csv.unexpected = Can't render this file because it contains an unexpected character in line %d and column %d.
|
||||||
error.csv.invalid_field_count = Can't render this file because it has a wrong number of fields in line %d.
|
error.csv.invalid_field_count = Can't render this file because it has a wrong number of fields in line %d.
|
||||||
|
error.broken_git_hook = Git hooks of this repository seem to be broken. Please follow the <a target="_blank" rel="noreferrer" href="%s">documentation</a> to fix them, then push some commits to refresh the status.
|
||||||
|
|
||||||
[graphs]
|
[graphs]
|
||||||
component_loading = Loading %s...
|
component_loading = Loading %s...
|
||||||
|
@ -149,8 +149,8 @@ footer.software=ソフトウェアについて
|
|||||||
footer.links=リンク
|
footer.links=リンク
|
||||||
|
|
||||||
[heatmap]
|
[heatmap]
|
||||||
number_of_contributions_in_the_last_12_months=過去 12 か月間で %s 個の貢献
|
number_of_contributions_in_the_last_12_months=過去 12 か月間で %s 件の実績
|
||||||
no_contributions=貢献なし
|
no_contributions=実績なし
|
||||||
less=少
|
less=少
|
||||||
more=多
|
more=多
|
||||||
|
|
||||||
@ -1510,7 +1510,7 @@ issues.role.member_helper=このユーザーはこのリポジトリを所有し
|
|||||||
issues.role.collaborator=共同作業者
|
issues.role.collaborator=共同作業者
|
||||||
issues.role.collaborator_helper=このユーザーはリポジトリ上で共同作業するように招待されています。
|
issues.role.collaborator_helper=このユーザーはリポジトリ上で共同作業するように招待されています。
|
||||||
issues.role.first_time_contributor=初めての貢献者
|
issues.role.first_time_contributor=初めての貢献者
|
||||||
issues.role.first_time_contributor_helper=これは、このユーザーのリポジトリへの最初の貢献です。
|
issues.role.first_time_contributor_helper=これは、このユーザーによるリポジトリへの最初の貢献です。
|
||||||
issues.role.contributor=貢献者
|
issues.role.contributor=貢献者
|
||||||
issues.role.contributor_helper=このユーザーは以前にリポジトリにコミットしています。
|
issues.role.contributor_helper=このユーザーは以前にリポジトリにコミットしています。
|
||||||
issues.re_request_review=レビューを再依頼
|
issues.re_request_review=レビューを再依頼
|
||||||
@ -2011,7 +2011,8 @@ settings.mirror_settings.docs.more_information_if_disabled=プッシュミラー
|
|||||||
settings.mirror_settings.docs.doc_link_title=リポジトリをミラーリングするには?
|
settings.mirror_settings.docs.doc_link_title=リポジトリをミラーリングするには?
|
||||||
settings.mirror_settings.docs.doc_link_pull_section=ドキュメントの「リモートリポジトリからのプル」セクション。
|
settings.mirror_settings.docs.doc_link_pull_section=ドキュメントの「リモートリポジトリからのプル」セクション。
|
||||||
settings.mirror_settings.docs.pulling_remote_title=リモートリポジトリからのプル
|
settings.mirror_settings.docs.pulling_remote_title=リモートリポジトリからのプル
|
||||||
settings.mirror_settings.mirrored_repository=同期するリポジトリ
|
settings.mirror_settings.mirrored_repository=ミラー元のリポジトリ
|
||||||
|
settings.mirror_settings.pushed_repository=プッシュ先のリポジトリ
|
||||||
settings.mirror_settings.direction=方向
|
settings.mirror_settings.direction=方向
|
||||||
settings.mirror_settings.direction.pull=プル
|
settings.mirror_settings.direction.pull=プル
|
||||||
settings.mirror_settings.direction.push=プッシュ
|
settings.mirror_settings.direction.push=プッシュ
|
||||||
@ -3546,6 +3547,8 @@ runs.actors_no_select=すべてのアクター
|
|||||||
runs.status_no_select=すべてのステータス
|
runs.status_no_select=すべてのステータス
|
||||||
runs.no_results=一致する結果はありません。
|
runs.no_results=一致する結果はありません。
|
||||||
runs.no_workflows=ワークフローはまだありません。
|
runs.no_workflows=ワークフローはまだありません。
|
||||||
|
runs.no_workflows.quick_start=Gitea Actions の始め方がわからない? では<a target="_blank" rel="noopener noreferrer" href="%s">クイックスタートガイド</a>をご覧ください。
|
||||||
|
runs.no_workflows.documentation=Gitea Actions の詳細については、<a target="_blank" rel="noopener noreferrer" href="%s">ドキュメント</a>を参照してください。
|
||||||
runs.no_runs=ワークフローはまだ実行されていません。
|
runs.no_runs=ワークフローはまだ実行されていません。
|
||||||
runs.empty_commit_message=(空のコミットメッセージ)
|
runs.empty_commit_message=(空のコミットメッセージ)
|
||||||
|
|
||||||
|
2
public/assets/img/svg/gitea-bitbucket.svg
generated
@ -1 +1 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" class="gitea-bitbucket__svg gitea-bitbucket__gitea-bitbucket svg gitea-bitbucket" preserveAspectRatio="xMinYMin meet" viewBox="0 0 256 295" width="16" height="16"><g fill="#205081"><path d="M128 0C57.732 0 .012 18.822.012 42.663c0 6.274 15.057 95.364 21.331 130.498 2.51 16.312 43.918 38.898 106.657 38.898 62.74 0 102.893-22.586 106.657-38.898 6.274-35.134 21.331-124.224 21.331-130.498C254.734 18.822 198.268 0 128 0m0 183.199c-22.586 0-40.153-17.567-40.153-40.153s17.567-40.153 40.153-40.153 40.153 17.567 40.153 40.153c0 21.331-17.567 40.153-40.153 40.153m0-127.988c-45.172 0-81.561-7.53-81.561-17.567 0-10.039 36.389-17.567 81.561-17.567s81.561 7.528 81.561 17.567c0 10.038-36.389 17.567-81.561 17.567"/><path d="M220.608 207.04c-2.51 0-3.764 1.255-3.764 1.255s-31.37 25.096-87.835 25.096c-56.466 0-87.835-25.096-87.835-25.096s-2.51-1.255-3.765-1.255c-2.51 0-5.019 1.255-5.019 5.02v1.254c5.02 26.35 8.784 45.172 8.784 47.682 3.764 18.822 41.408 33.88 86.58 33.88s82.816-15.058 86.58-33.88c0-2.51 3.765-21.332 8.784-47.682v-1.255c1.255-2.51 0-5.019-2.51-5.019"/><circle cx="128" cy="141.791" r="20.077"/></g></svg>
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 62.42 62.42" class="svg gitea-bitbucket" width="16" height="16" aria-hidden="true"><defs><linearGradient id="gitea-bitbucket__a" x1="64.01" x2="32.99" y1="30.27" y2="54.48" gradientUnits="userSpaceOnUse"><stop offset=".18" stop-color="#0052cc"/><stop offset="1" stop-color="#2684ff"/></linearGradient></defs><g data-name="Layer 2"><path fill="#2684ff" d="M2 3.13a2 2 0 0 0-2 2.32l8.49 51.54a2.72 2.72 0 0 0 2.66 2.27h40.73a2 2 0 0 0 2-1.68l8.49-52.12a2 2 0 0 0-2-2.32Zm35.75 37.25h-13l-3.52-18.39H40.9Z"/><path fill="url(#gitea-bitbucket__a)" d="M59.67 25.12H40.9l-3.15 18.39h-13L9.4 61.73a2.7 2.7 0 0 0 1.75.66h40.74a2 2 0 0 0 2-1.68Z" transform="translate(0 -3.13)"/></g></svg>
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 732 B |
2
public/assets/img/svg/gitea-facebook.svg
generated
@ -1 +1 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" class="gitea-facebook__svg gitea-facebook__gitea-facebook svg gitea-facebook" style="shape-rendering:geometricPrecision;text-rendering:geometricPrecision;image-rendering:optimizeQuality;fill-rule:evenodd;clip-rule:evenodd" viewBox="0 0 128 128" width="16" height="16"><path fill="#395b97" d="M93.5 8.5q-2.177 1.203-5 1.5L10 88.5q-.297 2.823-1.5 5a552 552 0 0 1-.5-56Q11.75 11.75 37.5 8a552 552 0 0 1 56 .5" style="opacity:.995"/><path fill="#366098" d="M93.5 8.5q23.832 6.337 26 31a677 677 0 0 0-1.5 37l-35 35a32.4 32.4 0 0 0-.5 8 442 442 0 0 1-1-42h14a380 380 0 0 0 3-17h-17q-3.75-20.745 17-18v-16q-38.632-4.865-33 34h-14v17h14v42q-14.01.25-28-.5-23.177-2.93-29-25.5 1.203-2.177 1.5-5L88.5 10q2.823-.297 5-1.5" style="opacity:.976"/><path fill="#346499" d="M119.5 39.5q.25 25.005-.5 50-5.432 30.368-36.5 30a32.4 32.4 0 0 1 .5-8l35-35q.254-18.76 1.5-37" style="opacity:.918"/></svg>
|
<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" fill-rule="evenodd" clip-rule="evenodd" image-rendering="optimizeQuality" shape-rendering="geometricPrecision" text-rendering="geometricPrecision" viewBox="0 0 14222 14222" class="svg gitea-facebook" width="16" height="16" aria-hidden="true"><g fill-rule="nonzero"><path fill="#1977f3" d="M14222 7111C14222 3184 11038 0 7111 0S0 3184 0 7111c0 3549 2600 6491 6000 7025V9167H4194V7111h1806V5544c0-1782 1062-2767 2686-2767 778 0 1592 139 1592 139v1750h-897c-883 0-1159 548-1159 1111v1334h1972l-315 2056H8222v4969c3400-533 6000-3475 6000-7025"/><path fill="#fefefe" d="m9879 9167 315-2056H8222V5777c0-562 275-1111 1159-1111h897V2916s-814-139-1592-139c-1624 0-2686 984-2686 2767v1567H4194v2056h1806v4969c362 57 733 86 1111 86s749-30 1111-86V9167z"/></g></svg>
|
Before Width: | Height: | Size: 941 B After Width: | Height: | Size: 815 B |
1
public/assets/img/svg/gitea-jetbrains.svg
generated
Normal file
@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" viewBox="0 0 70 70" class="svg gitea-jetbrains" width="16" height="16" aria-hidden="true"><linearGradient id="gitea-jetbrains__a" x1=".79" x2="33.317" y1="40.089" y2="40.089" gradientUnits="userSpaceOnUse"><stop offset=".258" style="stop-color:#f97a12"/><stop offset=".459" style="stop-color:#b07b58"/><stop offset=".724" style="stop-color:#577bae"/><stop offset=".91" style="stop-color:#1e7ce5"/><stop offset="1" style="stop-color:#087cfa"/></linearGradient><path d="M17.7 54.6.8 41.2l8.4-15.6L33.3 35z" style="fill:url(#gitea-jetbrains__a)"/><linearGradient id="gitea-jetbrains__b" x1="25.767" x2="79.424" y1="24.88" y2="54.57" gradientUnits="userSpaceOnUse"><stop offset="0" style="stop-color:#f97a12"/><stop offset=".072" style="stop-color:#cb7a3e"/><stop offset=".154" style="stop-color:#9e7b6a"/><stop offset=".242" style="stop-color:#757b91"/><stop offset=".334" style="stop-color:#537bb1"/><stop offset=".432" style="stop-color:#387ccc"/><stop offset=".538" style="stop-color:#237ce0"/><stop offset=".655" style="stop-color:#147cef"/><stop offset=".792" style="stop-color:#0b7cf7"/><stop offset="1" style="stop-color:#087cfa"/></linearGradient><path d="m70 18.7-1.3 40.5L41.8 70 25.6 59.6 49.3 35 38.9 12.3l9.3-11.2z" style="fill:url(#gitea-jetbrains__b)"/><linearGradient id="gitea-jetbrains__c" x1="63.228" x2="48.29" y1="42.915" y2="-1.719" gradientUnits="userSpaceOnUse"><stop offset="0" style="stop-color:#fe315d"/><stop offset=".078" style="stop-color:#cb417e"/><stop offset=".16" style="stop-color:#9e4e9b"/><stop offset=".247" style="stop-color:#755bb4"/><stop offset=".339" style="stop-color:#5365ca"/><stop offset=".436" style="stop-color:#386ddb"/><stop offset=".541" style="stop-color:#2374e9"/><stop offset=".658" style="stop-color:#1478f3"/><stop offset=".794" style="stop-color:#0b7bf8"/><stop offset="1" style="stop-color:#087cfa"/></linearGradient><path d="M70 18.7 48.7 43.9l-9.8-31.6 9.3-11.2z" style="fill:url(#gitea-jetbrains__c)"/><linearGradient id="gitea-jetbrains__d" x1="10.72" x2="55.524" y1="16.473" y2="90.58" gradientUnits="userSpaceOnUse"><stop offset="0" style="stop-color:#fe315d"/><stop offset=".04" style="stop-color:#f63462"/><stop offset=".104" style="stop-color:#df3a71"/><stop offset=".167" style="stop-color:#c24383"/><stop offset=".291" style="stop-color:#ad4a91"/><stop offset=".55" style="stop-color:#755bb4"/><stop offset=".917" style="stop-color:#1d76ed"/><stop offset="1" style="stop-color:#087cfa"/></linearGradient><path d="M33.7 58.1 5.6 68.3l4.5-15.8L16 33.1 0 27.7 10.1 0l22 2.7 21.6 24.7z" style="fill:url(#gitea-jetbrains__d)"/><path d="M13.7 13.5h43.2v43.2H13.7z" style="fill:#000"/><path d="M17.7 48.6h16.2v2.7H17.7zM29.4 22.4v-3.3h-9v3.3H23v11.3h-2.6V37h9v-3.3h-2.5V22.4zM38 37.3c-1.4 0-2.6-.3-3.5-.8s-1.7-1.2-2.3-1.9l2.5-2.8c.5.6 1 1 1.5 1.3s1.1.5 1.7.5c.7 0 1.3-.2 1.8-.7.4-.5.6-1.2.6-2.3V19.1h4v11.7c0 1.1-.1 2-.4 2.8s-.7 1.4-1.3 2c-.5.5-1.2 1-2 1.2-.8.3-1.6.5-2.6.5" style="fill:#fff"/></svg>
|
After Width: | Height: | Size: 3.0 KiB |
2
public/assets/img/svg/gitea-microsoftonline.svg
generated
@ -1 +1 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" class="gitea-microsoftonline__svg gitea-microsoftonline__gitea-microsoftonline svg gitea-microsoftonline" viewBox="0 0 2075 2499.8" width="16" height="16"><path fill="#eb3c00" d="M0 2016.6V496.8L1344.4 0 2075 233.7v2045.9l-730.6 220.3zl1344.4 161.8V409.2L467.6 613.8v1198.3z"/></svg>
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 48 48" class="svg gitea-microsoftonline" width="16" height="16" aria-hidden="true"><path fill="url(#gitea-microsoftonline__a)" d="m20.084 3.026-.224.136a8 8 0 0 0-1.009.722l.648-.456H25L26 11l-5 5-5 3.475v4.008a8 8 0 0 0 3.857 6.844l5.264 3.186L14 40h-2.145l-3.998-2.42A8 8 0 0 1 4 30.737V17.26a8 8 0 0 1 3.86-6.846l12-7.258q.111-.068.224-.131Z"/><path fill="url(#gitea-microsoftonline__b)" d="m20.084 3.026-.224.136a8 8 0 0 0-1.009.722l.648-.456H25L26 11l-5 5-5 3.475v4.008a8 8 0 0 0 3.857 6.844l5.264 3.186L14 40h-2.145l-3.998-2.42A8 8 0 0 1 4 30.737V17.26a8 8 0 0 1 3.86-6.846l12-7.258q.111-.068.224-.131Z"/><path fill="url(#gitea-microsoftonline__c)" d="M32 19v4.48a8 8 0 0 1-3.857 6.844l-12 7.264a8 8 0 0 1-8.008.16l11.722 7.096a8 8 0 0 0 8.286 0l12-7.264A8 8 0 0 0 44 30.736V27.5L43 26z"/><path fill="url(#gitea-microsoftonline__d)" d="M32 19v4.48a8 8 0 0 1-3.857 6.844l-12 7.264a8 8 0 0 1-8.008.16l11.722 7.096a8 8 0 0 0 8.286 0l12-7.264A8 8 0 0 0 44 30.736V27.5L43 26z"/><path fill="url(#gitea-microsoftonline__e)" d="m40.14 10.415-12-7.258a8 8 0 0 0-8.042-.139l-.238.144A8 8 0 0 0 16 10.008v9.483l3.86-2.334a8 8 0 0 1 8.28 0l12 7.258A8 8 0 0 1 43.997 31q.004-.132.004-.263V17.26a8 8 0 0 0-3.86-6.845Z"/><path fill="url(#gitea-microsoftonline__f)" d="m40.14 10.415-12-7.258a8 8 0 0 0-8.042-.139l-.238.144A8 8 0 0 0 16 10.008v9.483l3.86-2.334a8 8 0 0 1 8.28 0l12 7.258A8 8 0 0 1 43.997 31q.004-.132.004-.263V17.26a8 8 0 0 0-3.86-6.845Z"/><path fill="url(#gitea-microsoftonline__g)" d="M4.004 30.998"/><path fill="url(#gitea-microsoftonline__h)" d="M4.004 30.998"/><defs><radialGradient id="gitea-microsoftonline__a" cx="0" cy="0" r="1" gradientTransform="rotate(110.528 5.021 11.358)scale(33.3657 58.1966)" gradientUnits="userSpaceOnUse"><stop offset=".064" stop-color="#AE7FE2"/><stop offset="1" stop-color="#0078D4"/></radialGradient><radialGradient id="gitea-microsoftonline__c" cx="0" cy="0" r="1" gradientTransform="matrix(30.7198 -4.51832 2.98465 20.29248 10.43 36.351)" gradientUnits="userSpaceOnUse"><stop offset=".134" stop-color="#D59DFF"/><stop offset="1" stop-color="#5E438F"/></radialGradient><radialGradient id="gitea-microsoftonline__e" cx="0" cy="0" r="1" gradientTransform="matrix(-24.1583 -6.12555 10.3118 -40.66824 41.055 26.504)" gradientUnits="userSpaceOnUse"><stop offset=".058" stop-color="#50E6FF"/><stop offset="1" stop-color="#436DCD"/></radialGradient><radialGradient id="gitea-microsoftonline__g" cx="0" cy="0" r="1" gradientTransform="matrix(-24.1583 -6.12555 10.3118 -40.66824 41.055 26.504)" gradientUnits="userSpaceOnUse"><stop offset=".058" stop-color="#50E6FF"/><stop offset="1" stop-color="#436DCD"/></radialGradient><linearGradient id="gitea-microsoftonline__b" x1="17.512" x2="12.751" y1="37.868" y2="29.635" gradientUnits="userSpaceOnUse"><stop stop-color="#114A8B"/><stop offset="1" stop-color="#0078D4" stop-opacity="0"/></linearGradient><linearGradient id="gitea-microsoftonline__d" x1="40.357" x2="35.255" y1="25.377" y2="32.692" gradientUnits="userSpaceOnUse"><stop stop-color="#493474"/><stop offset="1" stop-color="#8C66BA" stop-opacity="0"/></linearGradient><linearGradient id="gitea-microsoftonline__f" x1="16.976" x2="24.487" y1="3.057" y2="3.057" gradientUnits="userSpaceOnUse"><stop stop-color="#2D3F80"/><stop offset="1" stop-color="#436DCD" stop-opacity="0"/></linearGradient><linearGradient id="gitea-microsoftonline__h" x1="16.976" x2="24.487" y1="3.057" y2="3.057" gradientUnits="userSpaceOnUse"><stop stop-color="#2D3F80"/><stop offset="1" stop-color="#436DCD" stop-opacity="0"/></linearGradient></defs></svg>
|
Before Width: | Height: | Size: 342 B After Width: | Height: | Size: 3.6 KiB |
@ -1 +0,0 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" viewBox="0 0 70 70" class="svg gitea-open-with-jetbrains" width="16" height="16" aria-hidden="true"><linearGradient id="gitea-open-with-jetbrains__a" x1=".79" x2="33.317" y1="40.089" y2="40.089" gradientUnits="userSpaceOnUse"><stop offset=".258" style="stop-color:#f97a12"/><stop offset=".459" style="stop-color:#b07b58"/><stop offset=".724" style="stop-color:#577bae"/><stop offset=".91" style="stop-color:#1e7ce5"/><stop offset="1" style="stop-color:#087cfa"/></linearGradient><path d="M17.7 54.6.8 41.2l8.4-15.6L33.3 35z" style="fill:url(#gitea-open-with-jetbrains__a)"/><linearGradient id="gitea-open-with-jetbrains__b" x1="25.767" x2="79.424" y1="24.88" y2="54.57" gradientUnits="userSpaceOnUse"><stop offset="0" style="stop-color:#f97a12"/><stop offset=".072" style="stop-color:#cb7a3e"/><stop offset=".154" style="stop-color:#9e7b6a"/><stop offset=".242" style="stop-color:#757b91"/><stop offset=".334" style="stop-color:#537bb1"/><stop offset=".432" style="stop-color:#387ccc"/><stop offset=".538" style="stop-color:#237ce0"/><stop offset=".655" style="stop-color:#147cef"/><stop offset=".792" style="stop-color:#0b7cf7"/><stop offset="1" style="stop-color:#087cfa"/></linearGradient><path d="m70 18.7-1.3 40.5L41.8 70 25.6 59.6 49.3 35 38.9 12.3l9.3-11.2z" style="fill:url(#gitea-open-with-jetbrains__b)"/><linearGradient id="gitea-open-with-jetbrains__c" x1="63.228" x2="48.29" y1="42.915" y2="-1.719" gradientUnits="userSpaceOnUse"><stop offset="0" style="stop-color:#fe315d"/><stop offset=".078" style="stop-color:#cb417e"/><stop offset=".16" style="stop-color:#9e4e9b"/><stop offset=".247" style="stop-color:#755bb4"/><stop offset=".339" style="stop-color:#5365ca"/><stop offset=".436" style="stop-color:#386ddb"/><stop offset=".541" style="stop-color:#2374e9"/><stop offset=".658" style="stop-color:#1478f3"/><stop offset=".794" style="stop-color:#0b7bf8"/><stop offset="1" style="stop-color:#087cfa"/></linearGradient><path d="M70 18.7 48.7 43.9l-9.8-31.6 9.3-11.2z" style="fill:url(#gitea-open-with-jetbrains__c)"/><linearGradient id="gitea-open-with-jetbrains__d" x1="10.72" x2="55.524" y1="16.473" y2="90.58" gradientUnits="userSpaceOnUse"><stop offset="0" style="stop-color:#fe315d"/><stop offset=".04" style="stop-color:#f63462"/><stop offset=".104" style="stop-color:#df3a71"/><stop offset=".167" style="stop-color:#c24383"/><stop offset=".291" style="stop-color:#ad4a91"/><stop offset=".55" style="stop-color:#755bb4"/><stop offset=".917" style="stop-color:#1d76ed"/><stop offset="1" style="stop-color:#087cfa"/></linearGradient><path d="M33.7 58.1 5.6 68.3l4.5-15.8L16 33.1 0 27.7 10.1 0l22 2.7 21.6 24.7z" style="fill:url(#gitea-open-with-jetbrains__d)"/><path d="M13.7 13.5h43.2v43.2H13.7z" style="fill:#000"/><path d="M17.7 48.6h16.2v2.7H17.7zM29.4 22.4v-3.3h-9v3.3H23v11.3h-2.6V37h9v-3.3h-2.5V22.4zM38 37.3c-1.4 0-2.6-.3-3.5-.8s-1.7-1.2-2.3-1.9l2.5-2.8c.5.6 1 1 1.5 1.3s1.1.5 1.7.5c.7 0 1.3-.2 1.8-.7.4-.5.6-1.2.6-2.3V19.1h4v11.7c0 1.1-.1 2-.4 2.8s-.7 1.4-1.3 2c-.5.5-1.2 1-2 1.2-.8.3-1.6.5-2.6.5" style="fill:#fff"/></svg>
|
|
Before Width: | Height: | Size: 3.0 KiB |
1
public/assets/img/svg/gitea-open-with-vscode.svg
generated
@ -1 +0,0 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-1 -1 34 34" class="svg gitea-open-with-vscode" width="16" height="16" aria-hidden="true"><path d="M30.9 3.4 24.3.3a2 2 0 0 0-2.3.4L9.4 12.2 3.9 8c-.5-.4-1.2-.4-1.7 0L.4 9.8c-.5.5-.5 1.4 0 2L5.2 16 .4 20.3c-.5.6-.5 1.5 0 2L2.2 24c.5.5 1.2.5 1.7 0l5.5-4L22 31.2a2 2 0 0 0 2.3.4l6.6-3.2a2 2 0 0 0 1.1-1.8V5.2a2 2 0 0 0-1.1-1.8M24 23.3 14.4 16 24 8.7z"/></svg>
|
|
Before Width: | Height: | Size: 406 B |
@ -1 +0,0 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" fill-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="2" clip-rule="evenodd" viewBox="0 0 16 16" class="svg gitea-open-with-vscodium" width="16" height="16" aria-hidden="true"><path fill-rule="nonzero" d="m10.2.2.5-.3c.3 0 .5.2.7.4l.2.8-.2 1-.8 2.4c-.3 1-.4 2 0 2.9l.8-2c.2 0 .4.1.4.3l-.3 1L9.2 13l3.1-2.9c.3-.2.7-.5.8-1a2 2 0 0 0-.3-1c-.2-.5-.5-.9-.6-1.4l.1-.7c.1-.1.3-.2.5-.1.2 0 .3.2.4.4.3.5.4 1.2.5 1.8l.6-1.2c0-.2.2-.4.4-.6l.4-.2c.2 0 .4.3.4.4v.6l-.8 1.6-1.4 1.8 1-.4c.2 0 .6.2.7.5 0 .2 0 .4-.2.5-.3.2-.6.2-1 .2-1 0-2.2.6-2.9 1.4L9.6 15c-.4.4-.9 1-1.4.8-.8-.1-.8-1.3-1-1.8 0-.3-.2-.6-.4-.7-.3-.2-.5-.3-.8-.3-.6-.1-1.2 0-1.8-.2l-.8-.4-.4-.7c-.3-.6-.3-1.2-.5-1.8A4 4 0 0 0 1 8l-.4-.4v-.4c.2-.2.5-.2.7 0 .5.2.5.8 1 1.1V6.2s.3-.1.4 0l.2.5L3 9c.4-.4.6-1 .5-1.5L3.4 7l.3-.2c.2 0 .3.2.4.3v.7c0 .6-.3 1.1-.4 1.7-.2.4-.3 1-.1 1.4.1.5.5.9.9 1 .5.3 1.1.4 1.7.4-.4-.6-.7-1.2-.7-2 0-.7.4-1.3.6-2C6.3 7 5.7 5.8 4.8 5l-1.5-.7c-.4-.2-.7-.7-.7-1.2.3-.1.7 0 1 .1L5 4.5l.6.1c.2-.3 0-.6-.2-.8-.3-.5-1-.6-1.3-1a.9.9 0 0 1-.2-.8c0-.2.3-.4.5-.4.4 0 .7.3.9.5.8.8 1.2 1.8 1.4 3s0 2.5-.2 3.7c0 .3-.2.5-.1.8l.2.2c.2 0 .4 0 .5-.2.4-.3.8-.8.9-1.3l.1-1.2.1-.6.4-.2.3.3v.6c-.1.5-.2 1-.5 1.6a2 2 0 0 1-.6 1l-1 1c-.1.2-.2.6-.1.9 0 .2.2.4.4.5.4.2.8.2 1 0 .3-.1.5-.4.7-.6l.5-1.4.4-2.5C9.7 7 9.6 6 9 5.2c-.2-.4-.5-.7-1-1l-1-.8c-.2-.3-.4-.7-.3-1.2h.6c.4.1.7.4.9.8s.4.8.9 1l-1-2c-.1-.3-.3-.5-.2-.8 0-.2.2-.4.4-.4s.4.1.5.3l.2.5 1 3.1a4 4 0 0 0 .4-2.3L10 1V.2Z"/></svg>
|
|
Before Width: | Height: | Size: 1.5 KiB |
2
public/assets/img/svg/gitea-twitter.svg
generated
@ -1 +1 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" fill-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="2" aria-hidden="true" class="gitea-twitter__svg gitea-twitter__gitea-twitter svg gitea-twitter" clip-rule="evenodd" viewBox="-89.009 -46.884 643.937 446.884" width="16" height="16"><path fill="#1da1f2" fill-rule="nonzero" d="M154.729 400c185.669 0 287.205-153.876 287.205-287.312 0-4.37-.089-8.72-.286-13.052A205.3 205.3 0 0 0 492 47.346c-18.087 8.044-37.55 13.458-57.968 15.899 20.841-12.501 36.84-32.278 44.389-55.852a202.4 202.4 0 0 1-64.098 24.511C395.903 12.276 369.679 0 340.641 0c-55.744 0-100.948 45.222-100.948 100.965 0 7.925.887 15.631 2.619 23.025-83.895-4.223-158.287-44.405-208.074-105.504A100.74 100.74 0 0 0 20.57 69.24c0 35.034 17.82 65.961 44.92 84.055a100.2 100.2 0 0 1-45.716-12.63c-.015.424-.015.837-.015 1.29 0 48.903 34.794 89.734 80.982 98.986a101 101 0 0 1-26.617 3.553c-6.493 0-12.821-.639-18.971-1.82 12.851 40.122 50.115 69.319 94.296 70.135-34.549 27.089-78.07 43.224-125.371 43.224A205 205 0 0 1 0 354.634c44.674 28.645 97.72 45.359 154.734 45.359"/></svg>
|
<svg viewBox="0 0 24 24" class="svg gitea-twitter" xmlns="http://www.w3.org/2000/svg" width="16" height="16" aria-hidden="true"><path d="M14.095 10.316 22.286 1h-1.94L13.23 9.088 7.551 1H1l8.59 12.231L1 23h1.94l7.51-8.543 6 8.543H23zm-2.658 3.022-.872-1.218L3.64 2.432h2.98l5.59 7.821.869 1.219 7.265 10.166h-2.982z"/></svg>
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 324 B |
1
public/assets/img/svg/gitea-vscode.svg
generated
Normal file
@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-1 -1 34 34" class="svg gitea-vscode" width="16" height="16" aria-hidden="true"><path d="M30.9 3.4 24.3.3a2 2 0 0 0-2.3.4L9.4 12.2 3.9 8c-.5-.4-1.2-.4-1.7 0L.4 9.8c-.5.5-.5 1.4 0 2L5.2 16 .4 20.3c-.5.6-.5 1.5 0 2L2.2 24c.5.5 1.2.5 1.7 0l5.5-4L22 31.2a2 2 0 0 0 2.3.4l6.6-3.2a2 2 0 0 0 1.1-1.8V5.2a2 2 0 0 0-1.1-1.8M24 23.3 14.4 16 24 8.7z"/></svg>
|
After Width: | Height: | Size: 396 B |
1
public/assets/img/svg/gitea-vscodium.svg
generated
Normal file
@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" fill-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="2" clip-rule="evenodd" viewBox="0 0 16 16" class="svg gitea-vscodium" width="16" height="16" aria-hidden="true"><path fill-rule="nonzero" d="m10.2.2.5-.3c.3 0 .5.2.7.4l.2.8-.2 1-.8 2.4c-.3 1-.4 2 0 2.9l.8-2c.2 0 .4.1.4.3l-.3 1L9.2 13l3.1-2.9c.3-.2.7-.5.8-1a2 2 0 0 0-.3-1c-.2-.5-.5-.9-.6-1.4l.1-.7c.1-.1.3-.2.5-.1.2 0 .3.2.4.4.3.5.4 1.2.5 1.8l.6-1.2c0-.2.2-.4.4-.6l.4-.2c.2 0 .4.3.4.4v.6l-.8 1.6-1.4 1.8 1-.4c.2 0 .6.2.7.5 0 .2 0 .4-.2.5-.3.2-.6.2-1 .2-1 0-2.2.6-2.9 1.4L9.6 15c-.4.4-.9 1-1.4.8-.8-.1-.8-1.3-1-1.8 0-.3-.2-.6-.4-.7-.3-.2-.5-.3-.8-.3-.6-.1-1.2 0-1.8-.2l-.8-.4-.4-.7c-.3-.6-.3-1.2-.5-1.8A4 4 0 0 0 1 8l-.4-.4v-.4c.2-.2.5-.2.7 0 .5.2.5.8 1 1.1V6.2s.3-.1.4 0l.2.5L3 9c.4-.4.6-1 .5-1.5L3.4 7l.3-.2c.2 0 .3.2.4.3v.7c0 .6-.3 1.1-.4 1.7-.2.4-.3 1-.1 1.4.1.5.5.9.9 1 .5.3 1.1.4 1.7.4-.4-.6-.7-1.2-.7-2 0-.7.4-1.3.6-2C6.3 7 5.7 5.8 4.8 5l-1.5-.7c-.4-.2-.7-.7-.7-1.2.3-.1.7 0 1 .1L5 4.5l.6.1c.2-.3 0-.6-.2-.8-.3-.5-1-.6-1.3-1a.9.9 0 0 1-.2-.8c0-.2.3-.4.5-.4.4 0 .7.3.9.5.8.8 1.2 1.8 1.4 3s0 2.5-.2 3.7c0 .3-.2.5-.1.8l.2.2c.2 0 .4 0 .5-.2.4-.3.8-.8.9-1.3l.1-1.2.1-.6.4-.2.3.3v.6c-.1.5-.2 1-.5 1.6a2 2 0 0 1-.6 1l-1 1c-.1.2-.2.6-.1.9 0 .2.2.4.4.5.4.2.8.2 1 0 .3-.1.5-.4.7-.6l.5-1.4.4-2.5C9.7 7 9.6 6 9 5.2c-.2-.4-.5-.7-1-1l-1-.8c-.2-.3-.4-.7-.3-1.2h.6c.4.1.7.4.9.8s.4.8.9 1l-1-2c-.1-.3-.3-.5-.2-.8 0-.2.2-.4.4-.4s.4.1.5.3l.2.5 1 3.1a4 4 0 0 0 .4-2.3L10 1V.2Z"/></svg>
|
After Width: | Height: | Size: 1.5 KiB |
@ -133,7 +133,7 @@ func CreateUser(ctx *context.APIContext) {
|
|||||||
u.UpdatedUnix = u.CreatedUnix
|
u.UpdatedUnix = u.CreatedUnix
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := user_model.CreateUser(ctx, u, overwriteDefault); err != nil {
|
if err := user_model.AdminCreateUser(ctx, u, overwriteDefault); err != nil {
|
||||||
if user_model.IsErrUserAlreadyExist(err) ||
|
if user_model.IsErrUserAlreadyExist(err) ||
|
||||||
user_model.IsErrEmailAlreadyUsed(err) ||
|
user_model.IsErrEmailAlreadyUsed(err) ||
|
||||||
db.IsErrNameReserved(err) ||
|
db.IsErrNameReserved(err) ||
|
||||||
@ -209,7 +209,7 @@ func EditUser(ctx *context.APIContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if form.Email != nil {
|
if form.Email != nil {
|
||||||
if err := user_service.AddOrSetPrimaryEmailAddress(ctx, ctx.ContextUser, *form.Email); err != nil {
|
if err := user_service.AdminAddOrSetPrimaryEmailAddress(ctx, ctx.ContextUser, *form.Email); err != nil {
|
||||||
switch {
|
switch {
|
||||||
case user_model.IsErrEmailCharIsNotSupported(err), user_model.IsErrEmailInvalid(err):
|
case user_model.IsErrEmailCharIsNotSupported(err), user_model.IsErrEmailInvalid(err):
|
||||||
ctx.Error(http.StatusBadRequest, "EmailInvalid", err)
|
ctx.Error(http.StatusBadRequest, "EmailInvalid", err)
|
||||||
|
@ -709,7 +709,7 @@ func CreateIssue(ctx *context.APIContext) {
|
|||||||
form.Labels = make([]int64, 0)
|
form.Labels = make([]int64, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := issue_service.NewIssue(ctx, ctx.Repo.Repository, issue, form.Labels, nil, assigneeIDs); err != nil {
|
if err := issue_service.NewIssue(ctx, ctx.Repo.Repository, issue, form.Labels, nil, assigneeIDs, 0); err != nil {
|
||||||
if repo_model.IsErrUserDoesNotHaveAccessToRepo(err) {
|
if repo_model.IsErrUserDoesNotHaveAccessToRepo(err) {
|
||||||
ctx.Error(http.StatusBadRequest, "UserDoesNotHaveAccessToRepo", err)
|
ctx.Error(http.StatusBadRequest, "UserDoesNotHaveAccessToRepo", err)
|
||||||
} else if errors.Is(err, user_model.ErrBlockedUser) {
|
} else if errors.Is(err, user_model.ErrBlockedUser) {
|
||||||
|
@ -14,7 +14,7 @@ import (
|
|||||||
"code.gitea.io/gitea/routers/api/v1/utils"
|
"code.gitea.io/gitea/routers/api/v1/utils"
|
||||||
"code.gitea.io/gitea/services/context"
|
"code.gitea.io/gitea/services/context"
|
||||||
"code.gitea.io/gitea/services/convert"
|
"code.gitea.io/gitea/services/convert"
|
||||||
files_service "code.gitea.io/gitea/services/repository/files"
|
commitstatus_service "code.gitea.io/gitea/services/repository/commitstatus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewCommitStatus creates a new CommitStatus
|
// NewCommitStatus creates a new CommitStatus
|
||||||
@ -64,7 +64,7 @@ func NewCommitStatus(ctx *context.APIContext) {
|
|||||||
Description: form.Description,
|
Description: form.Description,
|
||||||
Context: form.Context,
|
Context: form.Context,
|
||||||
}
|
}
|
||||||
if err := files_service.CreateCommitStatus(ctx, ctx.Repo.Repository, ctx.Doer, sha, status); err != nil {
|
if err := commitstatus_service.CreateCommitStatus(ctx, ctx.Repo.Repository, ctx.Doer, sha, status); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "CreateCommitStatus", err)
|
ctx.Error(http.StatusInternalServerError, "CreateCommitStatus", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
asymkey_model "code.gitea.io/gitea/models/asymkey"
|
|
||||||
authmodel "code.gitea.io/gitea/models/auth"
|
authmodel "code.gitea.io/gitea/models/auth"
|
||||||
"code.gitea.io/gitea/modules/cache"
|
"code.gitea.io/gitea/modules/cache"
|
||||||
"code.gitea.io/gitea/modules/eventsource"
|
"code.gitea.io/gitea/modules/eventsource"
|
||||||
@ -33,6 +32,7 @@ import (
|
|||||||
"code.gitea.io/gitea/routers/private"
|
"code.gitea.io/gitea/routers/private"
|
||||||
web_routers "code.gitea.io/gitea/routers/web"
|
web_routers "code.gitea.io/gitea/routers/web"
|
||||||
actions_service "code.gitea.io/gitea/services/actions"
|
actions_service "code.gitea.io/gitea/services/actions"
|
||||||
|
asymkey_service "code.gitea.io/gitea/services/asymkey"
|
||||||
"code.gitea.io/gitea/services/auth"
|
"code.gitea.io/gitea/services/auth"
|
||||||
"code.gitea.io/gitea/services/auth/source/oauth2"
|
"code.gitea.io/gitea/services/auth/source/oauth2"
|
||||||
"code.gitea.io/gitea/services/automerge"
|
"code.gitea.io/gitea/services/automerge"
|
||||||
@ -94,7 +94,7 @@ func syncAppConfForGit(ctx context.Context) error {
|
|||||||
mustInitCtx(ctx, repo_service.SyncRepositoryHooks)
|
mustInitCtx(ctx, repo_service.SyncRepositoryHooks)
|
||||||
|
|
||||||
log.Info("re-write ssh public keys ...")
|
log.Info("re-write ssh public keys ...")
|
||||||
mustInitCtx(ctx, asymkey_model.RewriteAllPublicKeys)
|
mustInitCtx(ctx, asymkey_service.RewriteAllPublicKeys)
|
||||||
|
|
||||||
return system.AppState.Set(ctx, runtimeState)
|
return system.AppState.Set(ctx, runtimeState)
|
||||||
}
|
}
|
||||||
|
@ -8,9 +8,11 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
git_model "code.gitea.io/gitea/models/git"
|
||||||
issues_model "code.gitea.io/gitea/models/issues"
|
issues_model "code.gitea.io/gitea/models/issues"
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
"code.gitea.io/gitea/modules/git"
|
"code.gitea.io/gitea/modules/git"
|
||||||
|
"code.gitea.io/gitea/modules/gitrepo"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
"code.gitea.io/gitea/modules/private"
|
"code.gitea.io/gitea/modules/private"
|
||||||
repo_module "code.gitea.io/gitea/modules/repository"
|
repo_module "code.gitea.io/gitea/modules/repository"
|
||||||
@ -27,6 +29,7 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) {
|
|||||||
|
|
||||||
// We don't rely on RepoAssignment here because:
|
// We don't rely on RepoAssignment here because:
|
||||||
// a) we don't need the git repo in this function
|
// a) we don't need the git repo in this function
|
||||||
|
// OUT OF DATE: we do need the git repo to sync the branch to the db now.
|
||||||
// b) our update function will likely change the repository in the db so we will need to refresh it
|
// b) our update function will likely change the repository in the db so we will need to refresh it
|
||||||
// c) we don't always need the repo
|
// c) we don't always need the repo
|
||||||
|
|
||||||
@ -34,7 +37,11 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) {
|
|||||||
repoName := ctx.Params(":repo")
|
repoName := ctx.Params(":repo")
|
||||||
|
|
||||||
// defer getting the repository at this point - as we should only retrieve it if we're going to call update
|
// defer getting the repository at this point - as we should only retrieve it if we're going to call update
|
||||||
var repo *repo_model.Repository
|
var (
|
||||||
|
repo *repo_model.Repository
|
||||||
|
gitRepo *git.Repository
|
||||||
|
)
|
||||||
|
defer gitRepo.Close() // it's safe to call Close on a nil pointer
|
||||||
|
|
||||||
updates := make([]*repo_module.PushUpdateOptions, 0, len(opts.OldCommitIDs))
|
updates := make([]*repo_module.PushUpdateOptions, 0, len(opts.OldCommitIDs))
|
||||||
wasEmpty := false
|
wasEmpty := false
|
||||||
@ -87,6 +94,63 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) {
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
branchesToSync := make([]*repo_module.PushUpdateOptions, 0, len(updates))
|
||||||
|
for _, update := range updates {
|
||||||
|
if !update.RefFullName.IsBranch() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if repo == nil {
|
||||||
|
repo = loadRepository(ctx, ownerName, repoName)
|
||||||
|
if ctx.Written() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
wasEmpty = repo.IsEmpty
|
||||||
|
}
|
||||||
|
|
||||||
|
if update.IsDelRef() {
|
||||||
|
if err := git_model.AddDeletedBranch(ctx, repo.ID, update.RefFullName.BranchName(), update.PusherID); err != nil {
|
||||||
|
log.Error("Failed to add deleted branch: %s/%s Error: %v", ownerName, repoName, err)
|
||||||
|
ctx.JSON(http.StatusInternalServerError, private.HookPostReceiveResult{
|
||||||
|
Err: fmt.Sprintf("Failed to add deleted branch: %s/%s Error: %v", ownerName, repoName, err),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
branchesToSync = append(branchesToSync, update)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(branchesToSync) > 0 {
|
||||||
|
if gitRepo == nil {
|
||||||
|
var err error
|
||||||
|
gitRepo, err = gitrepo.OpenRepository(ctx, repo)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Failed to open repository: %s/%s Error: %v", ownerName, repoName, err)
|
||||||
|
ctx.JSON(http.StatusInternalServerError, private.HookPostReceiveResult{
|
||||||
|
Err: fmt.Sprintf("Failed to open repository: %s/%s Error: %v", ownerName, repoName, err),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
branchNames = make([]string, 0, len(branchesToSync))
|
||||||
|
commitIDs = make([]string, 0, len(branchesToSync))
|
||||||
|
)
|
||||||
|
for _, update := range branchesToSync {
|
||||||
|
branchNames = append(branchNames, update.RefFullName.BranchName())
|
||||||
|
commitIDs = append(commitIDs, update.NewCommitID)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := repo_service.SyncBranchesToDB(ctx, repo.ID, opts.UserID, branchNames, commitIDs, func(commitID string) (*git.Commit, error) {
|
||||||
|
return gitRepo.GetCommit(commitID)
|
||||||
|
}); err != nil {
|
||||||
|
ctx.JSON(http.StatusInternalServerError, private.HookPostReceiveResult{
|
||||||
|
Err: fmt.Sprintf("Failed to sync branch to DB in repository: %s/%s Error: %v", ownerName, repoName, err),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle Push Options
|
// Handle Push Options
|
||||||
|
@ -177,7 +177,7 @@ func NewUserPost(ctx *context.Context) {
|
|||||||
u.MustChangePassword = form.MustChangePassword
|
u.MustChangePassword = form.MustChangePassword
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := user_model.CreateUser(ctx, u, overwriteDefault); err != nil {
|
if err := user_model.AdminCreateUser(ctx, u, overwriteDefault); err != nil {
|
||||||
switch {
|
switch {
|
||||||
case user_model.IsErrUserAlreadyExist(err):
|
case user_model.IsErrUserAlreadyExist(err):
|
||||||
ctx.Data["Err_UserName"] = true
|
ctx.Data["Err_UserName"] = true
|
||||||
@ -412,7 +412,7 @@ func EditUserPost(ctx *context.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if form.Email != "" {
|
if form.Email != "" {
|
||||||
if err := user_service.AddOrSetPrimaryEmailAddress(ctx, u, form.Email); err != nil {
|
if err := user_service.AdminAddOrSetPrimaryEmailAddress(ctx, u, form.Email); err != nil {
|
||||||
switch {
|
switch {
|
||||||
case user_model.IsErrEmailCharIsNotSupported(err), user_model.IsErrEmailInvalid(err):
|
case user_model.IsErrEmailCharIsNotSupported(err), user_model.IsErrEmailInvalid(err):
|
||||||
ctx.Data["Err_Email"] = true
|
ctx.Data["Err_Email"] = true
|
||||||
|
@ -123,9 +123,21 @@ func resetLocale(ctx *context.Context, u *user_model.User) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func RedirectAfterLogin(ctx *context.Context) {
|
||||||
|
redirectTo := ctx.FormString("redirect_to")
|
||||||
|
if redirectTo == "" {
|
||||||
|
redirectTo = ctx.GetSiteCookie("redirect_to")
|
||||||
|
}
|
||||||
|
middleware.DeleteRedirectToCookie(ctx.Resp)
|
||||||
|
nextRedirectTo := setting.AppSubURL + string(setting.LandingPageURL)
|
||||||
|
if setting.LandingPageURL == setting.LandingPageLogin {
|
||||||
|
nextRedirectTo = setting.AppSubURL + "/" // do not cycle-redirect to the login page
|
||||||
|
}
|
||||||
|
ctx.RedirectToFirst(redirectTo, nextRedirectTo)
|
||||||
|
}
|
||||||
|
|
||||||
func CheckAutoLogin(ctx *context.Context) bool {
|
func CheckAutoLogin(ctx *context.Context) bool {
|
||||||
// Check auto-login
|
isSucceed, err := autoSignIn(ctx) // try to auto-login
|
||||||
isSucceed, err := autoSignIn(ctx)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, auth_service.ErrAuthTokenInvalidHash) {
|
if errors.Is(err, auth_service.ErrAuthTokenInvalidHash) {
|
||||||
ctx.Flash.Error(ctx.Tr("auth.remember_me.compromised"), true)
|
ctx.Flash.Error(ctx.Tr("auth.remember_me.compromised"), true)
|
||||||
@ -138,17 +150,10 @@ func CheckAutoLogin(ctx *context.Context) bool {
|
|||||||
redirectTo := ctx.FormString("redirect_to")
|
redirectTo := ctx.FormString("redirect_to")
|
||||||
if len(redirectTo) > 0 {
|
if len(redirectTo) > 0 {
|
||||||
middleware.SetRedirectToCookie(ctx.Resp, redirectTo)
|
middleware.SetRedirectToCookie(ctx.Resp, redirectTo)
|
||||||
} else {
|
|
||||||
redirectTo = ctx.GetSiteCookie("redirect_to")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if isSucceed {
|
if isSucceed {
|
||||||
middleware.DeleteRedirectToCookie(ctx.Resp)
|
RedirectAfterLogin(ctx)
|
||||||
nextRedirectTo := setting.AppSubURL + string(setting.LandingPageURL)
|
|
||||||
if setting.LandingPageURL == setting.LandingPageLogin {
|
|
||||||
nextRedirectTo = setting.AppSubURL + "/" // do not cycle-redirect to the login page
|
|
||||||
}
|
|
||||||
ctx.RedirectToFirst(redirectTo, nextRedirectTo)
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,6 +168,11 @@ func SignIn(ctx *context.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ctx.IsSigned {
|
||||||
|
RedirectAfterLogin(ctx)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
oauth2Providers, err := oauth2.GetOAuth2Providers(ctx, optional.Some(true))
|
oauth2Providers, err := oauth2.GetOAuth2Providers(ctx, optional.Some(true))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("UserSignIn", err)
|
ctx.ServerError("UserSignIn", err)
|
||||||
|
43
routers/web/auth/auth_test.go
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
// Copyright 2024 The Gitea Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
package auth
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"code.gitea.io/gitea/modules/test"
|
||||||
|
"code.gitea.io/gitea/services/contexttest"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestUserLogin(t *testing.T) {
|
||||||
|
ctx, resp := contexttest.MockContext(t, "/user/login")
|
||||||
|
SignIn(ctx)
|
||||||
|
assert.Equal(t, http.StatusOK, resp.Code)
|
||||||
|
|
||||||
|
ctx, resp = contexttest.MockContext(t, "/user/login")
|
||||||
|
ctx.IsSigned = true
|
||||||
|
SignIn(ctx)
|
||||||
|
assert.Equal(t, http.StatusSeeOther, resp.Code)
|
||||||
|
assert.Equal(t, "/", test.RedirectURL(resp))
|
||||||
|
|
||||||
|
ctx, resp = contexttest.MockContext(t, "/user/login?redirect_to=/other")
|
||||||
|
ctx.IsSigned = true
|
||||||
|
SignIn(ctx)
|
||||||
|
assert.Equal(t, "/other", test.RedirectURL(resp))
|
||||||
|
|
||||||
|
ctx, resp = contexttest.MockContext(t, "/user/login")
|
||||||
|
ctx.Req.AddCookie(&http.Cookie{Name: "redirect_to", Value: "/other-cookie"})
|
||||||
|
ctx.IsSigned = true
|
||||||
|
SignIn(ctx)
|
||||||
|
assert.Equal(t, "/other-cookie", test.RedirectURL(resp))
|
||||||
|
|
||||||
|
ctx, resp = contexttest.MockContext(t, "/user/login?redirect_to="+url.QueryEscape("https://example.com"))
|
||||||
|
ctx.IsSigned = true
|
||||||
|
SignIn(ctx)
|
||||||
|
assert.Equal(t, "/", test.RedirectURL(resp))
|
||||||
|
}
|
@ -1224,6 +1224,14 @@ func NewIssuePost(ctx *context.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if projectID > 0 {
|
||||||
|
if !ctx.Repo.CanRead(unit.TypeProjects) {
|
||||||
|
// User must also be able to see the project.
|
||||||
|
ctx.Error(http.StatusBadRequest, "user hasn't permissions to read projects")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if setting.Attachment.Enabled {
|
if setting.Attachment.Enabled {
|
||||||
attachments = form.Files
|
attachments = form.Files
|
||||||
}
|
}
|
||||||
@ -1256,7 +1264,7 @@ func NewIssuePost(ctx *context.Context) {
|
|||||||
Ref: form.Ref,
|
Ref: form.Ref,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := issue_service.NewIssue(ctx, repo, issue, labelIDs, attachments, assigneeIDs); err != nil {
|
if err := issue_service.NewIssue(ctx, repo, issue, labelIDs, attachments, assigneeIDs, projectID); err != nil {
|
||||||
if repo_model.IsErrUserDoesNotHaveAccessToRepo(err) {
|
if repo_model.IsErrUserDoesNotHaveAccessToRepo(err) {
|
||||||
ctx.Error(http.StatusBadRequest, "UserDoesNotHaveAccessToRepo", err.Error())
|
ctx.Error(http.StatusBadRequest, "UserDoesNotHaveAccessToRepo", err.Error())
|
||||||
} else if errors.Is(err, user_model.ErrBlockedUser) {
|
} else if errors.Is(err, user_model.ErrBlockedUser) {
|
||||||
@ -1267,18 +1275,6 @@ func NewIssuePost(ctx *context.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if projectID > 0 {
|
|
||||||
if !ctx.Repo.CanRead(unit.TypeProjects) {
|
|
||||||
// User must also be able to see the project.
|
|
||||||
ctx.Error(http.StatusBadRequest, "user hasn't permissions to read projects")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if err := issues_model.ChangeProjectAssign(ctx, issue, ctx.Doer, projectID); err != nil {
|
|
||||||
ctx.ServerError("ChangeProjectAssign", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Trace("Issue created: %d/%d", repo.ID, issue.ID)
|
log.Trace("Issue created: %d/%d", repo.ID, issue.ID)
|
||||||
if ctx.FormString("redirect_after_creation") == "project" && projectID > 0 {
|
if ctx.FormString("redirect_after_creation") == "project" && projectID > 0 {
|
||||||
ctx.JSONRedirect(ctx.Repo.RepoLink + "/projects/" + strconv.FormatInt(projectID, 10))
|
ctx.JSONRedirect(ctx.Repo.RepoLink + "/projects/" + strconv.FormatInt(projectID, 10))
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
|
|
||||||
issues_model "code.gitea.io/gitea/models/issues"
|
issues_model "code.gitea.io/gitea/models/issues"
|
||||||
pull_model "code.gitea.io/gitea/models/pull"
|
pull_model "code.gitea.io/gitea/models/pull"
|
||||||
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
"code.gitea.io/gitea/modules/base"
|
"code.gitea.io/gitea/modules/base"
|
||||||
"code.gitea.io/gitea/modules/json"
|
"code.gitea.io/gitea/modules/json"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
@ -19,6 +20,7 @@ import (
|
|||||||
"code.gitea.io/gitea/services/context/upload"
|
"code.gitea.io/gitea/services/context/upload"
|
||||||
"code.gitea.io/gitea/services/forms"
|
"code.gitea.io/gitea/services/forms"
|
||||||
pull_service "code.gitea.io/gitea/services/pull"
|
pull_service "code.gitea.io/gitea/services/pull"
|
||||||
|
user_service "code.gitea.io/gitea/services/user"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -203,6 +205,10 @@ func renderConversation(ctx *context.Context, comment *issues_model.Comment, ori
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Data["AfterCommitID"] = pullHeadCommitID
|
ctx.Data["AfterCommitID"] = pullHeadCommitID
|
||||||
|
ctx.Data["CanBlockUser"] = func(blocker, blockee *user_model.User) bool {
|
||||||
|
return user_service.CanBlockUser(ctx, ctx.Doer, blocker, blockee)
|
||||||
|
}
|
||||||
|
|
||||||
if origin == "diff" {
|
if origin == "diff" {
|
||||||
ctx.HTML(http.StatusOK, tplDiffConversation)
|
ctx.HTML(http.StatusOK, tplDiffConversation)
|
||||||
} else if origin == "timeline" {
|
} else if origin == "timeline" {
|
||||||
|
@ -35,6 +35,7 @@ import (
|
|||||||
"code.gitea.io/gitea/services/forms"
|
"code.gitea.io/gitea/services/forms"
|
||||||
repo_service "code.gitea.io/gitea/services/repository"
|
repo_service "code.gitea.io/gitea/services/repository"
|
||||||
archiver_service "code.gitea.io/gitea/services/repository/archiver"
|
archiver_service "code.gitea.io/gitea/services/repository/archiver"
|
||||||
|
commitstatus_service "code.gitea.io/gitea/services/repository/commitstatus"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -634,30 +635,14 @@ func SearchRepo(ctx *context.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// collect the latest commit of each repo
|
latestCommitStatuses, err := commitstatus_service.FindReposLastestCommitStatuses(ctx, repos)
|
||||||
// at most there are dozens of repos (limited by MaxResponseItems), so it's not a big problem at the moment
|
|
||||||
repoBranchNames := make(map[int64]string, len(repos))
|
|
||||||
for _, repo := range repos {
|
|
||||||
repoBranchNames[repo.ID] = repo.DefaultBranch
|
|
||||||
}
|
|
||||||
|
|
||||||
repoIDsToLatestCommitSHAs, err := git_model.FindBranchesByRepoAndBranchName(ctx, repoBranchNames)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("FindBranchesByRepoAndBranchName: %v", err)
|
log.Error("FindReposLastestCommitStatuses: %v", err)
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// call the database O(1) times to get the commit statuses for all repos
|
|
||||||
repoToItsLatestCommitStatuses, err := git_model.GetLatestCommitStatusForPairs(ctx, repoIDsToLatestCommitSHAs, db.ListOptionsAll)
|
|
||||||
if err != nil {
|
|
||||||
log.Error("GetLatestCommitStatusForPairs: %v", err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
results := make([]*repo_service.WebSearchRepository, len(repos))
|
results := make([]*repo_service.WebSearchRepository, len(repos))
|
||||||
for i, repo := range repos {
|
for i, repo := range repos {
|
||||||
latestCommitStatus := git_model.CalcCommitStatus(repoToItsLatestCommitStatuses[repo.ID])
|
|
||||||
|
|
||||||
results[i] = &repo_service.WebSearchRepository{
|
results[i] = &repo_service.WebSearchRepository{
|
||||||
Repository: &api.Repository{
|
Repository: &api.Repository{
|
||||||
ID: repo.ID,
|
ID: repo.ID,
|
||||||
@ -671,8 +656,11 @@ func SearchRepo(ctx *context.Context) {
|
|||||||
Link: repo.Link(),
|
Link: repo.Link(),
|
||||||
Internal: !repo.IsPrivate && repo.Owner.Visibility == api.VisibleTypePrivate,
|
Internal: !repo.IsPrivate && repo.Owner.Visibility == api.VisibleTypePrivate,
|
||||||
},
|
},
|
||||||
LatestCommitStatus: latestCommitStatus,
|
}
|
||||||
LocaleLatestCommitStatus: latestCommitStatus.LocaleString(ctx.Locale),
|
|
||||||
|
if latestCommitStatuses[i] != nil {
|
||||||
|
results[i].LatestCommitStatus = latestCommitStatuses[i]
|
||||||
|
results[i].LocaleLatestCommitStatus = latestCommitStatuses[i].LocaleString(ctx.Locale)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -488,6 +488,13 @@ func SettingsPost(ctx *context.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if form.DefaultWikiBranch != "" {
|
||||||
|
if err := wiki_service.ChangeDefaultWikiBranch(ctx, repo, form.DefaultWikiBranch); err != nil {
|
||||||
|
log.Error("ChangeDefaultWikiBranch failed, err: %v", err)
|
||||||
|
ctx.Flash.Warning(ctx.Tr("repo.settings.failed_to_change_default_wiki_branch"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if form.EnableIssues && form.EnableExternalTracker && !unit_model.TypeExternalTracker.UnitGlobalDisabled() {
|
if form.EnableIssues && form.EnableExternalTracker && !unit_model.TypeExternalTracker.UnitGlobalDisabled() {
|
||||||
if !validation.IsValidExternalURL(form.ExternalTrackerURL) {
|
if !validation.IsValidExternalURL(form.ExternalTrackerURL) {
|
||||||
ctx.Flash.Error(ctx.Tr("repo.settings.external_tracker_url_error"))
|
ctx.Flash.Error(ctx.Tr("repo.settings.external_tracker_url_error"))
|
||||||
|
@ -919,7 +919,7 @@ func prepareOpenWithEditorApps(ctx *context.Context) {
|
|||||||
schema, _, _ := strings.Cut(app.OpenURL, ":")
|
schema, _, _ := strings.Cut(app.OpenURL, ":")
|
||||||
var iconHTML template.HTML
|
var iconHTML template.HTML
|
||||||
if schema == "vscode" || schema == "vscodium" || schema == "jetbrains" {
|
if schema == "vscode" || schema == "vscodium" || schema == "jetbrains" {
|
||||||
iconHTML = svg.RenderHTML(fmt.Sprintf("gitea-open-with-%s", schema), 16, "gt-mr-3")
|
iconHTML = svg.RenderHTML(fmt.Sprintf("gitea-%s", schema), 16, "gt-mr-3")
|
||||||
} else {
|
} else {
|
||||||
iconHTML = svg.RenderHTML("gitea-git", 16, "gt-mr-3") // TODO: it could support user's customized icon in the future
|
iconHTML = svg.RenderHTML("gitea-git", 16, "gt-mr-3") // TODO: it could support user's customized icon in the future
|
||||||
}
|
}
|
||||||
@ -998,6 +998,8 @@ func renderHomeCode(ctx *context.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkOutdatedBranch(ctx)
|
||||||
|
|
||||||
checkCitationFile(ctx, entry)
|
checkCitationFile(ctx, entry)
|
||||||
if ctx.Written() {
|
if ctx.Written() {
|
||||||
return
|
return
|
||||||
@ -1064,6 +1066,31 @@ func renderHomeCode(ctx *context.Context) {
|
|||||||
ctx.HTML(http.StatusOK, tplRepoHome)
|
ctx.HTML(http.StatusOK, tplRepoHome)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func checkOutdatedBranch(ctx *context.Context) {
|
||||||
|
if !(ctx.Repo.IsAdmin() || ctx.Repo.IsOwner()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the head commit of the branch since ctx.Repo.CommitID is not always the head commit of `ctx.Repo.BranchName`
|
||||||
|
commit, err := ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.BranchName)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("GetBranchCommitID: %v", err)
|
||||||
|
// Don't return an error page, as it can be rechecked the next time the user opens the page.
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
dbBranch, err := git_model.GetBranch(ctx, ctx.Repo.Repository.ID, ctx.Repo.BranchName)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("GetBranch: %v", err)
|
||||||
|
// Don't return an error page, as it can be rechecked the next time the user opens the page.
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if dbBranch.CommitID != commit.ID.String() {
|
||||||
|
ctx.Flash.Warning(ctx.Tr("repo.error.broken_git_hook", "https://docs.gitea.com/help/faq#push-hook--webhook--actions-arent-running"), true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// RenderUserCards render a page show users according the input template
|
// RenderUserCards render a page show users according the input template
|
||||||
func RenderUserCards(ctx *context.Context, total int, getter func(opts db.ListOptions) ([]*user_model.User, error), tpl base.TplName) {
|
func RenderUserCards(ctx *context.Context, total int, getter func(opts db.ListOptions) ([]*user_model.User, error), tpl base.TplName) {
|
||||||
page := ctx.FormInt("page")
|
page := ctx.FormInt("page")
|
||||||
|
@ -93,17 +93,32 @@ func findEntryForFile(commit *git.Commit, target string) (*git.TreeEntry, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func findWikiRepoCommit(ctx *context.Context) (*git.Repository, *git.Commit, error) {
|
func findWikiRepoCommit(ctx *context.Context) (*git.Repository, *git.Commit, error) {
|
||||||
wikiRepo, err := gitrepo.OpenWikiRepository(ctx, ctx.Repo.Repository)
|
wikiGitRepo, errGitRepo := gitrepo.OpenWikiRepository(ctx, ctx.Repo.Repository)
|
||||||
if err != nil {
|
if errGitRepo != nil {
|
||||||
ctx.ServerError("OpenRepository", err)
|
ctx.ServerError("OpenRepository", errGitRepo)
|
||||||
return nil, nil, err
|
return nil, nil, errGitRepo
|
||||||
}
|
}
|
||||||
|
|
||||||
commit, err := wikiRepo.GetBranchCommit(wiki_service.DefaultBranch)
|
commit, errCommit := wikiGitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultWikiBranch)
|
||||||
if err != nil {
|
if git.IsErrNotExist(errCommit) {
|
||||||
return wikiRepo, nil, err
|
// if the default branch recorded in database is out of sync, then re-sync it
|
||||||
|
gitRepoDefaultBranch, errBranch := wikiGitRepo.GetDefaultBranch()
|
||||||
|
if errBranch != nil {
|
||||||
|
return wikiGitRepo, nil, errBranch
|
||||||
|
}
|
||||||
|
// update the default branch in the database
|
||||||
|
errDb := repo_model.UpdateRepositoryCols(ctx, &repo_model.Repository{ID: ctx.Repo.Repository.ID, DefaultWikiBranch: gitRepoDefaultBranch}, "default_wiki_branch")
|
||||||
|
if errDb != nil {
|
||||||
|
return wikiGitRepo, nil, errDb
|
||||||
|
}
|
||||||
|
ctx.Repo.Repository.DefaultWikiBranch = gitRepoDefaultBranch
|
||||||
|
// retry to get the commit from the correct default branch
|
||||||
|
commit, errCommit = wikiGitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultWikiBranch)
|
||||||
}
|
}
|
||||||
return wikiRepo, commit, nil
|
if errCommit != nil {
|
||||||
|
return wikiGitRepo, nil, errCommit
|
||||||
|
}
|
||||||
|
return wikiGitRepo, commit, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// wikiContentsByEntry returns the contents of the wiki page referenced by the
|
// wikiContentsByEntry returns the contents of the wiki page referenced by the
|
||||||
@ -316,7 +331,7 @@ func renderViewPage(ctx *context.Context) (*git.Repository, *git.TreeEntry) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get commit count - wiki revisions
|
// get commit count - wiki revisions
|
||||||
commitsCount, _ := wikiRepo.FileCommitsCount(wiki_service.DefaultBranch, pageFilename)
|
commitsCount, _ := wikiRepo.FileCommitsCount(ctx.Repo.Repository.DefaultWikiBranch, pageFilename)
|
||||||
ctx.Data["CommitCount"] = commitsCount
|
ctx.Data["CommitCount"] = commitsCount
|
||||||
|
|
||||||
return wikiRepo, entry
|
return wikiRepo, entry
|
||||||
@ -368,7 +383,7 @@ func renderRevisionPage(ctx *context.Context) (*git.Repository, *git.TreeEntry)
|
|||||||
ctx.Data["footerContent"] = ""
|
ctx.Data["footerContent"] = ""
|
||||||
|
|
||||||
// get commit count - wiki revisions
|
// get commit count - wiki revisions
|
||||||
commitsCount, _ := wikiRepo.FileCommitsCount(wiki_service.DefaultBranch, pageFilename)
|
commitsCount, _ := wikiRepo.FileCommitsCount(ctx.Repo.Repository.DefaultWikiBranch, pageFilename)
|
||||||
ctx.Data["CommitCount"] = commitsCount
|
ctx.Data["CommitCount"] = commitsCount
|
||||||
|
|
||||||
// get page
|
// get page
|
||||||
@ -380,7 +395,7 @@ func renderRevisionPage(ctx *context.Context) (*git.Repository, *git.TreeEntry)
|
|||||||
// get Commit Count
|
// get Commit Count
|
||||||
commitsHistory, err := wikiRepo.CommitsByFileAndRange(
|
commitsHistory, err := wikiRepo.CommitsByFileAndRange(
|
||||||
git.CommitsByFileAndRangeOptions{
|
git.CommitsByFileAndRangeOptions{
|
||||||
Revision: wiki_service.DefaultBranch,
|
Revision: ctx.Repo.Repository.DefaultWikiBranch,
|
||||||
File: pageFilename,
|
File: pageFilename,
|
||||||
Page: page,
|
Page: page,
|
||||||
})
|
})
|
||||||
@ -402,20 +417,17 @@ func renderRevisionPage(ctx *context.Context) (*git.Repository, *git.TreeEntry)
|
|||||||
|
|
||||||
func renderEditPage(ctx *context.Context) {
|
func renderEditPage(ctx *context.Context) {
|
||||||
wikiRepo, commit, err := findWikiRepoCommit(ctx)
|
wikiRepo, commit, err := findWikiRepoCommit(ctx)
|
||||||
if err != nil {
|
defer func() {
|
||||||
if wikiRepo != nil {
|
if wikiRepo != nil {
|
||||||
wikiRepo.Close()
|
_ = wikiRepo.Close()
|
||||||
}
|
}
|
||||||
|
}()
|
||||||
|
if err != nil {
|
||||||
if !git.IsErrNotExist(err) {
|
if !git.IsErrNotExist(err) {
|
||||||
ctx.ServerError("GetBranchCommit", err)
|
ctx.ServerError("GetBranchCommit", err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer func() {
|
|
||||||
if wikiRepo != nil {
|
|
||||||
wikiRepo.Close()
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// get requested pagename
|
// get requested pagename
|
||||||
pageName := wiki_service.WebPathFromRequest(ctx.PathParamRaw("*"))
|
pageName := wiki_service.WebPathFromRequest(ctx.PathParamRaw("*"))
|
||||||
@ -584,17 +596,15 @@ func WikiPages(ctx *context.Context) {
|
|||||||
ctx.Data["CanWriteWiki"] = ctx.Repo.CanWrite(unit.TypeWiki) && !ctx.Repo.Repository.IsArchived
|
ctx.Data["CanWriteWiki"] = ctx.Repo.CanWrite(unit.TypeWiki) && !ctx.Repo.Repository.IsArchived
|
||||||
|
|
||||||
wikiRepo, commit, err := findWikiRepoCommit(ctx)
|
wikiRepo, commit, err := findWikiRepoCommit(ctx)
|
||||||
if err != nil {
|
|
||||||
if wikiRepo != nil {
|
|
||||||
wikiRepo.Close()
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if wikiRepo != nil {
|
if wikiRepo != nil {
|
||||||
wikiRepo.Close()
|
_ = wikiRepo.Close()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
if err != nil {
|
||||||
|
ctx.Redirect(ctx.Repo.RepoLink + "/wiki")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
entries, err := commit.ListEntries()
|
entries, err := commit.ListEntries()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"code.gitea.io/gitea/models/db"
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
"code.gitea.io/gitea/models/unittest"
|
"code.gitea.io/gitea/models/unittest"
|
||||||
"code.gitea.io/gitea/modules/git"
|
"code.gitea.io/gitea/modules/git"
|
||||||
@ -79,7 +80,7 @@ func assertPagesMetas(t *testing.T, expectedNames []string, metas any) {
|
|||||||
func TestWiki(t *testing.T) {
|
func TestWiki(t *testing.T) {
|
||||||
unittest.PrepareTestEnv(t)
|
unittest.PrepareTestEnv(t)
|
||||||
|
|
||||||
ctx, _ := contexttest.MockContext(t, "user2/repo1/wiki/?action=_pages")
|
ctx, _ := contexttest.MockContext(t, "user2/repo1/wiki")
|
||||||
ctx.SetParams("*", "Home")
|
ctx.SetParams("*", "Home")
|
||||||
contexttest.LoadRepo(t, ctx, 1)
|
contexttest.LoadRepo(t, ctx, 1)
|
||||||
Wiki(ctx)
|
Wiki(ctx)
|
||||||
@ -221,3 +222,32 @@ func TestWikiRaw(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDefaultWikiBranch(t *testing.T) {
|
||||||
|
unittest.PrepareTestEnv(t)
|
||||||
|
|
||||||
|
assert.NoError(t, repo_model.UpdateRepositoryCols(db.DefaultContext, &repo_model.Repository{ID: 1, DefaultWikiBranch: "wrong-branch"}))
|
||||||
|
|
||||||
|
ctx, _ := contexttest.MockContext(t, "user2/repo1/wiki")
|
||||||
|
ctx.SetParams("*", "Home")
|
||||||
|
contexttest.LoadRepo(t, ctx, 1)
|
||||||
|
assert.Equal(t, "wrong-branch", ctx.Repo.Repository.DefaultWikiBranch)
|
||||||
|
Wiki(ctx) // after the visiting, the out-of-sync database record will update the branch name to "master"
|
||||||
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||||
|
assert.Equal(t, "master", ctx.Repo.Repository.DefaultWikiBranch)
|
||||||
|
|
||||||
|
// invalid branch name should fail
|
||||||
|
assert.Error(t, wiki_service.ChangeDefaultWikiBranch(db.DefaultContext, repo, "the bad name"))
|
||||||
|
repo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||||
|
assert.Equal(t, "master", repo.DefaultWikiBranch)
|
||||||
|
|
||||||
|
// the same branch name, should succeed (actually a no-op)
|
||||||
|
assert.NoError(t, wiki_service.ChangeDefaultWikiBranch(db.DefaultContext, repo, "master"))
|
||||||
|
repo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||||
|
assert.Equal(t, "master", repo.DefaultWikiBranch)
|
||||||
|
|
||||||
|
// change to another name
|
||||||
|
assert.NoError(t, wiki_service.ChangeDefaultWikiBranch(db.DefaultContext, repo, "main"))
|
||||||
|
repo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||||
|
assert.Equal(t, "main", repo.DefaultWikiBranch)
|
||||||
|
}
|
||||||
|
@ -62,7 +62,7 @@ func KeysPost(ctx *context.Context) {
|
|||||||
ctx.Redirect(setting.AppSubURL + "/user/settings/keys")
|
ctx.Redirect(setting.AppSubURL + "/user/settings/keys")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if _, err = asymkey_model.AddPrincipalKey(ctx, ctx.Doer.ID, content, 0); err != nil {
|
if _, err = asymkey_service.AddPrincipalKey(ctx, ctx.Doer.ID, content, 0); err != nil {
|
||||||
ctx.Data["HasPrincipalError"] = true
|
ctx.Data["HasPrincipalError"] = true
|
||||||
switch {
|
switch {
|
||||||
case asymkey_model.IsErrKeyAlreadyExist(err), asymkey_model.IsErrKeyNameAlreadyUsed(err):
|
case asymkey_model.IsErrKeyAlreadyExist(err), asymkey_model.IsErrKeyNameAlreadyUsed(err):
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"code.gitea.io/gitea/modules/json"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
|
||||||
@ -21,17 +22,41 @@ type actionsClaims struct {
|
|||||||
TaskID int64
|
TaskID int64
|
||||||
RunID int64
|
RunID int64
|
||||||
JobID int64
|
JobID int64
|
||||||
|
Ac string `json:"ac"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type actionsCacheScope struct {
|
||||||
|
Scope string
|
||||||
|
Permission actionsCachePermission
|
||||||
|
}
|
||||||
|
|
||||||
|
type actionsCachePermission int
|
||||||
|
|
||||||
|
const (
|
||||||
|
actionsCachePermissionRead = 1 << iota
|
||||||
|
actionsCachePermissionWrite
|
||||||
|
)
|
||||||
|
|
||||||
func CreateAuthorizationToken(taskID, runID, jobID int64) (string, error) {
|
func CreateAuthorizationToken(taskID, runID, jobID int64) (string, error) {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
|
||||||
|
ac, err := json.Marshal(&[]actionsCacheScope{
|
||||||
|
{
|
||||||
|
Scope: "",
|
||||||
|
Permission: actionsCachePermissionWrite,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
claims := actionsClaims{
|
claims := actionsClaims{
|
||||||
RegisteredClaims: jwt.RegisteredClaims{
|
RegisteredClaims: jwt.RegisteredClaims{
|
||||||
ExpiresAt: jwt.NewNumericDate(now.Add(24 * time.Hour)),
|
ExpiresAt: jwt.NewNumericDate(now.Add(24 * time.Hour)),
|
||||||
NotBefore: jwt.NewNumericDate(now),
|
NotBefore: jwt.NewNumericDate(now),
|
||||||
},
|
},
|
||||||
Scp: fmt.Sprintf("Actions.Results:%d:%d", runID, jobID),
|
Scp: fmt.Sprintf("Actions.Results:%d:%d", runID, jobID),
|
||||||
|
Ac: string(ac),
|
||||||
TaskID: taskID,
|
TaskID: taskID,
|
||||||
RunID: runID,
|
RunID: runID,
|
||||||
JobID: jobID,
|
JobID: jobID,
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"code.gitea.io/gitea/modules/json"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
|
||||||
"github.com/golang-jwt/jwt/v5"
|
"github.com/golang-jwt/jwt/v5"
|
||||||
@ -29,6 +30,14 @@ func TestCreateAuthorizationToken(t *testing.T) {
|
|||||||
taskIDClaim, ok := claims["TaskID"]
|
taskIDClaim, ok := claims["TaskID"]
|
||||||
assert.True(t, ok, "Has TaskID claim in jwt token")
|
assert.True(t, ok, "Has TaskID claim in jwt token")
|
||||||
assert.Equal(t, float64(taskID), taskIDClaim, "Supplied taskid must match stored one")
|
assert.Equal(t, float64(taskID), taskIDClaim, "Supplied taskid must match stored one")
|
||||||
|
acClaim, ok := claims["ac"]
|
||||||
|
assert.True(t, ok, "Has ac claim in jwt token")
|
||||||
|
ac, ok := acClaim.(string)
|
||||||
|
assert.True(t, ok, "ac claim is a string for buildx gha cache")
|
||||||
|
scopes := []actionsCacheScope{}
|
||||||
|
err = json.Unmarshal([]byte(ac), &scopes)
|
||||||
|
assert.NoError(t, err, "ac claim is a json list for buildx gha cache")
|
||||||
|
assert.GreaterOrEqual(t, len(scopes), 1, "Expected at least one action cache scope for buildx gha cache")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseAuthorizationToken(t *testing.T) {
|
func TestParseAuthorizationToken(t *testing.T) {
|
||||||
|
@ -486,6 +486,10 @@ func handleSchedules(
|
|||||||
|
|
||||||
// DetectAndHandleSchedules detects the schedule workflows on the default branch and create schedule tasks
|
// DetectAndHandleSchedules detects the schedule workflows on the default branch and create schedule tasks
|
||||||
func DetectAndHandleSchedules(ctx context.Context, repo *repo_model.Repository) error {
|
func DetectAndHandleSchedules(ctx context.Context, repo *repo_model.Repository) error {
|
||||||
|
if repo.IsEmpty {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
gitRepo, err := gitrepo.OpenRepository(context.Background(), repo)
|
gitRepo, err := gitrepo.OpenRepository(context.Background(), repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("git.OpenRepository: %w", err)
|
return fmt.Errorf("git.OpenRepository: %w", err)
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
issues_model "code.gitea.io/gitea/models/issues"
|
issues_model "code.gitea.io/gitea/models/issues"
|
||||||
@ -21,26 +22,17 @@ import (
|
|||||||
|
|
||||||
// ProcReceive handle proc receive work
|
// ProcReceive handle proc receive work
|
||||||
func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, opts *private.HookOptions) ([]private.HookProcReceiveRefResult, error) {
|
func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, opts *private.HookOptions) ([]private.HookProcReceiveRefResult, error) {
|
||||||
// TODO: Add more options?
|
|
||||||
var (
|
|
||||||
topicBranch string
|
|
||||||
title string
|
|
||||||
description string
|
|
||||||
forcePush bool
|
|
||||||
)
|
|
||||||
|
|
||||||
results := make([]private.HookProcReceiveRefResult, 0, len(opts.OldCommitIDs))
|
results := make([]private.HookProcReceiveRefResult, 0, len(opts.OldCommitIDs))
|
||||||
|
topicBranch := opts.GitPushOptions["topic"]
|
||||||
ownerName := repo.OwnerName
|
forcePush, _ := strconv.ParseBool(opts.GitPushOptions["force-push"])
|
||||||
repoName := repo.Name
|
title := strings.TrimSpace(opts.GitPushOptions["title"])
|
||||||
|
description := strings.TrimSpace(opts.GitPushOptions["description"]) // TODO: Add more options?
|
||||||
topicBranch = opts.GitPushOptions["topic"]
|
|
||||||
_, forcePush = opts.GitPushOptions["force-push"]
|
|
||||||
objectFormat := git.ObjectFormatFromName(repo.ObjectFormatName)
|
objectFormat := git.ObjectFormatFromName(repo.ObjectFormatName)
|
||||||
|
userName := strings.ToLower(opts.UserName)
|
||||||
|
|
||||||
pusher, err := user_model.GetUserByID(ctx, opts.UserID)
|
pusher, err := user_model.GetUserByID(ctx, opts.UserID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Failed to get user. Error: %w", err)
|
return nil, fmt.Errorf("failed to get user. Error: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range opts.OldCommitIDs {
|
for i := range opts.OldCommitIDs {
|
||||||
@ -85,9 +77,6 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
var headBranch string
|
|
||||||
userName := strings.ToLower(opts.UserName)
|
|
||||||
|
|
||||||
if len(curentTopicBranch) == 0 {
|
if len(curentTopicBranch) == 0 {
|
||||||
curentTopicBranch = topicBranch
|
curentTopicBranch = topicBranch
|
||||||
}
|
}
|
||||||
@ -95,6 +84,7 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
|
|||||||
// because different user maybe want to use same topic,
|
// because different user maybe want to use same topic,
|
||||||
// So it's better to make sure the topic branch name
|
// So it's better to make sure the topic branch name
|
||||||
// has user name prefix
|
// has user name prefix
|
||||||
|
var headBranch string
|
||||||
if !strings.HasPrefix(curentTopicBranch, userName+"/") {
|
if !strings.HasPrefix(curentTopicBranch, userName+"/") {
|
||||||
headBranch = userName + "/" + curentTopicBranch
|
headBranch = userName + "/" + curentTopicBranch
|
||||||
} else {
|
} else {
|
||||||
@ -104,21 +94,26 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
|
|||||||
pr, err := issues_model.GetUnmergedPullRequest(ctx, repo.ID, repo.ID, headBranch, baseBranchName, issues_model.PullRequestFlowAGit)
|
pr, err := issues_model.GetUnmergedPullRequest(ctx, repo.ID, repo.ID, headBranch, baseBranchName, issues_model.PullRequestFlowAGit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !issues_model.IsErrPullRequestNotExist(err) {
|
if !issues_model.IsErrPullRequestNotExist(err) {
|
||||||
return nil, fmt.Errorf("Failed to get unmerged agit flow pull request in repository: %s/%s Error: %w", ownerName, repoName, err)
|
return nil, fmt.Errorf("failed to get unmerged agit flow pull request in repository: %s Error: %w", repo.FullName(), err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var commit *git.Commit
|
||||||
|
if title == "" || description == "" {
|
||||||
|
commit, err = gitRepo.GetCommit(opts.NewCommitIDs[i])
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to get commit %s in repository: %s Error: %w", opts.NewCommitIDs[i], repo.FullName(), err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// create a new pull request
|
// create a new pull request
|
||||||
if len(title) == 0 {
|
if title == "" {
|
||||||
var has bool
|
title = strings.Split(commit.CommitMessage, "\n")[0]
|
||||||
title, has = opts.GitPushOptions["title"]
|
}
|
||||||
if !has || len(title) == 0 {
|
if description == "" {
|
||||||
commit, err := gitRepo.GetCommit(opts.NewCommitIDs[i])
|
_, description, _ = strings.Cut(commit.CommitMessage, "\n\n")
|
||||||
if err != nil {
|
}
|
||||||
return nil, fmt.Errorf("Failed to get commit %s in repository: %s/%s Error: %w", opts.NewCommitIDs[i], ownerName, repoName, err)
|
if description == "" {
|
||||||
}
|
description = title
|
||||||
title = strings.Split(commit.CommitMessage, "\n")[0]
|
|
||||||
}
|
|
||||||
description = opts.GitPushOptions["description"]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
prIssue := &issues_model.Issue{
|
prIssue := &issues_model.Issue{
|
||||||
@ -160,12 +155,12 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
|
|||||||
|
|
||||||
// update exist pull request
|
// update exist pull request
|
||||||
if err := pr.LoadBaseRepo(ctx); err != nil {
|
if err := pr.LoadBaseRepo(ctx); err != nil {
|
||||||
return nil, fmt.Errorf("Unable to load base repository for PR[%d] Error: %w", pr.ID, err)
|
return nil, fmt.Errorf("unable to load base repository for PR[%d] Error: %w", pr.ID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
oldCommitID, err := gitRepo.GetRefCommitID(pr.GetGitRefName())
|
oldCommitID, err := gitRepo.GetRefCommitID(pr.GetGitRefName())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Unable to get ref commit id in base repository for PR[%d] Error: %w", pr.ID, err)
|
return nil, fmt.Errorf("unable to get ref commit id in base repository for PR[%d] Error: %w", pr.ID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if oldCommitID == opts.NewCommitIDs[i] {
|
if oldCommitID == opts.NewCommitIDs[i] {
|
||||||
@ -179,9 +174,11 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !forcePush {
|
if !forcePush {
|
||||||
output, _, err := git.NewCommand(ctx, "rev-list", "--max-count=1").AddDynamicArguments(oldCommitID, "^"+opts.NewCommitIDs[i]).RunStdString(&git.RunOpts{Dir: repo.RepoPath(), Env: os.Environ()})
|
output, _, err := git.NewCommand(ctx, "rev-list", "--max-count=1").
|
||||||
|
AddDynamicArguments(oldCommitID, "^"+opts.NewCommitIDs[i]).
|
||||||
|
RunStdString(&git.RunOpts{Dir: repo.RepoPath(), Env: os.Environ()})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Fail to detect force push: %w", err)
|
return nil, fmt.Errorf("failed to detect force push: %w", err)
|
||||||
} else if len(output) > 0 {
|
} else if len(output) > 0 {
|
||||||
results = append(results, private.HookProcReceiveRefResult{
|
results = append(results, private.HookProcReceiveRefResult{
|
||||||
OriginalRef: opts.RefFullNames[i],
|
OriginalRef: opts.RefFullNames[i],
|
||||||
@ -195,17 +192,13 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
|
|||||||
|
|
||||||
pr.HeadCommitID = opts.NewCommitIDs[i]
|
pr.HeadCommitID = opts.NewCommitIDs[i]
|
||||||
if err = pull_service.UpdateRef(ctx, pr); err != nil {
|
if err = pull_service.UpdateRef(ctx, pr); err != nil {
|
||||||
return nil, fmt.Errorf("Failed to update pull ref. Error: %w", err)
|
return nil, fmt.Errorf("failed to update pull ref. Error: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
pull_service.AddToTaskQueue(ctx, pr)
|
pull_service.AddToTaskQueue(ctx, pr)
|
||||||
pusher, err := user_model.GetUserByID(ctx, opts.UserID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("Failed to get user. Error: %w", err)
|
|
||||||
}
|
|
||||||
err = pr.LoadIssue(ctx)
|
err = pr.LoadIssue(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Failed to load pull issue. Error: %w", err)
|
return nil, fmt.Errorf("failed to load pull issue. Error: %w", err)
|
||||||
}
|
}
|
||||||
comment, err := pull_service.CreatePushPullComment(ctx, pusher, pr, oldCommitID, opts.NewCommitIDs[i])
|
comment, err := pull_service.CreatePushPullComment(ctx, pusher, pr, oldCommitID, opts.NewCommitIDs[i])
|
||||||
if err == nil && comment != nil {
|
if err == nil && comment != nil {
|
||||||
|
@ -7,7 +7,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
asymkey_model "code.gitea.io/gitea/models/asymkey"
|
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
)
|
)
|
||||||
@ -27,5 +26,5 @@ func DeleteDeployKey(ctx context.Context, doer *user_model.User, id int64) error
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return asymkey_model.RewriteAllPublicKeys(ctx)
|
return RewriteAllPublicKeys(ctx)
|
||||||
}
|
}
|
||||||
|
@ -43,8 +43,8 @@ func DeletePublicKey(ctx context.Context, doer *user_model.User, id int64) (err
|
|||||||
committer.Close()
|
committer.Close()
|
||||||
|
|
||||||
if key.Type == asymkey_model.KeyTypePrincipal {
|
if key.Type == asymkey_model.KeyTypePrincipal {
|
||||||
return asymkey_model.RewriteAllPrincipalKeys(ctx)
|
return RewriteAllPrincipalKeys(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
return asymkey_model.RewriteAllPublicKeys(ctx)
|
return RewriteAllPublicKeys(ctx)
|
||||||
}
|
}
|
||||||
|
79
services/asymkey/ssh_key_authorized_keys.go
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
// Copyright 2024 The Gitea Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
package asymkey
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
asymkey_model "code.gitea.io/gitea/models/asymkey"
|
||||||
|
"code.gitea.io/gitea/modules/log"
|
||||||
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
"code.gitea.io/gitea/modules/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
// RewriteAllPublicKeys removes any authorized key and rewrite all keys from database again.
|
||||||
|
// Note: db.GetEngine(ctx).Iterate does not get latest data after insert/delete, so we have to call this function
|
||||||
|
// outside any session scope independently.
|
||||||
|
func RewriteAllPublicKeys(ctx context.Context) error {
|
||||||
|
// Don't rewrite key if internal server
|
||||||
|
if setting.SSH.StartBuiltinServer || !setting.SSH.CreateAuthorizedKeysFile {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return asymkey_model.WithSSHOpLocker(func() error {
|
||||||
|
return rewriteAllPublicKeys(ctx)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func rewriteAllPublicKeys(ctx context.Context) error {
|
||||||
|
if setting.SSH.RootPath != "" {
|
||||||
|
// First of ensure that the RootPath is present, and if not make it with 0700 permissions
|
||||||
|
// This of course doesn't guarantee that this is the right directory for authorized_keys
|
||||||
|
// but at least if it's supposed to be this directory and it doesn't exist and we're the
|
||||||
|
// right user it will at least be created properly.
|
||||||
|
err := os.MkdirAll(setting.SSH.RootPath, 0o700)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Unable to MkdirAll(%s): %v", setting.SSH.RootPath, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fPath := filepath.Join(setting.SSH.RootPath, "authorized_keys")
|
||||||
|
tmpPath := fPath + ".tmp"
|
||||||
|
t, err := os.OpenFile(tmpPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o600)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
t.Close()
|
||||||
|
if err := util.Remove(tmpPath); err != nil {
|
||||||
|
log.Warn("Unable to remove temporary authorized keys file: %s: Error: %v", tmpPath, err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
if setting.SSH.AuthorizedKeysBackup {
|
||||||
|
isExist, err := util.IsExist(fPath)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Unable to check if %s exists. Error: %v", fPath, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if isExist {
|
||||||
|
bakPath := fmt.Sprintf("%s_%d.gitea_bak", fPath, time.Now().Unix())
|
||||||
|
if err = util.CopyFile(fPath, bakPath); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := asymkey_model.RegeneratePublicKeys(ctx, t); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Close()
|
||||||
|
return util.Rename(tmpPath, fPath)
|
||||||
|
}
|
@ -13,31 +13,22 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
asymkey_model "code.gitea.io/gitea/models/asymkey"
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
"code.gitea.io/gitea/modules/util"
|
"code.gitea.io/gitea/modules/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
// _____ __ .__ .__ .___
|
|
||||||
// / _ \ __ ___/ |_| |__ ___________|__|_______ ____ __| _/
|
|
||||||
// / /_\ \| | \ __\ | \ / _ \_ __ \ \___ // __ \ / __ |
|
|
||||||
// / | \ | /| | | Y ( <_> ) | \/ |/ /\ ___// /_/ |
|
|
||||||
// \____|__ /____/ |__| |___| /\____/|__| |__/_____ \\___ >____ |
|
|
||||||
// \/ \/ \/ \/ \/
|
|
||||||
// __________ .__ .__ .__
|
|
||||||
// \______ _______|__| ____ ____ |_____________ | | ______
|
|
||||||
// | ___\_ __ | |/ \_/ ___\| \____ \__ \ | | / ___/
|
|
||||||
// | | | | \| | | \ \___| | |_> / __ \| |__\___ \
|
|
||||||
// |____| |__| |__|___| /\___ |__| __(____ |____/____ >
|
|
||||||
// \/ \/ |__| \/ \/
|
|
||||||
//
|
|
||||||
// This file contains functions for creating authorized_principals files
|
// This file contains functions for creating authorized_principals files
|
||||||
//
|
//
|
||||||
// There is a dependence on the database within RewriteAllPrincipalKeys & RegeneratePrincipalKeys
|
// There is a dependence on the database within RewriteAllPrincipalKeys & RegeneratePrincipalKeys
|
||||||
// The sshOpLocker is used from ssh_key_authorized_keys.go
|
// The sshOpLocker is used from ssh_key_authorized_keys.go
|
||||||
|
|
||||||
const authorizedPrincipalsFile = "authorized_principals"
|
const (
|
||||||
|
authorizedPrincipalsFile = "authorized_principals"
|
||||||
|
tplCommentPrefix = `# gitea public key`
|
||||||
|
)
|
||||||
|
|
||||||
// RewriteAllPrincipalKeys removes any authorized principal and rewrite all keys from database again.
|
// RewriteAllPrincipalKeys removes any authorized principal and rewrite all keys from database again.
|
||||||
// Note: db.GetEngine(ctx).Iterate does not get latest data after insert/delete, so we have to call this function
|
// Note: db.GetEngine(ctx).Iterate does not get latest data after insert/delete, so we have to call this function
|
||||||
@ -48,9 +39,12 @@ func RewriteAllPrincipalKeys(ctx context.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
sshOpLocker.Lock()
|
return asymkey_model.WithSSHOpLocker(func() error {
|
||||||
defer sshOpLocker.Unlock()
|
return rewriteAllPrincipalKeys(ctx)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func rewriteAllPrincipalKeys(ctx context.Context) error {
|
||||||
if setting.SSH.RootPath != "" {
|
if setting.SSH.RootPath != "" {
|
||||||
// First of ensure that the RootPath is present, and if not make it with 0700 permissions
|
// First of ensure that the RootPath is present, and if not make it with 0700 permissions
|
||||||
// This of course doesn't guarantee that this is the right directory for authorized_keys
|
// This of course doesn't guarantee that this is the right directory for authorized_keys
|
||||||
@ -97,8 +91,8 @@ func RewriteAllPrincipalKeys(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func regeneratePrincipalKeys(ctx context.Context, t io.StringWriter) error {
|
func regeneratePrincipalKeys(ctx context.Context, t io.StringWriter) error {
|
||||||
if err := db.GetEngine(ctx).Where("type = ?", KeyTypePrincipal).Iterate(new(PublicKey), func(idx int, bean any) (err error) {
|
if err := db.GetEngine(ctx).Where("type = ?", asymkey_model.KeyTypePrincipal).Iterate(new(asymkey_model.PublicKey), func(idx int, bean any) (err error) {
|
||||||
_, err = t.WriteString((bean.(*PublicKey)).AuthorizedString())
|
_, err = t.WriteString((bean.(*asymkey_model.PublicKey)).AuthorizedString())
|
||||||
return err
|
return err
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return err
|
return err
|
54
services/asymkey/ssh_key_principals.go
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
// Copyright 2024 The Gitea Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
package asymkey
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
asymkey_model "code.gitea.io/gitea/models/asymkey"
|
||||||
|
"code.gitea.io/gitea/models/db"
|
||||||
|
"code.gitea.io/gitea/models/perm"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AddPrincipalKey adds new principal to database and authorized_principals file.
|
||||||
|
func AddPrincipalKey(ctx context.Context, ownerID int64, content string, authSourceID int64) (*asymkey_model.PublicKey, error) {
|
||||||
|
dbCtx, committer, err := db.TxContext(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer committer.Close()
|
||||||
|
|
||||||
|
// Principals cannot be duplicated.
|
||||||
|
has, err := db.GetEngine(dbCtx).
|
||||||
|
Where("content = ? AND type = ?", content, asymkey_model.KeyTypePrincipal).
|
||||||
|
Get(new(asymkey_model.PublicKey))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else if has {
|
||||||
|
return nil, asymkey_model.ErrKeyAlreadyExist{
|
||||||
|
Content: content,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
key := &asymkey_model.PublicKey{
|
||||||
|
OwnerID: ownerID,
|
||||||
|
Name: content,
|
||||||
|
Content: content,
|
||||||
|
Mode: perm.AccessModeWrite,
|
||||||
|
Type: asymkey_model.KeyTypePrincipal,
|
||||||
|
LoginSourceID: authSourceID,
|
||||||
|
}
|
||||||
|
if err = db.Insert(dbCtx, key); err != nil {
|
||||||
|
return nil, fmt.Errorf("addKey: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = committer.Commit(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
committer.Close()
|
||||||
|
|
||||||
|
return key, RewriteAllPrincipalKeys(ctx)
|
||||||
|
}
|
@ -13,6 +13,7 @@ import (
|
|||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
auth_module "code.gitea.io/gitea/modules/auth"
|
auth_module "code.gitea.io/gitea/modules/auth"
|
||||||
"code.gitea.io/gitea/modules/optional"
|
"code.gitea.io/gitea/modules/optional"
|
||||||
|
asymkey_service "code.gitea.io/gitea/services/asymkey"
|
||||||
source_service "code.gitea.io/gitea/services/auth/source"
|
source_service "code.gitea.io/gitea/services/auth/source"
|
||||||
user_service "code.gitea.io/gitea/services/user"
|
user_service "code.gitea.io/gitea/services/user"
|
||||||
)
|
)
|
||||||
@ -68,7 +69,7 @@ func (source *Source) Authenticate(ctx context.Context, user *user_model.User, u
|
|||||||
|
|
||||||
if user != nil {
|
if user != nil {
|
||||||
if isAttributeSSHPublicKeySet && asymkey_model.SynchronizePublicKeys(ctx, user, source.authSource, sr.SSHPublicKey) {
|
if isAttributeSSHPublicKeySet && asymkey_model.SynchronizePublicKeys(ctx, user, source.authSource, sr.SSHPublicKey) {
|
||||||
if err := asymkey_model.RewriteAllPublicKeys(ctx); err != nil {
|
if err := asymkey_service.RewriteAllPublicKeys(ctx); err != nil {
|
||||||
return user, err
|
return user, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -94,7 +95,7 @@ func (source *Source) Authenticate(ctx context.Context, user *user_model.User, u
|
|||||||
}
|
}
|
||||||
|
|
||||||
if isAttributeSSHPublicKeySet && asymkey_model.AddPublicKeysBySource(ctx, user, source.authSource, sr.SSHPublicKey) {
|
if isAttributeSSHPublicKeySet && asymkey_model.AddPublicKeysBySource(ctx, user, source.authSource, sr.SSHPublicKey) {
|
||||||
if err := asymkey_model.RewriteAllPublicKeys(ctx); err != nil {
|
if err := asymkey_service.RewriteAllPublicKeys(ctx); err != nil {
|
||||||
return user, err
|
return user, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ import (
|
|||||||
"code.gitea.io/gitea/modules/container"
|
"code.gitea.io/gitea/modules/container"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
"code.gitea.io/gitea/modules/optional"
|
"code.gitea.io/gitea/modules/optional"
|
||||||
|
asymkey_service "code.gitea.io/gitea/services/asymkey"
|
||||||
source_service "code.gitea.io/gitea/services/auth/source"
|
source_service "code.gitea.io/gitea/services/auth/source"
|
||||||
user_service "code.gitea.io/gitea/services/user"
|
user_service "code.gitea.io/gitea/services/user"
|
||||||
)
|
)
|
||||||
@ -77,7 +78,7 @@ func (source *Source) Sync(ctx context.Context, updateExisting bool) error {
|
|||||||
log.Warn("SyncExternalUsers: Cancelled at update of %s before completed update of users", source.authSource.Name)
|
log.Warn("SyncExternalUsers: Cancelled at update of %s before completed update of users", source.authSource.Name)
|
||||||
// Rewrite authorized_keys file if LDAP Public SSH Key attribute is set and any key was added or removed
|
// Rewrite authorized_keys file if LDAP Public SSH Key attribute is set and any key was added or removed
|
||||||
if sshKeysNeedUpdate {
|
if sshKeysNeedUpdate {
|
||||||
err = asymkey_model.RewriteAllPublicKeys(ctx)
|
err = asymkey_service.RewriteAllPublicKeys(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("RewriteAllPublicKeys: %v", err)
|
log.Error("RewriteAllPublicKeys: %v", err)
|
||||||
}
|
}
|
||||||
@ -195,7 +196,7 @@ func (source *Source) Sync(ctx context.Context, updateExisting bool) error {
|
|||||||
|
|
||||||
// Rewrite authorized_keys file if LDAP Public SSH Key attribute is set and any key was added or removed
|
// Rewrite authorized_keys file if LDAP Public SSH Key attribute is set and any key was added or removed
|
||||||
if sshKeysNeedUpdate {
|
if sshKeysNeedUpdate {
|
||||||
err = asymkey_model.RewriteAllPublicKeys(ctx)
|
err = asymkey_service.RewriteAllPublicKeys(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("RewriteAllPublicKeys: %v", err)
|
log.Error("RewriteAllPublicKeys: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -256,7 +256,7 @@ func (b *Base) Redirect(location string, status ...int) {
|
|||||||
code = status[0]
|
code = status[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.Contains(location, "://") || strings.HasPrefix(location, "//") {
|
if strings.HasPrefix(location, "http://") || strings.HasPrefix(location, "https://") || strings.HasPrefix(location, "//") {
|
||||||
// Some browsers (Safari) have buggy behavior for Cookie + Cache + External Redirection, eg: /my-path => https://other/path
|
// Some browsers (Safari) have buggy behavior for Cookie + Cache + External Redirection, eg: /my-path => https://other/path
|
||||||
// 1. the first request to "/my-path" contains cookie
|
// 1. the first request to "/my-path" contains cookie
|
||||||
// 2. some time later, the request to "/my-path" doesn't contain cookie (caused by Prevent web tracking)
|
// 2. some time later, the request to "/my-path" doesn't contain cookie (caused by Prevent web tracking)
|
||||||
|
47
services/context/base_test.go
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
// Copyright 2024 The Gitea Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
package context
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestRedirect(t *testing.T) {
|
||||||
|
req, _ := http.NewRequest("GET", "/", nil)
|
||||||
|
|
||||||
|
cases := []struct {
|
||||||
|
url string
|
||||||
|
keep bool
|
||||||
|
}{
|
||||||
|
{"http://test", false},
|
||||||
|
{"https://test", false},
|
||||||
|
{"//test", false},
|
||||||
|
{"/://test", true},
|
||||||
|
{"/test", true},
|
||||||
|
}
|
||||||
|
for _, c := range cases {
|
||||||
|
resp := httptest.NewRecorder()
|
||||||
|
b, cleanup := NewBaseContext(resp, req)
|
||||||
|
resp.Header().Add("Set-Cookie", (&http.Cookie{Name: setting.SessionConfig.CookieName, Value: "dummy"}).String())
|
||||||
|
b.Redirect(c.url)
|
||||||
|
cleanup()
|
||||||
|
has := resp.Header().Get("Set-Cookie") == "i_like_gitea=dummy"
|
||||||
|
assert.Equal(t, c.keep, has, "url = %q", c.url)
|
||||||
|
}
|
||||||
|
|
||||||
|
req, _ = http.NewRequest("GET", "/", nil)
|
||||||
|
resp := httptest.NewRecorder()
|
||||||
|
req.Header.Add("HX-Request", "true")
|
||||||
|
b, cleanup := NewBaseContext(resp, req)
|
||||||
|
b.Redirect("/other")
|
||||||
|
cleanup()
|
||||||
|
assert.Equal(t, "/other", resp.Header().Get("HX-Redirect"))
|
||||||
|
assert.Equal(t, http.StatusNoContent, resp.Code)
|
||||||
|
}
|
@ -7,6 +7,7 @@ package contexttest
|
|||||||
import (
|
import (
|
||||||
gocontext "context"
|
gocontext "context"
|
||||||
"io"
|
"io"
|
||||||
|
"maps"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"net/url"
|
"net/url"
|
||||||
@ -36,7 +37,7 @@ func mockRequest(t *testing.T, reqPath string) *http.Request {
|
|||||||
}
|
}
|
||||||
requestURL, err := url.Parse(path)
|
requestURL, err := url.Parse(path)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
req := &http.Request{Method: method, URL: requestURL, Form: url.Values{}}
|
req := &http.Request{Method: method, URL: requestURL, Form: maps.Clone(requestURL.Query()), Header: http.Header{}}
|
||||||
req = req.WithContext(middleware.WithContextData(req.Context()))
|
req = req.WithContext(middleware.WithContextData(req.Context()))
|
||||||
return req
|
return req
|
||||||
}
|
}
|
||||||
|
@ -8,13 +8,13 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
activities_model "code.gitea.io/gitea/models/activities"
|
activities_model "code.gitea.io/gitea/models/activities"
|
||||||
asymkey_model "code.gitea.io/gitea/models/asymkey"
|
|
||||||
"code.gitea.io/gitea/models/system"
|
"code.gitea.io/gitea/models/system"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
"code.gitea.io/gitea/modules/git"
|
"code.gitea.io/gitea/modules/git"
|
||||||
issue_indexer "code.gitea.io/gitea/modules/indexer/issues"
|
issue_indexer "code.gitea.io/gitea/modules/indexer/issues"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
"code.gitea.io/gitea/modules/updatechecker"
|
"code.gitea.io/gitea/modules/updatechecker"
|
||||||
|
asymkey_service "code.gitea.io/gitea/services/asymkey"
|
||||||
repo_service "code.gitea.io/gitea/services/repository"
|
repo_service "code.gitea.io/gitea/services/repository"
|
||||||
archiver_service "code.gitea.io/gitea/services/repository/archiver"
|
archiver_service "code.gitea.io/gitea/services/repository/archiver"
|
||||||
user_service "code.gitea.io/gitea/services/user"
|
user_service "code.gitea.io/gitea/services/user"
|
||||||
@ -71,7 +71,7 @@ func registerRewriteAllPublicKeys() {
|
|||||||
RunAtStart: false,
|
RunAtStart: false,
|
||||||
Schedule: "@every 72h",
|
Schedule: "@every 72h",
|
||||||
}, func(ctx context.Context, _ *user_model.User, _ Config) error {
|
}, func(ctx context.Context, _ *user_model.User, _ Config) error {
|
||||||
return asymkey_model.RewriteAllPublicKeys(ctx)
|
return asymkey_service.RewriteAllPublicKeys(ctx)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ func registerRewriteAllPrincipalKeys() {
|
|||||||
RunAtStart: false,
|
RunAtStart: false,
|
||||||
Schedule: "@every 72h",
|
Schedule: "@every 72h",
|
||||||
}, func(ctx context.Context, _ *user_model.User, _ Config) error {
|
}, func(ctx context.Context, _ *user_model.User, _ Config) error {
|
||||||
return asymkey_model.RewriteAllPrincipalKeys(ctx)
|
return asymkey_service.RewriteAllPrincipalKeys(ctx)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ import (
|
|||||||
"code.gitea.io/gitea/modules/container"
|
"code.gitea.io/gitea/modules/container"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
asymkey_service "code.gitea.io/gitea/services/asymkey"
|
||||||
)
|
)
|
||||||
|
|
||||||
const tplCommentPrefix = `# gitea public key`
|
const tplCommentPrefix = `# gitea public key`
|
||||||
@ -33,7 +34,7 @@ func checkAuthorizedKeys(ctx context.Context, logger log.Logger, autofix bool) e
|
|||||||
return fmt.Errorf("Unable to open authorized_keys file. ERROR: %w", err)
|
return fmt.Errorf("Unable to open authorized_keys file. ERROR: %w", err)
|
||||||
}
|
}
|
||||||
logger.Warn("Unable to open authorized_keys. (ERROR: %v). Attempting to rewrite...", err)
|
logger.Warn("Unable to open authorized_keys. (ERROR: %v). Attempting to rewrite...", err)
|
||||||
if err = asymkey_model.RewriteAllPublicKeys(ctx); err != nil {
|
if err = asymkey_service.RewriteAllPublicKeys(ctx); err != nil {
|
||||||
logger.Critical("Unable to rewrite authorized_keys file. ERROR: %v", err)
|
logger.Critical("Unable to rewrite authorized_keys file. ERROR: %v", err)
|
||||||
return fmt.Errorf("Unable to rewrite authorized_keys file. ERROR: %w", err)
|
return fmt.Errorf("Unable to rewrite authorized_keys file. ERROR: %w", err)
|
||||||
}
|
}
|
||||||
@ -76,7 +77,7 @@ func checkAuthorizedKeys(ctx context.Context, logger log.Logger, autofix bool) e
|
|||||||
return fmt.Errorf(`authorized_keys is out of date and should be regenerated with "gitea admin regenerate keys" or "gitea doctor --run authorized-keys --fix"`)
|
return fmt.Errorf(`authorized_keys is out of date and should be regenerated with "gitea admin regenerate keys" or "gitea doctor --run authorized-keys --fix"`)
|
||||||
}
|
}
|
||||||
logger.Warn("authorized_keys is out of date. Attempting rewrite...")
|
logger.Warn("authorized_keys is out of date. Attempting rewrite...")
|
||||||
err = asymkey_model.RewriteAllPublicKeys(ctx)
|
err = asymkey_service.RewriteAllPublicKeys(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Critical("Unable to rewrite authorized_keys file. ERROR: %v", err)
|
logger.Critical("Unable to rewrite authorized_keys file. ERROR: %v", err)
|
||||||
return fmt.Errorf("Unable to rewrite authorized_keys file. ERROR: %w", err)
|
return fmt.Errorf("Unable to rewrite authorized_keys file. ERROR: %w", err)
|
||||||
|
@ -133,6 +133,7 @@ type RepoSettingForm struct {
|
|||||||
EnableCode bool
|
EnableCode bool
|
||||||
EnableWiki bool
|
EnableWiki bool
|
||||||
EnableExternalWiki bool
|
EnableExternalWiki bool
|
||||||
|
DefaultWikiBranch string
|
||||||
ExternalWikiURL string
|
ExternalWikiURL string
|
||||||
EnableIssues bool
|
EnableIssues bool
|
||||||
EnableExternalTracker bool
|
EnableExternalTracker bool
|
||||||
|