Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into vitest-global
Browse files Browse the repository at this point in the history
* origin/main:
  Fix dropdown icon position (go-gitea#27175)
  Fix repo sub menu (go-gitea#27169)
  Fix review request number and add more tests (go-gitea#27104)
  Fix the variable regexp pattern on web page (go-gitea#27161)
  Fix organization field being null in POST /orgs/{orgid}/teams (go-gitea#27150)
  Add index to `issue_user.issue_id` (go-gitea#27154)
  [skip ci] Updated translations via Crowdin
  Start development on Gitea 1.22 (go-gitea#27155)
  Fix successful return value for `SyncAndGetUserSpecificDiff` (go-gitea#27152)
  Improve actions docs related to `pull_request` event (go-gitea#27126)
  Remove outdated paragraphs when comparing Gitea Actions to GitHub Actions (go-gitea#27119)
  Fix: treat tab "overview" as "repositories" in user profiles without readme (go-gitea#27124)
  Fix incorrect test code for error handling (go-gitea#27139)
  Increase auth provider icon size on login page (go-gitea#27122)
  fix pagination for followers and following (go-gitea#27127)
  services/wiki: Close() after error handling (go-gitea#27129)
  Use fetch helpers instead of fetch (go-gitea#27026)
  Change green buttons to primary color (go-gitea#27099)
  Fix wrong xorm get usage on migration (go-gitea#27111)
  • Loading branch information
silverwind committed Sep 21, 2023
2 parents 7285d9f + 1f026bc commit d8ee8ac
Show file tree
Hide file tree
Showing 169 changed files with 498 additions and 397 deletions.
5 changes: 4 additions & 1 deletion .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ overrides:
- files: ["**/*.test.*", "web_src/js/test/setup.js"]
env:
vitest-globals/env: true
- files: ["web_src/js/modules/fetch.js", "web_src/js/standalone/**/*"]
rules:
no-restricted-syntax: [2, WithStatement, ForInStatement, LabeledStatement, SequenceExpression]

rules:
"@eslint-community/eslint-comments/disable-enable-pair": [2]
Expand Down Expand Up @@ -424,7 +427,7 @@ rules:
no-restricted-exports: [0]
no-restricted-globals: [2, addEventListener, blur, close, closed, confirm, defaultStatus, defaultstatus, error, event, external, find, focus, frameElement, frames, history, innerHeight, innerWidth, isFinite, isNaN, length, location, locationbar, menubar, moveBy, moveTo, name, onblur, onerror, onfocus, onload, onresize, onunload, open, opener, opera, outerHeight, outerWidth, pageXOffset, pageYOffset, parent, print, removeEventListener, resizeBy, resizeTo, screen, screenLeft, screenTop, screenX, screenY, scroll, scrollbars, scrollBy, scrollTo, scrollX, scrollY, self, status, statusbar, stop, toolbar, top, __dirname, __filename]
no-restricted-imports: [0]
no-restricted-syntax: [2, WithStatement, ForInStatement, LabeledStatement, SequenceExpression]
no-restricted-syntax: [2, WithStatement, ForInStatement, LabeledStatement, SequenceExpression, {selector: "CallExpression[callee.name='fetch']", message: "use modules/fetch.js instead"}]
no-return-assign: [0]
no-script-url: [2]
no-self-assign: [2, {props: true}]
Expand Down
2 changes: 1 addition & 1 deletion docs/content/contributing/guidelines-frontend.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Some lint rules and IDEs also have warnings if the returned Promise is not handl
### Fetching data

To fetch data, use the wrapper functions `GET`, `POST` etc. from `modules/fetch.js`. They
accept a `data` option for the content, will automatically set CSFR token and return a
accept a `data` option for the content, will automatically set CSRF token and return a
Promise for a [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response).

### HTML Attributes and `dataset`
Expand Down
22 changes: 9 additions & 13 deletions docs/content/usage/actions/comparison.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,6 @@ As a workaround, you can use [go-hashfiles](https://gitea.com/actions/go-hashfil

## Missing features

### Variables

See [Variables](https://docs.github.com/en/actions/learn-github-actions/variables).

It's under development.

### Problem Matchers

Problem Matchers are a way to scan the output of actions for a specified regex pattern and surface that information prominently in the UI.
Expand All @@ -120,15 +114,17 @@ Pre and Post steps don't have their own section in the job log user interface.

### Downloading actions

Gitea Actions doesn't download actions from GitHub by default.
"By default" means that you don't specify the host in the `uses` field, like `uses: actions/checkout@v3`.
As a contrast, `uses: https://github.com/actions/checkout@v3` has specified host.
Previously (Pre 1.21.0), `[actions].DEFAULT_ACTIONS_URL` defaulted to `https://gitea.com`.
We have since restricted this option to only allow two values (`github` and `self`).
When set to `github`, the new default, Gitea will download non-fully-qualified actions from <https://github.com>.
For example, if you use `uses: actions/checkout@v3`, it will download the checkout repository from <https://github.com/actions/checkout.git>.

If you want to download an action from another git hoster, you can use an absolute URL, e.g. `uses: https://gitea.com/actions/checkout@v3`.

The missing host will be filled with `https://gitea.com` if you don't configure it.
That means `uses: actions/checkout@v3` will download the action from [gitea.com/actions/checkout](https://gitea.com/actions/checkout), instead of [github.com/actions/checkout](https://github.com/actions/checkout).
If your Gitea instance is in an intranet or a restricted area, you can set the URL to `self` to only download actions from your own instance by default.
Of course, you can still use absolute URLs in workflows.

As mentioned, it's configurable.
If you want your runners to download actions from GitHub or your own Gitea instance by default, you can configure it by setting `[actions].DEFAULT_ACTIONS_URL`. See [Configuration Cheat Sheet](administration/config-cheat-sheet.md#actions-actions).
More details about the `[actions].DEFAULT_ACTIONS_URL` configuration can be found in the [Configuration Cheat Sheet](administration/config-cheat-sheet.md#actions-actions)

### Context availability

Expand Down
12 changes: 5 additions & 7 deletions docs/content/usage/actions/comparison.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,13 @@ Gitea Actions目前不支持此功能。

### 下载Actions

Gitea Actions默认不从GitHub下载Actions。
"默认" 意味着您在`uses` 字段中不指定主机,如`uses: actions/checkout@v3`
相反,`uses: https://github.com/actions/checkout@v3`是有指定主机的
`[actions].DEFAULT_ACTIONS_URL` 保持默认值为 `github` 时,Gitea将会从 https://github.com 下载相对路径的actions。比如:
如果你使用 `uses: actions/checkout@v3`,Gitea将会从 https://github.com/actions/checkout.git 下载这个 actions 项目
如果你想要从另外一个 Git服务下载actions,你只需要使用绝对URL `uses: https://gitea.com/actions/checkout@v3` 来下载

如果您不进行配置,缺失的主机将填充为`https://gitea.com`
这意味着`uses: actions/checkout@v3`将从[gitea.com/actions/checkout](https://gitea.com/actions/checkout)下载该Action,而不是[github.com/actions/checkout](https://github.com/actions/checkout)
如果你的 Gitea 实例是部署在一个互联网限制的网络中,有可以使用绝对地址来下载 actions。你也可以讲配置项修改为 `[actions].DEFAULT_ACTIONS_URL = self`。这样所有的相对路径的actions引用,将不再会从 github.com 去下载,而会从这个 Gitea 实例自己的仓库中去下载。例如: `uses: actions/checkout@v3` 将会从 `[server].ROOT_URL`/actions/checkout.git 这个地址去下载 actions。

正如前面提到的,这是可配置的。
如果您希望您的运行程序默认从GitHub或您自己的Gitea实例下载动作,您可以通过设置`[actions].DEFAULT_ACTIONS_URL`进行配置。请参阅[配置备忘单](administration/config-cheat-sheet.md#actions-actions)
设置`[actions].DEFAULT_ACTIONS_URL`进行配置。请参阅[配置备忘单](administration/config-cheat-sheet.md#actions-actions)

### 上下文可用性

Expand Down
3 changes: 3 additions & 0 deletions docs/content/usage/actions/faq.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,6 @@ For events supported only by GitHub, see GitHub's [documentation](https://docs.g
| pull_request_review_comment | `created`, `edited` |
| release | `published`, `edited` |
| registry_package | `published` |

> For `pull_request` events, in [GitHub Actions](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request), the `ref` is `refs/pull/:prNumber/merge`, which is a reference to the merge commit preview. However, Gitea has no such reference.
> Therefore, the `ref` in Gitea Actions is `refs/pull/:prNumber/head`, which points to the head of pull request rather than the preview of the merge commit.
3 changes: 3 additions & 0 deletions docs/content/usage/actions/faq.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,6 @@ defaults:
| pull_request_review_comment | `created`, `edited` |
| release | `published`, `edited` |
| registry_package | `published` |

> 对于 `pull_request` 事件,在 [GitHub Actions](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request) 中 `ref` 是 `refs/pull/:prNumber/merge`,它指向这个拉取请求合并提交的一个预览。但是 Gitea 没有这种 reference。
> 因此,Gitea Actions 中 `ref` 是 `refs/pull/:prNumber/head`,它指向这个拉取请求的头分支而不是合并提交的预览。
17 changes: 17 additions & 0 deletions models/fixtures/issue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -321,3 +321,20 @@
created_unix: 946684830
updated_unix: 978307200
is_locked: false

-
id: 20
repo_id: 23
index: 1
poster_id: 2
original_author_id: 0
name: issue for pr
content: content
milestone_id: 0
priority: 0
is_closed: false
is_pull: true
num_comments: 0
created_unix: 978307210
updated_unix: 978307210
is_locked: false
9 changes: 9 additions & 0 deletions models/fixtures/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,12 @@
base_branch: main
merge_base: cbff181af4c9c7fee3cf6c106699e07d9a3f54e6
has_merged: false

-
id: 8
type: 0 # gitea pull request
status: 2 # mergable
issue_id: 20
index: 1
head_repo_id: 23
base_repo_id: 23
2 changes: 1 addition & 1 deletion models/fixtures/repository.yml
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@
num_forks: 0
num_issues: 0
num_closed_issues: 0
num_pulls: 0
num_pulls: 1
num_closed_pulls: 0
num_milestones: 0
num_closed_milestones: 0
Expand Down
38 changes: 38 additions & 0 deletions models/fixtures/review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,41 @@
content: "singular review from org6 and final review for this pr"
updated_unix: 946684831
created_unix: 946684831

-
id: 16
type: 4
reviewer_id: 20
issue_id: 20
content: "review request for user20"
updated_unix: 946684832
created_unix: 946684832

-
id: 17
type: 1
reviewer_id: 20
issue_id: 20
content: "review approved by user20"
updated_unix: 946684833
created_unix: 946684833
-
id: 18
type: 4
reviewer_id: 0
reviewer_team_id: 5
issue_id: 20
content: "review request for team5"
updated_unix: 946684834
created_unix: 946684834

-
id: 19
type: 4
reviewer_id: 15
reviewer_team_id: 0
issue_id: 20
content: "review request for user15"
updated_unix: 946684835
created_unix: 946684835

2 changes: 1 addition & 1 deletion models/fixtures/team.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
name: review_team
authorize: 1 # read
num_repos: 1
num_members: 2
num_members: 3
includes_all_repositories: false
can_create_org_repo: false

Expand Down
6 changes: 6 additions & 0 deletions models/fixtures/team_user.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,9 @@
org_id: 36
team_id: 20
uid: 5

-
id: 22
org_id: 17
team_id: 9
uid: 15
9 changes: 8 additions & 1 deletion models/issues/issue_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,14 +362,21 @@ func applyReviewRequestedCondition(sess *xorm.Session, reviewRequestedID int64)
From("team_user").
Where(builder.Eq{"team_user.uid": reviewRequestedID})

// if the review is approved or rejected, it should not be shown in the review requested list
maxReview := builder.Select("MAX(r.id)").
From("review as r").
Where(builder.In("r.type", []ReviewType{ReviewTypeApprove, ReviewTypeReject, ReviewTypeRequest})).
GroupBy("r.issue_id, r.reviewer_id, r.reviewer_team_id")

subQuery := builder.Select("review.issue_id").
From("review").
Where(builder.And(
builder.In("review.type", []ReviewType{ReviewTypeRequest, ReviewTypeReject, ReviewTypeApprove}),
builder.Eq{"review.type": ReviewTypeRequest},
builder.Or(
builder.Eq{"review.reviewer_id": reviewRequestedID},
builder.In("review.reviewer_team_id", existInTeamQuery),
),
builder.In("review.id", maxReview),
))
return sess.Where("issue.poster_id <> ?", reviewRequestedID).
And(builder.In("issue.id", subQuery))
Expand Down
2 changes: 1 addition & 1 deletion models/issues/issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ func TestCountIssues(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
count, err := issues_model.CountIssues(db.DefaultContext, &issues_model.IssuesOptions{})
assert.NoError(t, err)
assert.EqualValues(t, 19, count)
assert.EqualValues(t, 20, count)
}

func TestIssueLoadAttributes(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion models/issues/issue_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
type IssueUser struct {
ID int64 `xorm:"pk autoincr"`
UID int64 `xorm:"INDEX"` // User ID.
IssueID int64
IssueID int64 `xorm:"INDEX"`
IsRead bool
IsMentioned bool
}
Expand Down
2 changes: 2 additions & 0 deletions models/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,8 @@ var migrations = []Migration{
NewMigration("Add ScheduleID for ActionRun", v1_21.AddScheduleIDForActionRun),
// v276 -> v277
NewMigration("Add RemoteAddress to mirrors", v1_21.AddRemoteAddressToMirrors),
// v277 -> v278
NewMigration("Add Index to issue_user.issue_id", v1_21.AddIndexToIssueUserIssueID),
}

// GetCurrentDBVersion returns the current db version
Expand Down
33 changes: 14 additions & 19 deletions models/migrations/v1_21/v276.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ func migratePullMirrors(x *xorm.Engine) error {
ID int64 `xorm:"pk autoincr"`
RepoID int64 `xorm:"INDEX"`
RemoteAddress string `xorm:"VARCHAR(2048)"`
RepoOwner string
RepoName string
}

sess := x.NewSession()
Expand All @@ -59,7 +61,9 @@ func migratePullMirrors(x *xorm.Engine) error {

for {
var mirrors []Mirror
if err := sess.Limit(limit, start).Find(&mirrors); err != nil {
if err := sess.Select("mirror.id, mirror.repo_id, mirror.remote_address, repository.owner_name as repo_owner, repository.name as repo_name").
Join("INNER", "repository", "repository.id = mirror.repo_id").
Limit(limit, start).Find(&mirrors); err != nil {
return err
}

Expand All @@ -69,7 +73,7 @@ func migratePullMirrors(x *xorm.Engine) error {
start += len(mirrors)

for _, m := range mirrors {
remoteAddress, err := getRemoteAddress(sess, m.RepoID, "origin")
remoteAddress, err := getRemoteAddress(m.RepoOwner, m.RepoName, "origin")
if err != nil {
return err
}
Expand Down Expand Up @@ -100,6 +104,8 @@ func migratePushMirrors(x *xorm.Engine) error {
RepoID int64 `xorm:"INDEX"`
RemoteName string
RemoteAddress string `xorm:"VARCHAR(2048)"`
RepoOwner string
RepoName string
}

sess := x.NewSession()
Expand All @@ -118,7 +124,9 @@ func migratePushMirrors(x *xorm.Engine) error {

for {
var mirrors []PushMirror
if err := sess.Limit(limit, start).Find(&mirrors); err != nil {
if err := sess.Select("push_mirror.id, push_mirror.repo_id, push_mirror.remote_name, push_mirror.remote_address, repository.owner_name as repo_owner, repository.name as repo_name").
Join("INNER", "repository", "repository.id = push_mirror.repo_id").
Limit(limit, start).Find(&mirrors); err != nil {
return err
}

Expand All @@ -128,7 +136,7 @@ func migratePushMirrors(x *xorm.Engine) error {
start += len(mirrors)

for _, m := range mirrors {
remoteAddress, err := getRemoteAddress(sess, m.RepoID, m.RemoteName)
remoteAddress, err := getRemoteAddress(m.RepoOwner, m.RepoName, m.RemoteName)
if err != nil {
return err
}
Expand All @@ -153,25 +161,12 @@ func migratePushMirrors(x *xorm.Engine) error {
return sess.Commit()
}

func getRemoteAddress(sess *xorm.Session, repoID int64, remoteName string) (string, error) {
var ownerName string
var repoName string
has, err := sess.
Table("repository").
Cols("owner_name", "lower_name").
Where("id=?", repoID).
Get(&ownerName, &repoName)
if err != nil {
return "", err
} else if !has {
return "", fmt.Errorf("repository [%v] not found", repoID)
}

func getRemoteAddress(ownerName, repoName, remoteName string) (string, error) {
repoPath := filepath.Join(setting.RepoRootPath, strings.ToLower(ownerName), strings.ToLower(repoName)+".git")

remoteURL, err := git.GetRemoteAddress(context.Background(), repoPath, remoteName)
if err != nil {
return "", err
return "", fmt.Errorf("get remote %s's address of %s/%s failed: %v", remoteName, ownerName, repoName, err)
}

u, err := giturl.Parse(remoteURL)
Expand Down
16 changes: 16 additions & 0 deletions models/migrations/v1_21/v277.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2023 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package v1_21 //nolint

import (
"xorm.io/xorm"
)

func AddIndexToIssueUserIssueID(x *xorm.Engine) error {
type IssueUser struct {
IssueID int64 `xorm:"INDEX"`
}

return x.Sync(new(IssueUser))
}
Loading

0 comments on commit d8ee8ac

Please sign in to comment.