Skip to content

Commit

Permalink
Merge branch 'main' into clean-template-helper
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny authored Apr 7, 2023
2 parents 37f5766 + 17623bb commit e9d3619
Show file tree
Hide file tree
Showing 51 changed files with 569 additions and 253 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Build stage
FROM golang:1.20-alpine3.17 AS build-env
FROM docker.io/library/golang:1.20-alpine3.17 AS build-env

ARG GOPROXY
ENV GOPROXY ${GOPROXY:-direct}
Expand All @@ -23,7 +23,7 @@ RUN if [ -n "${GITEA_VERSION}" ]; then git checkout "${GITEA_VERSION}"; fi \
# Begin env-to-ini build
RUN go build contrib/environment-to-ini/environment-to-ini.go

FROM alpine:3.17
FROM docker.io/library/alpine:3.17
LABEL maintainer="[email protected]"

EXPOSE 22 3000
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile.rootless
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Build stage
FROM golang:1.20-alpine3.17 AS build-env
FROM docker.io/library/golang:1.20-alpine3.17 AS build-env

ARG GOPROXY
ENV GOPROXY ${GOPROXY:-direct}
Expand All @@ -23,7 +23,7 @@ RUN if [ -n "${GITEA_VERSION}" ]; then git checkout "${GITEA_VERSION}"; fi \
# Begin env-to-ini build
RUN go build contrib/environment-to-ini/environment-to-ini.go

FROM alpine:3.17
FROM docker.io/library/alpine:3.17
LABEL maintainer="[email protected]"

EXPOSE 2222 3000
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ generate-go: $(TAGS_PREREQ)

.PHONY: security-check
security-check:
go run $(GOVULNCHECK_PACKAGE) -v ./...
go run $(GOVULNCHECK_PACKAGE) ./...

