Skip to content

Commit

Permalink
Merge remote-tracking branch 'giteaofficial/main'
Browse files Browse the repository at this point in the history
* giteaofficial/main: (25 commits)
  zh-cn support on doc pages (go-gitea#24166)
  [skip ci] Updated translations via Crowdin
  Use double quotes consistently in en-US (go-gitea#24141)
  Use correct locale key for forks page (go-gitea#24172)
  Improve Wiki TOC (go-gitea#24137)
  Localize activity heatmap (except tooltip) (go-gitea#24131)
  Support triggering workflows by wiki related events (go-gitea#24119)
  add CLI command to register runner tokens (go-gitea#23762)
  Add new user types `reserved`, `bot`, and `remote` (go-gitea#24026)
  Fix Org edit page bugs: renaming detection, maxlength (go-gitea#24161)
  Make HAS_GO a simply expanded variable (go-gitea#24169)
  Support converting varchar to nvarchar for mssql database (go-gitea#24105)
  Fix math and mermaid rendering bugs (go-gitea#24049)
  Refactor locale number (go-gitea#24134)
  [skip ci] Updated translations via Crowdin
  Use 1.18's aria role for dropdown menus (go-gitea#24144)
  Set EasyMDE heading font-size to the same size as the resulting markdown (go-gitea#24151)
  Fix 2-dot direct compare to use the right base commit (go-gitea#24133)
  Add migration to fix external unit access mode of owner/admin team (go-gitea#24117)
  Remove untranslatable `on_date` key (go-gitea#24106)
  ...
  • Loading branch information
zjjhot committed Apr 18, 2023
2 parents 9ecde7f + f82ee30 commit bab3026
Show file tree
Hide file tree
Showing 132 changed files with 1,172 additions and 610 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ IMPORT := code.gitea.io/gitea

GO ?= go
SHASUM ?= shasum -a 256
HAS_GO = $(shell hash $(GO) > /dev/null 2>&1 && echo "GO" || echo "NOGO" )
HAS_GO := $(shell hash $(GO) > /dev/null 2>&1 && echo yes)
COMMA := ,

XGO_VERSION := go-1.20.x
Expand All @@ -41,7 +41,7 @@ DOCKER_IMAGE ?= gitea/gitea
DOCKER_TAG ?= latest
DOCKER_REF := $(DOCKER_IMAGE):$(DOCKER_TAG)

ifeq ($(HAS_GO), GO)
ifeq ($(HAS_GO), yes)
GOPATH ?= $(shell $(GO) env GOPATH)
export PATH := $(GOPATH)/bin:$(PATH)

Expand Down
56 changes: 56 additions & 0 deletions cmd/actions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright 2023 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package cmd

import (
"fmt"

"code.gitea.io/gitea/modules/private"
"code.gitea.io/gitea/modules/setting"

"github.com/urfave/cli"
)

var (
// CmdActions represents the available actions sub-commands.
CmdActions = cli.Command{
Name: "actions",
Usage: "",
Description: "Commands for managing Gitea Actions",
Subcommands: []cli.Command{
subcmdActionsGenRunnerToken,
},
}

subcmdActionsGenRunnerToken = cli.Command{
Name: "generate-runner-token",
Usage: "Generate a new token for a runner to use to register with the server",
Action: runGenerateActionsRunnerToken,
Aliases: []string{"grt"},
Flags: []cli.Flag{
cli.StringFlag{
Name: "scope, s",
Value: "",
Usage: "{owner}[/{repo}] - leave empty for a global runner",
},
},
}
)

func runGenerateActionsRunnerToken(c *cli.Context) error {
ctx, cancel := installSignals()
defer cancel()

setting.InitProviderFromExistingFile()
setting.LoadCommonSettings()

scope := c.String("scope")

respText, extra := private.GenerateActionsRunnerToken(ctx, scope)
if extra.HasError() {
return handleCliResponseExtra(extra)
}
_, _ = fmt.Printf("%s\n", respText)
return nil
}
27 changes: 16 additions & 11 deletions cmd/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
var CmdConvert = cli.Command{
Name: "convert",
Usage: "Convert the database",
Description: "A command to convert an existing MySQL database from utf8 to utf8mb4",
Description: "A command to convert an existing MySQL database from utf8 to utf8mb4 or MSSQL database from varchar to nvarchar",
Action: runConvert,
}

Expand All @@ -35,17 +35,22 @@ func runConvert(ctx *cli.Context) error {
log.Info("Log path: %s", setting.Log.RootPath)
log.Info("Configuration file: %s", setting.CustomConf)

if !setting.Database.Type.IsMySQL() {
fmt.Println("This command can only be used with a MySQL database")
return nil
switch {
case setting.Database.Type.IsMySQL():
if err := db.ConvertUtf8ToUtf8mb4(); err != nil {
log.Fatal("Failed to convert database from utf8 to utf8mb4: %v", err)
return err
}
fmt.Println("Converted successfully, please confirm your database's character set is now utf8mb4")
case setting.Database.Type.IsMSSQL():
if err := db.ConvertVarcharToNVarchar(); err != nil {
log.Fatal("Failed to convert database from varchar to nvarchar: %v", err)
return err
}
fmt.Println("Converted successfully, please confirm your database's all columns character is NVARCHAR now")
default:
fmt.Println("This command can only be used with a MySQL or MSSQL database")
}

if err := db.ConvertUtf8ToUtf8mb4(); err != nil {
log.Fatal("Failed to convert database from utf8 to utf8mb4: %v", err)
return err
}

fmt.Println("Converted successfully, please confirm your database's character set is now utf8mb4")

return nil
}
25 changes: 25 additions & 0 deletions docs/content/doc/administration/command-line.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -551,3 +551,28 @@ Restore-repo restore repository data from disk dir:
- `--owner_name lunny`: Restore destination owner name
- `--repo_name tango`: Restore destination repository name
- `--units <units>`: Which items will be restored, one or more units should be separated as comma. wiki, issues, labels, releases, release_assets, milestones, pull_requests, comments are allowed. Empty means all units.

### actions generate-runner-token

Generate a new token for a runner to use to register with the server

- Options:
- `--scope {owner}[/{repo}]`, `-s {owner}[/{repo}]`: To limit the scope of the runner, no scope means the runner can be used for all repos, but you can also limit it to a specific repo or owner

To register a global runner:

```
gitea actions generate-runner-token
```

To register a runner for a specific organization, in this case `org`:

```
gitea actions generate-runner-token -s org
```

To register a runner for a specific repo, in this case `username/test-repo`:

```
gitea actions generate-runner-token -s username/test-repo
```
4 changes: 2 additions & 2 deletions docs/content/doc/administration/https-support.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ PORT_TO_REDIRECT = 3080

[ACME](https://tools.ietf.org/html/rfc8555) 是一种证书颁发机构标准协议,允许您自动请求和续订 SSL/TLS 证书。[Let`s Encrypt](https://letsencrypt.org/) 是使用此标准的免费公开信任的证书颁发机构服务器。仅实施“HTTP-01”和“TLS-ALPN-01”挑战。为了使 ACME 质询通过并验证您的域所有权,“80”端口(“HTTP-01”)或“443”端口(“TLS-ALPN-01”)上 gitea 域的外部流量必须由 gitea 实例提供服务。可能需要设置 [HTTP 重定向](#设置http重定向) 和端口转发才能正确路由外部流量。否则,到端口“80”的正常流量将自动重定向到 HTTPS。**您必须同意**ACME提供商的服务条款(默认为Let's Encrypt的 [服务条款](https://letsencrypt.org/documents/LE-SA-v1.2-2017年11月15日.pdf)

实用默认 Let's Encrypt 的最小配置如下:
使用默认 Let's Encrypt 的最小配置如下:

```ini
[server]
Expand Down Expand Up @@ -92,7 +92,7 @@ ACME_EMAIL=email@example.com

按照 [reverse proxy guide](../reverse-proxies) 的规则设置你的反向代理服务器

然后,按照下面的想到启用 HTTPS:
然后,按照下面的向导启用 HTTPS:

- [nginx](https://nginx.org/en/docs/http/configuring_https_servers.html)
- [apache2/httpd](https://httpd.apache.org/docs/2.4/ssl/ssl_howto.html)
Expand Down
91 changes: 91 additions & 0 deletions docs/content/doc/installation/upgrade-from-gitea.zh-cn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
---
date: "2021-09-02T16:00:00+08:00"
title: "从旧版 Gitea 升级"
slug: "upgrade-from-gitea"
weight: 100
toc: false
draft: false
menu:
sidebar:
parent: "installation"
name: "从旧版 Gitea 升级"
weight: 100
identifier: "upgrade-from-gitea"
---

# 从旧版 Gitea 升级

**目录**

{{< toc >}}

想要升级 Gitea,只需要下载新版,停止运行旧版,进行数据备份,然后运行新版就好。
每次 Gitea 实例启动时,它都会检查是否要进行数据库迁移。
如果需要进行数据库迁移,Gitea 会花一些时间完成升级然后继续服务。

## 为重大变更检查更新日志

为了让 Gitea 变得更好,进行重大变更是不可避免的,尤其是一些里程碑更新的发布。
在更新前,请 [在 Gitea 博客上阅读更新日志](https://blog.gitea.io/)
并检查重大变更是否会影响你的 Gitea 实例。

## 降级前的备份

Gitea 会保留首二位版本号相同的版本的兼容性 (`a.b.x` -> `a.b.y`),
这些版本拥有相同的数据库结构,可以自由升级或降级。
其他情况 (`a.b.?` -> `a.c.?`)下,
新版 Gitea 可能将会将数据库升级到与旧版数据库不同的结构。

举个例子:

| 当前 | 目标 | 结果 |
| --- | --- | --- |
| 1.4.0 | 1.4.1 ||
| 1.4.1 | 1.4.0 | ⚠️ 不建议,后果自负!尽管数据库结构可能不会变更,让它可以正常工作。我们强烈建议降级前进行完全的备份。 |
| 1.4.x | 1.5.y | ✅ 数据库会被自动升级。你可以直接从 1.4.x 升级到最新的 1.5.y。 |
| 1.5.y | 1.4.x | ❌ 数据库已被升级且不可被旧版 Gitea 利用,使用备份来进行降级。 |

**因为你不能基于升级后的数据库运行旧版 Gitea,所以你应该在数据库升级前完成数据备份。**

如果你在生产环境下使用 Gitea,你应该在升级前做好备份,哪怕只是小版本的补丁更新。

备份步骤:

* 停止 Gitea 实例
* 备份数据库
* 备份 Gitea 配置文件
* 备份 Gitea 在 `APP_DATA_PATH` 中的数据文件
* 备份 Gitea 的外部存储 (例如: S3/MinIO 或被使用的其他存储)

如果你在使用云服务或拥有快照功能的文件系统,
最好对 Gitea 的数据盘及相关资料存储进行一次快照。

## 从 Docker 升级

* `docker pull` 拉取 Gitea 的最新发布版。
* 停止运行中的实例,备份数据。
* 使用 `docker``docker-compose` 启动更新的 Gitea Docker 容器.

## 从包升级

* 停止运行中的实例,备份数据。
* 使用你的包管理器更新 Gitea 到最新版本。
* 启动 Gitea 实例。

## 从二进制升级

* 下载最新的 Gitea 二进制文件到临时文件夹中。
* 停止运行中的实例,备份数据。
* 将旧的 Gitea 二进制文件覆盖成新的。
* 启动 Gitea 实例。

在 Linux 系统上自动执行以上步骤的脚本可在 [Gitea 的 source tree 中找到 `contrib/upgrade.sh` 来获取](https://github.com/go-gitea/gitea/blob/main/contrib/upgrade.sh).

## 小心你的自定义模板

Gitea 的模板结构与变量可能会随着各个版本的发布发生变化,如果你使用了自定义模板,
你得注意你的模板与你使用的 Gitea 版本的兼容性。

如果自定义模板与 Gitea 版本不兼容,你可能会得到:
`50x` 服务器错误,页面元素丢失或故障,莫名其妙的页面布局,等等…
移除或更新不兼容的模板,Gitea Web 才可以正常工作。
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ arguments - which can alternatively be run by running the subcommand web.`
cmd.CmdDocs,
cmd.CmdDumpRepository,
cmd.CmdRestoreRepository,
cmd.CmdActions,
}
// Now adjust these commands to add our global configuration options

Expand Down
9 changes: 9 additions & 0 deletions models/activities/user_heatmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,12 @@ func getUserHeatmapData(user *user_model.User, team *organization.Team, doer *us
OrderBy("timestamp").
Find(&hdata)
}

// GetTotalContributionsInHeatmap returns the total number of contributions in a heatmap
func GetTotalContributionsInHeatmap(hdata []*UserHeatmapData) int64 {
var total int64
for _, v := range hdata {
total += v.Contributions
}
return total
}
27 changes: 27 additions & 0 deletions models/db/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,33 @@ func ConvertUtf8ToUtf8mb4() error {
return nil
}

// ConvertVarcharToNVarchar converts database and tables from varchar to nvarchar if it's mssql
func ConvertVarcharToNVarchar() error {
if x.Dialect().URI().DBType != schemas.MSSQL {
return nil
}

sess := x.NewSession()
defer sess.Close()
res, err := sess.QuerySliceString(`SELECT 'ALTER TABLE ' + OBJECT_NAME(SC.object_id) + ' MODIFY SC.name NVARCHAR(' + CONVERT(VARCHAR(5),SC.max_length) + ')'
FROM SYS.columns SC
JOIN SYS.types ST
ON SC.system_type_id = ST.system_type_id
AND SC.user_type_id = ST.user_type_id
WHERE ST.name ='varchar'`)
if err != nil {
return err
}
for _, row := range res {
if len(row) == 1 {
if _, err = sess.Exec(row[0]); err != nil {
return err
}
}
}
return err
}

// Cell2Int64 converts a xorm.Cell type to int64,
// and handles possible irregular cases.
func Cell2Int64(val xorm.Cell) int64 {
Expand Down
4 changes: 2 additions & 2 deletions models/issues/assignees.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ func IsUserAssignedToIssue(ctx context.Context, issue *Issue, user *user_model.U
}

// ToggleIssueAssignee changes a user between assigned and not assigned for this issue, and make issue comment for it.
func ToggleIssueAssignee(issue *Issue, doer *user_model.User, assigneeID int64) (removed bool, comment *Comment, err error) {
ctx, committer, err := db.TxContext(db.DefaultContext)
func ToggleIssueAssignee(ctx context.Context, issue *Issue, doer *user_model.User, assigneeID int64) (removed bool, comment *Comment, err error) {
ctx, committer, err := db.TxContext(ctx)
if err != nil {
return false, nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions models/issues/assignees_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ func TestUpdateAssignee(t *testing.T) {
// Assign multiple users
user2, err := user_model.GetUserByID(db.DefaultContext, 2)
assert.NoError(t, err)
_, _, err = issues_model.ToggleIssueAssignee(issue, &user_model.User{ID: 1}, user2.ID)
_, _, err = issues_model.ToggleIssueAssignee(db.DefaultContext, issue, &user_model.User{ID: 1}, user2.ID)
assert.NoError(t, err)

user3, err := user_model.GetUserByID(db.DefaultContext, 3)
assert.NoError(t, err)
_, _, err = issues_model.ToggleIssueAssignee(issue, &user_model.User{ID: 1}, user3.ID)
_, _, err = issues_model.ToggleIssueAssignee(db.DefaultContext, issue, &user_model.User{ID: 1}, user3.ID)
assert.NoError(t, err)

user1, err := user_model.GetUserByID(db.DefaultContext, 1) // This user is already assigned (see the definition in fixtures), so running UpdateAssignee should unassign him
assert.NoError(t, err)
_, _, err = issues_model.ToggleIssueAssignee(issue, &user_model.User{ID: 1}, user1.ID)
_, _, err = issues_model.ToggleIssueAssignee(db.DefaultContext, issue, &user_model.User{ID: 1}, user1.ID)
assert.NoError(t, err)

// Check if he got removed
Expand Down
4 changes: 2 additions & 2 deletions models/issues/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -743,8 +743,8 @@ func ChangeIssueStatus(ctx context.Context, issue *Issue, doer *user_model.User,
}

// ChangeIssueTitle changes the title of this issue, as the given user.
func ChangeIssueTitle(issue *Issue, doer *user_model.User, oldTitle string) (err error) {
ctx, committer, err := db.TxContext(db.DefaultContext)
func ChangeIssueTitle(ctx context.Context, issue *Issue, doer *user_model.User, oldTitle string) (err error) {
ctx, committer, err := db.TxContext(ctx)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion models/issues/issue_xref_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestXRef_NeuterCrossReferences(t *testing.T) {

d := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
i.Title = "title2, no mentions"
assert.NoError(t, issues_model.ChangeIssueTitle(i, d, title))
assert.NoError(t, issues_model.ChangeIssueTitle(db.DefaultContext, i, d, title))

ref = unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{IssueID: itarget.ID, RefIssueID: i.ID, RefCommentID: 0})
assert.Equal(t, issues_model.CommentTypeIssueRef, ref.Type)
Expand Down
2 changes: 2 additions & 0 deletions models/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,8 @@ var migrations = []Migration{
NewMigration("Fix incorrect owner team unit access mode", v1_20.FixIncorrectOwnerTeamUnitAccessMode),
// v252 -> v253
NewMigration("Fix incorrect admin team unit access mode", v1_20.FixIncorrectAdminTeamUnitAccessMode),
// v253 -> v254
NewMigration("Fix ExternalTracker and ExternalWiki accessMode in owner and admin team", v1_20.FixExternalTrackerAndExternalWikiAccessModeInOwnerAndAdminTeam),
}

// GetCurrentDBVersion returns the current db version
Expand Down
Loading

0 comments on commit bab3026

Please sign in to comment.