Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
* upstream/main:
  Fix input.value attr for RequiredClaimName/Value (go-gitea#20946)
  Move some files into models' sub packages (go-gitea#20262)
  [skip ci] Updated translations via Crowdin
  docs[zh-cn]: Install on Kubernetes (go-gitea#20874)
  Return 404 NotFound if requested attachment does not exist (go-gitea#20886)
  Avoid frequent string2bytes conversions (go-gitea#20940)
  • Loading branch information
zjjhot committed Aug 25, 2022
2 parents f0e7544 + a2db810 commit 64da426
Show file tree
Hide file tree
Showing 158 changed files with 1,874 additions and 1,746 deletions.
35 changes: 17 additions & 18 deletions cmd/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ import (
"strings"
"text/tabwriter"

"code.gitea.io/gitea/models"
asymkey_model "code.gitea.io/gitea/models/asymkey"
"code.gitea.io/gitea/models/auth"
auth_model "code.gitea.io/gitea/models/auth"
"code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
Expand Down Expand Up @@ -593,12 +592,12 @@ func runCreateUser(c *cli.Context) error {
}

if c.Bool("access-token") {
t := &models.AccessToken{
t := &auth_model.AccessToken{
Name: "gitea-admin",
UID: u.ID,
}

if err := models.NewAccessToken(t); err != nil {
if err := auth_model.NewAccessToken(t); err != nil {
return err
}

Expand Down Expand Up @@ -700,12 +699,12 @@ func runGenerateAccessToken(c *cli.Context) error {
return err
}

t := &models.AccessToken{
t := &auth_model.AccessToken{
Name: c.String("token-name"),
UID: user.ID,
}

if err := models.NewAccessToken(t); err != nil {
if err := auth_model.NewAccessToken(t); err != nil {
return err
}

Expand Down Expand Up @@ -779,9 +778,9 @@ func runRepoSyncReleases(_ *cli.Context) error {
}

func getReleaseCount(id int64) (int64, error) {
return models.GetReleaseCountByRepoID(
return repo_model.GetReleaseCountByRepoID(
id,
models.FindReleasesOptions{
repo_model.FindReleasesOptions{
IncludeTags: true,
},
)
Expand Down Expand Up @@ -844,8 +843,8 @@ func runAddOauth(c *cli.Context) error {
return err
}

return auth.CreateSource(&auth.Source{
Type: auth.OAuth2,
return auth_model.CreateSource(&auth_model.Source{
Type: auth_model.OAuth2,
Name: c.String("name"),
IsActive: true,
Cfg: parseOAuth2Config(c),
Expand All @@ -864,7 +863,7 @@ func runUpdateOauth(c *cli.Context) error {
return err
}

source, err := auth.GetSourceByID(c.Int64("id"))
source, err := auth_model.GetSourceByID(c.Int64("id"))
if err != nil {
return err
}
Expand Down Expand Up @@ -944,7 +943,7 @@ func runUpdateOauth(c *cli.Context) error {
oAuth2Config.CustomURLMapping = customURLMapping
source.Cfg = oAuth2Config

return auth.UpdateSource(source)
return auth_model.UpdateSource(source)
}

func parseSMTPConfig(c *cli.Context, conf *smtp.Source) error {
Expand Down Expand Up @@ -1015,8 +1014,8 @@ func runAddSMTP(c *cli.Context) error {
smtpConfig.Auth = "PLAIN"
}

return auth.CreateSource(&auth.Source{
Type: auth.SMTP,
return auth_model.CreateSource(&auth_model.Source{
Type: auth_model.SMTP,
Name: c.String("name"),
IsActive: active,
Cfg: &smtpConfig,
Expand All @@ -1035,7 +1034,7 @@ func runUpdateSMTP(c *cli.Context) error {
return err
}

source, err := auth.GetSourceByID(c.Int64("id"))
source, err := auth_model.GetSourceByID(c.Int64("id"))
if err != nil {
return err
}
Expand All @@ -1056,7 +1055,7 @@ func runUpdateSMTP(c *cli.Context) error {

source.Cfg = smtpConfig

return auth.UpdateSource(source)
return auth_model.UpdateSource(source)
}

func runListAuth(c *cli.Context) error {
Expand All @@ -1067,7 +1066,7 @@ func runListAuth(c *cli.Context) error {
return err
}

authSources, err := auth.Sources()
authSources, err := auth_model.Sources()
if err != nil {
return err
}
Expand Down Expand Up @@ -1105,7 +1104,7 @@ func runDeleteAuth(c *cli.Context) error {
return err
}

source, err := auth.GetSourceByID(c.Int64("id"))
source, err := auth_model.GetSourceByID(c.Int64("id"))
if err != nil {
return err
}
Expand Down
82 changes: 82 additions & 0 deletions docs/content/doc/installation/on-kubernetes.zh-cn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
---
date: "2020-03-19T19:27:00+02:00"
title: "在 Kubernetes 安装 Gitea"
slug: "install-on-kubernetes"
weight: 10
toc: false
draft: false
menu:
sidebar:
parent: "installation"
name: "Kubernetes"
weight: 50
identifier: "install-on-kubernetes"
---

# 使用 Helm 在 Kubernetes 云原生环境中安装 Gitea

Gitea 已经提供了便于在 Kubernetes 云原生环境中安装所需的 Helm Chart

默认安装指令为:

```bash
helm repo add gitea https://dl.gitea.io/charts
helm repo update
helm install gitea gitea/gitea
```

如果采用默认安装指令,Helm 会部署单实例的 Gitea, PostgreSQL, Memcached。若您想实现自定义安装(包括配置 Gitea 集群、NGINX Ingress、MySQL、MariaDB、持久存储等),请前往阅读:[Gitea Helm Chart](https://gitea.com/gitea/helm-chart/)

您也可以通过 `helm show` 命令导出 `README.md` 和配置文件 `values.yaml` 进行学习和编辑,例如:

```bash
helm show values gitea > values.yaml
helm show readme gitea > README.md

# 使用自定义的配置文件 values.yaml
helm install gitea -f values.yaml gitea/gitea
```

## 运行状况检查接口

Gitea 附带了一个运行状况检查接口 `/api/healthz`,你可以像这样在 Kubernetes 中配置它:

```yaml
livenessProbe:
httpGet:
path: /api/healthz
port: http
initialDelaySeconds: 200
timeoutSeconds: 5
periodSeconds: 10
successThreshold: 1
failureThreshold: 10
```
成功的运行状况检查响应代码为 HTTP `200`,下面是示例:

```
HTTP/1.1 200 OK


{
"status": "pass",
"description": "Gitea: Git with a cup of tea",
"checks": {
"cache:ping": [
{
"status": "pass",
"time": "2022-02-19T09:16:08Z"
}
],
"database:ping": [
{
"status": "pass",
"time": "2022-02-19T09:16:08Z"
}
]
}
}
```
有关更多信息,请参考 Kubernetes 文档 [配置存活、就绪和启动探测器](https://kubernetes.io/zh-cn/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/)
12 changes: 6 additions & 6 deletions integrations/api_notification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"net/http"
"testing"

"code.gitea.io/gitea/models"
activities_model "code.gitea.io/gitea/models/activities"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
Expand All @@ -23,7 +23,7 @@ func TestAPINotification(t *testing.T) {

user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
thread5 := unittest.AssertExistsAndLoadBean(t, &models.Notification{ID: 5})
thread5 := unittest.AssertExistsAndLoadBean(t, &activities_model.Notification{ID: 5})
assert.NoError(t, thread5.LoadAttributes())
session := loginUser(t, user2.Name)
token := getTokenForLoggedInUser(t, session)
Expand Down Expand Up @@ -126,9 +126,9 @@ func TestAPINotification(t *testing.T) {
req = NewRequest(t, "PATCH", fmt.Sprintf("/api/v1/notifications/threads/%d?token=%s", thread5.ID, token))
session.MakeRequest(t, req, http.StatusResetContent)

assert.Equal(t, models.NotificationStatusUnread, thread5.Status)
thread5 = unittest.AssertExistsAndLoadBean(t, &models.Notification{ID: 5})
assert.Equal(t, models.NotificationStatusRead, thread5.Status)
assert.Equal(t, activities_model.NotificationStatusUnread, thread5.Status)
thread5 = unittest.AssertExistsAndLoadBean(t, &activities_model.Notification{ID: 5})
assert.Equal(t, activities_model.NotificationStatusRead, thread5.Status)

// -- check notifications --
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications/new?token=%s", token))
Expand All @@ -141,7 +141,7 @@ func TestAPINotificationPUT(t *testing.T) {
defer prepareTestEnv(t)()

user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
thread5 := unittest.AssertExistsAndLoadBean(t, &models.Notification{ID: 5})
thread5 := unittest.AssertExistsAndLoadBean(t, &activities_model.Notification{ID: 5})
assert.NoError(t, thread5.LoadAttributes())
session := loginUser(t, user2.Name)
token := getTokenForLoggedInUser(t, session)
Expand Down
5 changes: 2 additions & 3 deletions integrations/api_releases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"net/url"
"testing"

"code.gitea.io/gitea/models"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
Expand Down Expand Up @@ -84,7 +83,7 @@ func createNewReleaseUsingAPI(t *testing.T, session *TestSession, token string,

var newRelease api.Release
DecodeJSON(t, resp, &newRelease)
rel := &models.Release{
rel := &repo_model.Release{
ID: newRelease.ID,
TagName: newRelease.TagName,
Title: newRelease.Title,
Expand Down Expand Up @@ -138,7 +137,7 @@ func TestAPICreateAndUpdateRelease(t *testing.T) {
resp = session.MakeRequest(t, req, http.StatusOK)

DecodeJSON(t, resp, &newRelease)
rel := &models.Release{
rel := &repo_model.Release{
ID: newRelease.ID,
TagName: newRelease.TagName,
Title: newRelease.Title,
Expand Down
8 changes: 4 additions & 4 deletions integrations/api_token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"net/http"
"testing"

"code.gitea.io/gitea/models"
auth_model "code.gitea.io/gitea/models/auth"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
api "code.gitea.io/gitea/modules/structs"
Expand All @@ -27,7 +27,7 @@ func TestAPICreateAndDeleteToken(t *testing.T) {

var newAccessToken api.AccessToken
DecodeJSON(t, resp, &newAccessToken)
unittest.AssertExistsAndLoadBean(t, &models.AccessToken{
unittest.AssertExistsAndLoadBean(t, &auth_model.AccessToken{
ID: newAccessToken.ID,
Name: newAccessToken.Name,
Token: newAccessToken.Token,
Expand All @@ -38,7 +38,7 @@ func TestAPICreateAndDeleteToken(t *testing.T) {
req = AddBasicAuthHeader(req, user.Name)
MakeRequest(t, req, http.StatusNoContent)

unittest.AssertNotExistsBean(t, &models.AccessToken{ID: newAccessToken.ID})
unittest.AssertNotExistsBean(t, &auth_model.AccessToken{ID: newAccessToken.ID})

req = NewRequestWithJSON(t, "POST", "/api/v1/users/user1/tokens", map[string]string{
"name": "test-key-2",
Expand All @@ -51,7 +51,7 @@ func TestAPICreateAndDeleteToken(t *testing.T) {
req = AddBasicAuthHeader(req, user.Name)
MakeRequest(t, req, http.StatusNoContent)

unittest.AssertNotExistsBean(t, &models.AccessToken{ID: newAccessToken.ID})
unittest.AssertNotExistsBean(t, &auth_model.AccessToken{ID: newAccessToken.ID})
}

// TestAPIDeleteMissingToken ensures that error is thrown when token not found
Expand Down
8 changes: 4 additions & 4 deletions integrations/api_user_heatmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"testing"
"time"

"code.gitea.io/gitea/models"
activities_model "code.gitea.io/gitea/models/activities"
"code.gitea.io/gitea/modules/timeutil"

"github.com/stretchr/testify/assert"
Expand All @@ -29,10 +29,10 @@ func TestUserHeatmap(t *testing.T) {
urlStr := fmt.Sprintf("/api/v1/users/%s/heatmap?token=%s", normalUsername, token)
req := NewRequest(t, "GET", urlStr)
resp := MakeRequest(t, req, http.StatusOK)
var heatmap []*models.UserHeatmapData
var heatmap []*activities_model.UserHeatmapData
DecodeJSON(t, resp, &heatmap)
var dummyheatmap []*models.UserHeatmapData
dummyheatmap = append(dummyheatmap, &models.UserHeatmapData{Timestamp: 1603227600, Contributions: 1})
var dummyheatmap []*activities_model.UserHeatmapData
dummyheatmap = append(dummyheatmap, &activities_model.UserHeatmapData{Timestamp: 1603227600, Contributions: 1})

assert.Equal(t, dummyheatmap, heatmap)
}
6 changes: 3 additions & 3 deletions integrations/eventsource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"testing"
"time"

"code.gitea.io/gitea/models"
activities_model "code.gitea.io/gitea/models/activities"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
Expand Down Expand Up @@ -42,7 +42,7 @@ func TestEventSourceManagerRun(t *testing.T) {
if !ok {
return false
}
data, ok := event.Data.(models.UserIDCount)
data, ok := event.Data.(activities_model.UserIDCount)
if !ok {
return false
}
Expand All @@ -55,7 +55,7 @@ func TestEventSourceManagerRun(t *testing.T) {

user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
thread5 := unittest.AssertExistsAndLoadBean(t, &models.Notification{ID: 5})
thread5 := unittest.AssertExistsAndLoadBean(t, &activities_model.Notification{ID: 5})
assert.NoError(t, thread5.LoadAttributes())
session := loginUser(t, user2.Name)
token := getTokenForLoggedInUser(t, session)
Expand Down
Loading

0 comments on commit 64da426

Please sign in to comment.