$(EXECUTABLE): $(GO_SOURCES) $(TAGS_PREREQ)
CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) build $(GOFLAGS) $(EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@
Expand Down
33 changes: 0 additions & 33 deletions docs/content/doc/usage/push-options.en-us.md

This file was deleted.

33 changes: 0 additions & 33 deletions docs/content/doc/usage/push-options.zh-tw.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,18 +1,51 @@
---
date: "2020-07-06T16:00:00+02:00"
title: "Push To Create"
slug: "push-to-create"
title: "Usage: Push"
slug: "push"
weight: 15
toc: false
draft: false
menu:
sidebar:
parent: "usage"
name: "Push To Create"
name: "Push"
weight: 15
identifier: "push-to-create"
identifier: "push"
---

**Table of Contents**

{{< toc >}}

There are some additional features when pushing commits to Gitea server.

# Open PR through Push

When you push commits to a non-default branch for the first time,
you will receive a link you can click on to visit the compare page of your branch compared to your main branch.
From there, it's easy to create a pull request, even if you want to target another branch.

![Gitea Push Hint](/gitea-push-hint.png)

# Push Options

In Gitea `1.13`, support for some [push options](https://git-scm.com/docs/git-push#Documentation/git-push.txt--oltoptiongt)
were added.

## Supported Options

- `repo.private` (true|false) - Change the repository's visibility.

This is particularly useful when combined with push-to-create.

- `repo.template` (true|false) - Change whether the repository is a template.

Example of changing a repository's visibility to public:

```shell
git push -o repo.private=false -u origin main
```

# Push To Create

Push to create is a feature that allows you to push to a repository that does not exist yet in Gitea. This is useful for automation and for allowing users to create repositories without having to go through the web interface. This feature is disabled by default.
Expand All @@ -35,6 +68,4 @@ git push -u origin main

This assumes you are using an SSH remote, but you can also use HTTPS remotes as well.

## Push options (bonus)

Push-to-create will default to the visibility defined by `DEFAULT_PUSH_CREATE_PRIVATE` in `app.ini`. To explicitly set the visibility, you can use a [push option]({{< relref "doc/usage/push-options.en-us.md" >}}).
Push-to-create will default to the visibility defined by `DEFAULT_PUSH_CREATE_PRIVATE` in `app.ini`.
69 changes: 69 additions & 0 deletions docs/content/doc/usage/push.zh-tw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
date: "2020-07-06T16:00:00+02:00"
title: "使用: Push"
slug: "push"
weight: 15
toc: false
draft: false
menu:
sidebar:
parent: "usage"
name: "Push"
weight: 15
identifier: "push"
---

**Table of Contents**

{{< toc >}}

There are some additional features when pushing commits to Gitea server.

# Push Merge Hint

When you pushing commits to a non-default branch, you will get an information from
Gitea which is a link, you can click the link and go to a compare page. It's a quick
way to create a pull request or a code review yourself in the Gitea UI.

![Gitea Push Hint](/gitea-push-hint.png)

# Push Options

Gitea 從 `1.13` 版開始支援某些 [push options](https://git-scm.com/docs/git-push#Documentation/git-push.txt--oltoptiongt)

## 支援的 Options

- `repo.private` (true|false) - 修改儲存庫的可見性。

與 push-to-create 一起使用時特別有用。

- `repo.template` (true|false) - 修改儲存庫是否為範本儲存庫。

以下範例修改儲存庫的可見性為公開:

```shell
git push -o repo.private=false -u origin main
```

# Push To Create

Push to create is a feature that allows you to push to a repository that does not exist yet in Gitea. This is useful for automation and for allowing users to create repositories without having to go through the web interface. This feature is disabled by default.

## Enabling Push To Create

In the `app.ini` file, set `ENABLE_PUSH_CREATE_USER` to `true` and `ENABLE_PUSH_CREATE_ORG` to `true` if you want to allow users to create repositories in their own user account and in organizations they are a member of respectively. Restart Gitea for the changes to take effect. You can read more about these two options in the [Configuration Cheat Sheet]({{< relref "doc/administration/config-cheat-sheet.zh-tw.md#repository-repository" >}}).

## Using Push To Create

Assuming you have a git repository in the current directory, you can push to a repository that does not exist yet in Gitea by running the following command:

```shell
# Add the remote you want to push to
git remote add origin git@{domain}:{username}/{repo name that does not exist yet}.git

# push to the remote
git push -u origin main
```

This assumes you are using an SSH remote, but you can also use HTTPS remotes as well.
Binary file added docs/static/gitea-push-hint.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion models/actions/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type ActionRun struct {
TriggerUser *user_model.User `xorm:"-"`
Ref string
CommitSHA string
IsForkPullRequest bool
IsForkPullRequest bool // If this is triggered by a PR from a forked repository or an untrusted user, we need to check if it is approved and limit permissions when running the workflow.
NeedApproval bool // may need approval if it's a fork pull request
ApprovedBy int64 `xorm:"index"` // who approved
Event webhook_module.HookEventType
Expand Down
6 changes: 6 additions & 0 deletions models/fixtures/org_user.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,9 @@
uid: 31
org_id: 19
is_public: true

-
id: 14
uid: 5
org_id: 23
is_public: false
13 changes: 12 additions & 1 deletion models/fixtures/team.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,15 @@
num_repos: 0
num_members: 0
includes_all_repositories: false
can_create_org_repo: true
can_create_org_repo: true

-
id: 17
org_id: 23
lower_name: team14writeauth
name: team14WriteAuth
authorize: 2 # write
num_repos: 0
num_members: 1
includes_all_repositories: false
can_create_org_repo: true
6 changes: 6 additions & 0 deletions models/fixtures/team_unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,9 @@
team_id: 9
type: 1 # code
access_mode: 1

-
id: 46
team_id: 17
type: 9 # package
access_mode: 0
6 changes: 6 additions & 0 deletions models/fixtures/team_user.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,9 @@
org_id: 3
team_id: 14
uid: 2

-
id: 18
org_id: 23
team_id: 17
uid: 5
4 changes: 2 additions & 2 deletions models/fixtures/user.yml
Original file line number Diff line number Diff line change
Expand Up @@ -844,8 +844,8 @@
num_following: 0
num_stars: 0
num_repos: 2
num_teams: 1
num_members: 0
num_teams: 2
num_members: 1
visibility: 2
repo_admin_change_team_access: false
theme: ""
Expand Down
16 changes: 11 additions & 5 deletions models/organization/org_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,25 +212,31 @@ func TestGetOrgUsersByUserID(t *testing.T) {

orgUsers, err := organization.GetOrgUsersByUserID(5, &organization.SearchOrganizationsOptions{All: true})
assert.NoError(t, err)
if assert.Len(t, orgUsers, 2) {
if assert.Len(t, orgUsers, 3) {
assert.Equal(t, organization.OrgUser{
ID: orgUsers[0].ID,
OrgID: 6,
OrgID: 23,
UID: 5,
IsPublic: true,
IsPublic: false,
}, *orgUsers[0])
assert.Equal(t, organization.OrgUser{
ID: orgUsers[1].ID,
OrgID: 6,
UID: 5,
IsPublic: true,
}, *orgUsers[1])
assert.Equal(t, organization.OrgUser{
ID: orgUsers[2].ID,
OrgID: 7,
UID: 5,
IsPublic: false,
}, *orgUsers[1])
}, *orgUsers[2])
}

publicOrgUsers, err := organization.GetOrgUsersByUserID(5, &organization.SearchOrganizationsOptions{All: false})
assert.NoError(t, err)
assert.Len(t, publicOrgUsers, 1)
assert.Equal(t, *orgUsers[0], *publicOrgUsers[0])
assert.Equal(t, *orgUsers[1], *publicOrgUsers[0])

orgUsers, err = organization.GetOrgUsersByUserID(1, &organization.SearchOrganizationsOptions{All: true})
assert.NoError(t, err)
Expand Down
23 changes: 17 additions & 6 deletions models/repo/user_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,25 @@ func GetReviewers(ctx context.Context, repo *Repository, doerID, posterID int64)
return users, db.GetEngine(ctx).Where(cond).OrderBy(user_model.GetOrderByName()).Find(&users)
}

// GetIssuePosters returns all users that have authored an issue/pull request for the given repository
func GetIssuePosters(ctx context.Context, repo *Repository, isPull bool) ([]*user_model.User, error) {
users := make([]*user_model.User, 0, 8)
// GetIssuePostersWithSearch returns users with limit of 30 whose username started with prefix that have authored an issue/pull request for the given repository
// If isShowFullName is set to true, also include full name prefix search
func GetIssuePostersWithSearch(ctx context.Context, repo *Repository, isPull bool, search string, isShowFullName bool) ([]*user_model.User, error) {
users := make([]*user_model.User, 0, 30)
var prefixCond builder.Cond = builder.Like{"name", search + "%"}
if isShowFullName {
prefixCond = prefixCond.Or(builder.Like{"full_name", "%" + search + "%"})
}

cond := builder.In("`user`.id",
builder.Select("poster_id").From("issue").Where(
builder.Eq{"repo_id": repo.ID}.
And(builder.Eq{"is_pull": isPull}),
).GroupBy("poster_id"),
)
return users, db.GetEngine(ctx).Where(cond).OrderBy(user_model.GetOrderByName()).Find(&users)
).GroupBy("poster_id")).And(prefixCond)

return users, db.GetEngine(ctx).
Where(cond).
Cols("id", "name", "full_name", "avatar", "avatar_email", "use_custom_avatar").
OrderBy("name").
Limit(30).
Find(&users)
}
Loading

0 comments on commit e9d3619

Please sign in to comment.