Skip to content

Commit

Permalink
Merge remote-tracking branch 'giteaofficial/main'
Browse files Browse the repository at this point in the history
* giteaofficial/main: (23 commits)
  Fix wrong test usage of `AppSubURL` (go-gitea#29459)
  Improve contrast on blame timestamp, fix double border (go-gitea#29482)
  Fix/Improve `processWindowErrorEvent` (go-gitea#29407)
  Apply compact padding to small buttons with svg icons (go-gitea#29471)
  Fix counter display number incorrectly displayed on the page (go-gitea#29448)
  Fix incorrect user location link on profile page (go-gitea#29474)
  Fix workflow trigger event bugs (go-gitea#29467)
  Fix URL calculation in clone input box (go-gitea#29470)
  Remove jQuery from the "find file" page (go-gitea#29456)
  Move generate from module to service (go-gitea#29465)
  The job should always run when `if` is `always()` (go-gitea#29464)
  Recolor dark theme to blue shade (go-gitea#29283)
  Let ctx.FormOptionalBool() return optional.Option[bool] (go-gitea#29461)
  Implement actions badge svgs (go-gitea#28102)
  Fix missed return (go-gitea#29450)
  Use tailwind instead of `gt-[wh]-` helper classes (go-gitea#29423)
  Lock issues and pulls faster (go-gitea#29436)
  Allow to change primary email before account activation (go-gitea#29412)
  Update docs about `DEFAULT_ACTIONS_URL` (go-gitea#29442)
  Only use supported sort order for "explore/users" page (go-gitea#29430)
  ...
  • Loading branch information
zjjhot committed Feb 29, 2024
2 parents ddef710 + a6fd017 commit dd1ca6c
Show file tree
Hide file tree
Showing 405 changed files with 1,249 additions and 754 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/cron-lock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ jobs:
steps:
- uses: dessant/lock-threads@v5
with:
issue-inactive-days: 45
issue-inactive-days: 10
issue-comment: |
Automatically locked because of our [CONTRIBUTING guidelines](https://github.com/go-gitea/gitea/blob/main/CONTRIBUTING.md#issue-locking)
pr-inactive-days: 7
pr-comment: |
Automatically locked because of our [CONTRIBUTING guidelines](https://github.com/go-gitea/gitea/blob/main/CONTRIBUTING.md#issue-locking)
15 changes: 7 additions & 8 deletions docs/content/usage/actions/faq.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,24 @@ It is technically possible to implement, but we need to discuss whether it is ne

## Where will the runner download scripts when using actions such as `actions/checkout@v4`?

You may be aware that there are tens of thousands of [marketplace actions](https://github.com/marketplace?type=actions) in GitHub.
However, when you write `uses: actions/checkout@v4`, it actually downloads the scripts from [gitea.com/actions/checkout](http://gitea.com/actions/checkout) by default (not GitHub).
This is a mirror of [github.com/actions/checkout](http://github.com/actions/checkout), but it's impossible to mirror all of them.
That's why you may encounter failures when trying to use some actions that haven't been mirrored.
There are tens of thousands of [actions scripts](https://github.com/marketplace?type=actions) in GitHub, and when you write `uses: actions/checkout@v4`, it downloads the scripts from [github.com/actions/checkout](http://github.com/actions/checkout) by default.
But what if you want to use actions from other places such as gitea.com instead of GitHub?

The good news is that you can specify the URL prefix to use actions from anywhere.
This is an extra syntax in Gitea Actions.
For example:

- `uses: https://github.com/xxx/xxx@xxx`
- `uses: https://gitea.com/xxx/xxx@xxx`
- `uses: https://github.com/xxx/xxx@xxx`
- `uses: http://your_gitea_instance.com/xxx@xxx`

Be careful, the `https://` or `http://` prefix is necessary!

Alternatively, 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).
This is one of the differences from GitHub Actions which supports actions scripts only from GitHub.
But it should allow users much more flexibility in how they run Actions.

This is one of the differences from GitHub Actions, but it should allow users much more flexibility in how they run Actions.
Alternatively, if you want your runners to download actions from 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).

## How to limit the permission of the runners?

Expand Down
16 changes: 8 additions & 8 deletions docs/content/usage/actions/faq.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,25 @@ DEFAULT_REPO_UNITS = ...,repo.actions

## 使用`actions/checkout@v4`等Actions时,Job容器会从何处下载脚本?

您可能知道GitHub上有成千上万个[Actions市场](https://github.com/marketplace?type=actions)
然而,当您编写`uses: actions/checkout@v4`时,它实际上默认从[gitea.com/actions/checkout](http://gitea.com/actions/checkout)下载脚本(而不是从GitHub下载)。
这是[github.com/actions/checkout](http://github.com/actions/checkout)的镜像,但无法将它们全部镜像。
这就是为什么在尝试使用尚未镜像的某些Actions时可能会遇到失败的原因。
GitHub 上有成千上万个 [Actions 脚本](https://github.com/marketplace?type=actions)
当您编写 `uses: actions/checkout@v4` 时,它默认会从 [github.com/actions/checkout](https://github.com/actions/checkout) 下载脚本。
那如果您想使用一些托管在其它平台上的脚本呢,比如在 gitea.com 上的?

好消息是,您可以指定要从任何位置使用Actions的URL前缀。
这是Gitea Actions中的额外语法。
例如:

- `uses: https://github.com/xxx/xxx@xxx`
- `uses: https://gitea.com/xxx/xxx@xxx`
- `uses: https://github.com/xxx/xxx@xxx`
- `uses: http://your_gitea_instance.com/xxx@xxx`

注意,`https://``http://`前缀是必需的!

另外,如果您希望您的Runner默认从GitHub或您自己的Gitea实例下载Actions,可以通过设置 `[actions].DEFAULT_ACTIONS_URL`进行配置
参见[配置速查表](administration/config-cheat-sheet.md#actions-actions)
这是与 GitHub Actions 的一个区别,GitHub Actions 只允许使用托管在 GitHub 上的 actions 脚本
但用户理应拥有权利去灵活决定如何运行 Actions

这是与GitHub Actions的一个区别,但它应该允许用户以更灵活的方式运行Actions。
另外,如果您希望您的 Runner 默认从您自己的 Gitea 实例下载 Actions,可以通过设置 `[actions].DEFAULT_ACTIONS_URL`进行配置。
参见[配置速查表](administration/config-cheat-sheet.md#actions-actions)

## 如何限制Runner的权限?

Expand Down
37 changes: 37 additions & 0 deletions docs/content/usage/badge.en-us.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
date: "2023-02-25T00:00:00+00:00"
title: "Badge"
slug: "badge"
sidebar_position: 11
toc: false
draft: false
aliases:
- /en-us/badge
menu:
sidebar:
parent: "usage"
name: "Badge"
sidebar_position: 11
identifier: "Badge"
---

# Badge

Gitea has its builtin Badge system which allows you to display the status of your repository in other places. You can use the following badges:

## Workflow Badge

The Gitea Actions workflow badge is a badge that shows the status of the latest workflow run.
It is designed to be compatible with [GitHub Actions workflow badge](https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/adding-a-workflow-status-badge).

You can use the following URL to get the badge:

```
https://your-gitea-instance.com/{owner}/{repo}/actions/workflows/{workflow_file}?branch={branch}&event={event}
```

- `{owner}`: The owner of the repository.
- `{repo}`: The name of the repository.
- `{workflow_file}`: The name of the workflow file.
- `{branch}`: Optional. The branch of the workflow. Default to your repository's default branch.
- `{event}`: Optional. The event of the workflow. Default to none.
17 changes: 17 additions & 0 deletions models/actions/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,23 @@ func GetRunByIndex(ctx context.Context, repoID, index int64) (*ActionRun, error)
return run, nil
}

func GetWorkflowLatestRun(ctx context.Context, repoID int64, workflowFile, branch, event string) (*ActionRun, error) {
var run ActionRun
q := db.GetEngine(ctx).Where("repo_id=?", repoID).
And("ref = ?", branch).
And("workflow_id = ?", workflowFile)
if event != "" {
q.And("event = ?", event)
}
has, err := q.Desc("id").Get(&run)
if err != nil {
return nil, err
} else if !has {
return nil, util.NewNotExistErrorf("run with repo_id %d, ref %s, workflow_id %s", repoID, branch, workflowFile)
}
return &run, nil
}

// UpdateRun updates a run.
// It requires the inputted run has Version set.
// It will return error if the version is not matched (it means the run has been changed after loaded).
Expand Down
21 changes: 11 additions & 10 deletions models/repo/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"code.gitea.io/gitea/models/db"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util"
Expand Down Expand Up @@ -228,10 +229,10 @@ type FindReleasesOptions struct {
RepoID int64
IncludeDrafts bool
IncludeTags bool
IsPreRelease util.OptionalBool
IsDraft util.OptionalBool
IsPreRelease optional.Option[bool]
IsDraft optional.Option[bool]
TagNames []string
HasSha1 util.OptionalBool // useful to find draft releases which are created with existing tags
HasSha1 optional.Option[bool] // useful to find draft releases which are created with existing tags
}

func (opts FindReleasesOptions) ToConds() builder.Cond {
Expand All @@ -246,14 +247,14 @@ func (opts FindReleasesOptions) ToConds() builder.Cond {
if len(opts.TagNames) > 0 {
cond = cond.And(builder.In("tag_name", opts.TagNames))
}
if !opts.IsPreRelease.IsNone() {
cond = cond.And(builder.Eq{"is_prerelease": opts.IsPreRelease.IsTrue()})
if opts.IsPreRelease.Has() {
cond = cond.And(builder.Eq{"is_prerelease": opts.IsPreRelease.Value()})
}
if !opts.IsDraft.IsNone() {
cond = cond.And(builder.Eq{"is_draft": opts.IsDraft.IsTrue()})
if opts.IsDraft.Has() {
cond = cond.And(builder.Eq{"is_draft": opts.IsDraft.Value()})
}
if !opts.HasSha1.IsNone() {
if opts.HasSha1.IsTrue() {
if opts.HasSha1.Has() {
if opts.HasSha1.Value() {
cond = cond.And(builder.Neq{"sha1": ""})
} else {
cond = cond.And(builder.Eq{"sha1": ""})
Expand All @@ -275,7 +276,7 @@ func GetTagNamesByRepoID(ctx context.Context, repoID int64) ([]string, error) {
ListOptions: listOptions,
IncludeDrafts: true,
IncludeTags: true,
HasSha1: util.OptionalBoolTrue,
HasSha1: optional.Some(true),
RepoID: repoID,
}

Expand Down
46 changes: 29 additions & 17 deletions models/user/email_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ import (
"xorm.io/builder"
)

// ErrEmailNotActivated e-mail address has not been activated error
var ErrEmailNotActivated = util.NewInvalidArgumentErrorf("e-mail address has not been activated")

// ErrEmailCharIsNotSupported e-mail address contains unsupported character
type ErrEmailCharIsNotSupported struct {
Email string
Expand Down Expand Up @@ -313,27 +310,27 @@ func updateActivation(ctx context.Context, email *EmailAddress, activate bool) e
return UpdateUserCols(ctx, user, "rands")
}

// MakeEmailPrimary sets primary email address of given user.
func MakeEmailPrimary(ctx context.Context, email *EmailAddress) error {
has, err := db.GetEngine(ctx).Get(email)
if err != nil {
func MakeActiveEmailPrimary(ctx context.Context, emailID int64) error {
return makeEmailPrimaryInternal(ctx, emailID, true)
}

func MakeInactiveEmailPrimary(ctx context.Context, emailID int64) error {
return makeEmailPrimaryInternal(ctx, emailID, false)
}

func makeEmailPrimaryInternal(ctx context.Context, emailID int64, isActive bool) error {
email := &EmailAddress{}
if has, err := db.GetEngine(ctx).ID(emailID).Where(builder.Eq{"is_activated": isActive}).Get(email); err != nil {
return err
} else if !has {
return ErrEmailAddressNotExist{Email: email.Email}
}

if !email.IsActivated {
return ErrEmailNotActivated
return ErrEmailAddressNotExist{}
}

user := &User{}
has, err = db.GetEngine(ctx).ID(email.UID).Get(user)
if err != nil {
if has, err := db.GetEngine(ctx).ID(email.UID).Get(user); err != nil {
return err
} else if !has {
return ErrUserNotExist{
UID: email.UID,
}
return ErrUserNotExist{UID: email.UID}
}

ctx, committer, err := db.TxContext(ctx)
Expand Down Expand Up @@ -365,6 +362,21 @@ func MakeEmailPrimary(ctx context.Context, email *EmailAddress) error {
return committer.Commit()
}

// ChangeInactivePrimaryEmail replaces the inactive primary email of a given user
func ChangeInactivePrimaryEmail(ctx context.Context, uid int64, oldEmailAddr, newEmailAddr string) error {
return db.WithTx(ctx, func(ctx context.Context) error {
_, err := db.GetEngine(ctx).Where(builder.Eq{"uid": uid, "lower_email": strings.ToLower(oldEmailAddr)}).Delete(&EmailAddress{})
if err != nil {
return err
}
newEmail, err := InsertEmailAddress(ctx, &EmailAddress{UID: uid, Email: newEmailAddr})
if err != nil {
return err
}
return MakeInactiveEmailPrimary(ctx, newEmail.ID)
})
}

// VerifyActiveEmailCode verifies active email code when active account
func VerifyActiveEmailCode(ctx context.Context, code, email string) *EmailAddress {
minutes := setting.Service.ActiveCodeLives
Expand Down
27 changes: 9 additions & 18 deletions models/user/email_address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,22 @@ func TestIsEmailUsed(t *testing.T) {
func TestMakeEmailPrimary(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())

email := &user_model.EmailAddress{
Email: "user567890@example.com",
}
err := user_model.MakeEmailPrimary(db.DefaultContext, email)
err := user_model.MakeActiveEmailPrimary(db.DefaultContext, 9999999)
assert.Error(t, err)
assert.EqualError(t, err, user_model.ErrEmailAddressNotExist{Email: email.Email}.Error())
assert.ErrorIs(t, err, user_model.ErrEmailAddressNotExist{})

email = &user_model.EmailAddress{
Email: "user11@example.com",
}
err = user_model.MakeEmailPrimary(db.DefaultContext, email)
email := unittest.AssertExistsAndLoadBean(t, &user_model.EmailAddress{Email: "user11@example.com"})
err = user_model.MakeActiveEmailPrimary(db.DefaultContext, email.ID)
assert.Error(t, err)
assert.EqualError(t, err, user_model.ErrEmailNotActivated.Error())
assert.ErrorIs(t, err, user_model.ErrEmailAddressNotExist{}) // inactive email is considered as not exist for "MakeActiveEmailPrimary"

email = &user_model.EmailAddress{
Email: "user9999999@example.com",
}
err = user_model.MakeEmailPrimary(db.DefaultContext, email)
email = unittest.AssertExistsAndLoadBean(t, &user_model.EmailAddress{Email: "user9999999@example.com"})
err = user_model.MakeActiveEmailPrimary(db.DefaultContext, email.ID)
assert.Error(t, err)
assert.True(t, user_model.IsErrUserNotExist(err))

email = &user_model.EmailAddress{
Email: "user101@example.com",
}
err = user_model.MakeEmailPrimary(db.DefaultContext, email)
email = unittest.AssertExistsAndLoadBean(t, &user_model.EmailAddress{Email: "user101@example.com"})
err = user_model.MakeActiveEmailPrimary(db.DefaultContext, email.ID)
assert.NoError(t, err)

user, _ := user_model.GetUserByID(db.DefaultContext, int64(10))
Expand Down
3 changes: 3 additions & 0 deletions models/user/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"

"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util"

Expand All @@ -30,6 +31,8 @@ type SearchUserOptions struct {
Actor *User // The user doing the search
SearchByEmail bool // Search by email as well as username/full name

SupportedSortOrders container.Set[string] // if not nil, only allow to use the sort orders in this set

IsActive util.OptionalBool
IsAdmin util.OptionalBool
IsRestricted util.OptionalBool
Expand Down
3 changes: 3 additions & 0 deletions modules/actions/workflows.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,9 @@ func matchPullRequestEvent(gitRepo *git.Repository, commit *git.Commit, prPayloa
// all acts conditions should be satisfied
for cond, vals := range acts {
switch cond {
case "types":
// types have been checked
continue
case "branches":
refName := git.RefName(prPayload.PullRequest.Base.Ref)
patterns, err := workflowpattern.CompilePatterns(vals...)
Expand Down
Loading

0 comments on commit dd1ca6c

Please sign in to comment.