Skip to content

Commit fe91485

Browse files
authored
Merge branch 'main' into fix/delete-action
2 parents 53aead1 + 6eb6783 commit fe91485

25 files changed

+436
-186
lines changed

docs/content/doc/usage/push-options.en-us.md

-33
This file was deleted.

docs/content/doc/usage/push-options.zh-tw.md

-33
This file was deleted.

docs/content/doc/usage/push-to-create.en-us.md docs/content/doc/usage/push.en-us.md

+38-7
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,51 @@
11
---
22
date: "2020-07-06T16:00:00+02:00"
3-
title: "Push To Create"
4-
slug: "push-to-create"
3+
title: "Usage: Push"
4+
slug: "push"
55
weight: 15
66
toc: false
77
draft: false
88
menu:
99
sidebar:
1010
parent: "usage"
11-
name: "Push To Create"
11+
name: "Push"
1212
weight: 15
13-
identifier: "push-to-create"
13+
identifier: "push"
1414
---
1515

16+
**Table of Contents**
17+
18+
{{< toc >}}
19+
20+
There are some additional features when pushing commits to Gitea server.
21+
22+
# Open PR through Push
23+
24+
When you push commits to a non-default branch for the first time,
25+
you will receive a link you can click on to visit the compare page of your branch compared to your main branch.
26+
From there, it's easy to create a pull request, even if you want to target another branch.
27+
28+
![Gitea Push Hint](/gitea-push-hint.png)
29+
30+
# Push Options
31+
32+
In Gitea `1.13`, support for some [push options](https://git-scm.com/docs/git-push#Documentation/git-push.txt--oltoptiongt)
33+
were added.
34+
35+
## Supported Options
36+
37+
- `repo.private` (true|false) - Change the repository's visibility.
38+
39+
This is particularly useful when combined with push-to-create.
40+
41+
- `repo.template` (true|false) - Change whether the repository is a template.
42+
43+
Example of changing a repository's visibility to public:
44+
45+
```shell
46+
git push -o repo.private=false -u origin main
47+
```
48+
1649
# Push To Create
1750

1851
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.
@@ -35,6 +68,4 @@ git push -u origin main
3568

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

38-
## Push options (bonus)
39-
40-
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" >}}).
71+
Push-to-create will default to the visibility defined by `DEFAULT_PUSH_CREATE_PRIVATE` in `app.ini`.

docs/content/doc/usage/push.zh-tw.md

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
date: "2020-07-06T16:00:00+02:00"
3+
title: "使用: Push"
4+
slug: "push"
5+
weight: 15
6+
toc: false
7+
draft: false
8+
menu:
9+
sidebar:
10+
parent: "usage"
11+
name: "Push"
12+
weight: 15
13+
identifier: "push"
14+
---
15+
16+
**Table of Contents**
17+
18+
{{< toc >}}
19+
20+
There are some additional features when pushing commits to Gitea server.
21+
22+
# Push Merge Hint
23+
24+
When you pushing commits to a non-default branch, you will get an information from
25+
Gitea which is a link, you can click the link and go to a compare page. It's a quick
26+
way to create a pull request or a code review yourself in the Gitea UI.
27+
28+
![Gitea Push Hint](/gitea-push-hint.png)
29+
30+
# Push Options
31+
32+
Gitea 從 `1.13` 版開始支援某些 [push options](https://git-scm.com/docs/git-push#Documentation/git-push.txt--oltoptiongt)
33+
34+
35+
## 支援的 Options
36+
37+
- `repo.private` (true|false) - 修改儲存庫的可見性。
38+
39+
與 push-to-create 一起使用時特別有用。
40+
41+
- `repo.template` (true|false) - 修改儲存庫是否為範本儲存庫。
42+
43+
以下範例修改儲存庫的可見性為公開:
44+
45+
```shell
46+
git push -o repo.private=false -u origin main
47+
```
48+
49+
# Push To Create
50+
51+
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.
52+
53+
## Enabling Push To Create
54+
55+
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" >}}).
56+
57+
## Using Push To Create
58+
59+
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:
60+
61+
```shell
62+
# Add the remote you want to push to
63+
git remote add origin git@{domain}:{username}/{repo name that does not exist yet}.git
64+
65+
# push to the remote
66+
git push -u origin main
67+
```
68+
69+
This assumes you are using an SSH remote, but you can also use HTTPS remotes as well.

docs/static/gitea-push-hint.png

412 KB
Loading

models/repo/user_repo.go

+17-6
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,25 @@ func GetReviewers(ctx context.Context, repo *Repository, doerID, posterID int64)
155155
return users, db.GetEngine(ctx).Where(cond).OrderBy(user_model.GetOrderByName()).Find(&users)
156156
}
157157

158-
// GetIssuePosters returns all users that have authored an issue/pull request for the given repository
159-
func GetIssuePosters(ctx context.Context, repo *Repository, isPull bool) ([]*user_model.User, error) {
160-
users := make([]*user_model.User, 0, 8)
158+
// GetIssuePostersWithSearch returns users with limit of 30 whose username started with prefix that have authored an issue/pull request for the given repository
159+
// If isShowFullName is set to true, also include full name prefix search
160+
func GetIssuePostersWithSearch(ctx context.Context, repo *Repository, isPull bool, search string, isShowFullName bool) ([]*user_model.User, error) {
161+
users := make([]*user_model.User, 0, 30)
162+
var prefixCond builder.Cond = builder.Like{"name", search + "%"}
163+
if isShowFullName {
164+
prefixCond = prefixCond.Or(builder.Like{"full_name", "%" + search + "%"})
165+
}
166+
161167
cond := builder.In("`user`.id",
162168
builder.Select("poster_id").From("issue").Where(
163169
builder.Eq{"repo_id": repo.ID}.
164170
And(builder.Eq{"is_pull": isPull}),
165-
).GroupBy("poster_id"),
166-
)
167-
return users, db.GetEngine(ctx).Where(cond).OrderBy(user_model.GetOrderByName()).Find(&users)
171+
).GroupBy("poster_id")).And(prefixCond)
172+
173+
return users, db.GetEngine(ctx).
174+
Where(cond).
175+
Cols("id", "name", "full_name", "avatar", "avatar_email", "use_custom_avatar").
176+
OrderBy("name").
177+
Limit(30).
178+
Find(&users)
168179
}

options/locale/locale_en-US.ini

+1
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,7 @@ delete_preexisting = Delete pre-existing files
933933
delete_preexisting_content = Delete files in %s
934934
delete_preexisting_success = Deleted unadopted files in %s
935935
blame_prior = View blame prior to this change
936+
author_search_tooltip = Shows a maximum of 30 users
936937
937938
transfer.accept = Accept Transfer
938939
transfer.accept_desc = Transfer to "%s"

options/locale/locale_si-LK.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1168,7 +1168,7 @@ issues.ref_pull_from=<a href="%[3]s">මෙම අදින්න ඉල්ල
11681168
issues.ref_closing_from=<a href="%[3]s">මෙම ගැටළුව වසා දමනු ඇත%[4]s මෙම ගැටළුව</a> <a id="%[1]s" href="#%[1]s">%[2]s</a>
11691169
issues.ref_reopening_from=<a href="%[3]s">මෙම ගැටළුව නැවත විවෘත කරනු ඇත%[4]s මෙම ගැටළුව</a> <a id="%[1]s" href="#%[1]s">%[2]s</a>
11701170
issues.ref_closed_from=<a href="%[3]s">මෙම නිකුතුව%[4]s</a> <a id="%[1]s" href="#%[1]s">%[2]s</a>
1171-
issues.ref_reopened_from=<a href="%[3]s">මෙම නිකුතුව%[4]s</a> <a id="%[1]s" href="#%[1]s">%[2]s</a>
1171+
issues.ref_reopened_from=<a href="%[3]s">මෙම නිකුතුව%[4]s</a> <a id="%[1]s" href="#%[1]s">%[2]s</a>නැවත විවෘත කරන ලදි
11721172
issues.ref_from=`හිම%[1]s`
11731173
issues.poster=පෝස්ටර්
11741174
issues.collaborator=සහයෝගීතාව

options/locale/locale_zh-CN.ini

+1
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,7 @@ download_file=下载文件
11041104
normal_view=普通视图
11051105
line=行
11061106
lines=行
1107+
from_comment=(评论)
11071108

11081109
editor.add_file=添加文件
11091110
editor.new_file=新建文件

routers/web/repo/helper.go

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2023 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package repo
5+
6+
import (
7+
"sort"
8+
9+
"code.gitea.io/gitea/models/user"
10+
"code.gitea.io/gitea/modules/context"
11+
)
12+
13+
func makeSelfOnTop(ctx *context.Context, users []*user.User) []*user.User {
14+
if ctx.Doer != nil {
15+
sort.Slice(users, func(i, j int) bool {
16+
if users[i].ID == users[j].ID {
17+
return false
18+
}
19+
return users[i].ID == ctx.Doer.ID // if users[i] is self, put it before others, so less=true
20+
})
21+
}
22+
return users
23+
}

routers/web/repo/helper_test.go

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2023 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package repo
5+
6+
import (
7+
"testing"
8+
9+
"code.gitea.io/gitea/models/user"
10+
"code.gitea.io/gitea/modules/context"
11+
12+
"github.com/stretchr/testify/assert"
13+
)
14+
15+
func TestMakeSelfOnTop(t *testing.T) {
16+
users := makeSelfOnTop(&context.Context{}, []*user.User{{ID: 2}, {ID: 1}})
17+
assert.Len(t, users, 2)
18+
assert.EqualValues(t, 2, users[0].ID)
19+
20+
users = makeSelfOnTop(&context.Context{Doer: &user.User{ID: 1}}, []*user.User{{ID: 2}, {ID: 1}})
21+
assert.Len(t, users, 2)
22+
assert.EqualValues(t, 1, users[0].ID)
23+
24+
users = makeSelfOnTop(&context.Context{Doer: &user.User{ID: 2}}, []*user.User{{ID: 2}, {ID: 1}})
25+
assert.Len(t, users, 2)
26+
assert.EqualValues(t, 2, users[0].ID)
27+
}

routers/web/repo/issue.go

+49-10
Original file line numberDiff line numberDiff line change
@@ -303,17 +303,12 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
303303
ctx.Data["CommitStatuses"] = commitStatuses
304304

305305
// Get assignees.
306-
ctx.Data["Assignees"], err = repo_model.GetRepoAssignees(ctx, repo)
306+
assigneeUsers, err := repo_model.GetRepoAssignees(ctx, repo)
307307
if err != nil {
308-
ctx.ServerError("GetAssignees", err)
309-
return
310-
}
311-
312-
ctx.Data["Posters"], err = repo_model.GetIssuePosters(ctx, repo, isPullOption.IsTrue())
313-
if err != nil {
314-
ctx.ServerError("GetIssuePosters", err)
308+
ctx.ServerError("GetRepoAssignees", err)
315309
return
316310
}
311+
ctx.Data["Assignees"] = makeSelfOnTop(ctx, assigneeUsers)
317312

318313
handleTeamMentions(ctx)
319314
if ctx.Written() {
@@ -479,11 +474,12 @@ func RetrieveRepoMilestonesAndAssignees(ctx *context.Context, repo *repo_model.R
479474
return
480475
}
481476

482-
ctx.Data["Assignees"], err = repo_model.GetRepoAssignees(ctx, repo)
477+
assigneeUsers, err := repo_model.GetRepoAssignees(ctx, repo)
483478
if err != nil {
484-
ctx.ServerError("GetAssignees", err)
479+
ctx.ServerError("GetRepoAssignees", err)
485480
return
486481
}
482+
ctx.Data["Assignees"] = makeSelfOnTop(ctx, assigneeUsers)
487483

488484
handleTeamMentions(ctx)
489485
}
@@ -3354,3 +3350,46 @@ func handleTeamMentions(ctx *context.Context) {
33543350
ctx.Data["MentionableTeamsOrg"] = ctx.Repo.Owner.Name
33553351
ctx.Data["MentionableTeamsOrgAvatar"] = ctx.Repo.Owner.AvatarLink(ctx)
33563352
}
3353+
3354+
type userSearchInfo struct {
3355+
UserID int64 `json:"user_id"`
3356+
UserName string `json:"username"`
3357+
AvatarLink string `json:"avatar_link"`
3358+
FullName string `json:"full_name"`
3359+
}
3360+
3361+
type userSearchResponse struct {
3362+
Results []*userSearchInfo `json:"results"`
3363+
}
3364+
3365+
// IssuePosters get posters for current repo's issues/pull requests
3366+
func IssuePosters(ctx *context.Context) {
3367+
repo := ctx.Repo.Repository
3368+
isPullList := ctx.Params(":type") == "pulls"
3369+
search := strings.TrimSpace(ctx.FormString("q"))
3370+
posters, err := repo_model.GetIssuePostersWithSearch(ctx, repo, isPullList, search, setting.UI.DefaultShowFullName)
3371+
if err != nil {
3372+
ctx.JSON(http.StatusInternalServerError, err)
3373+
return
3374+
}
3375+
3376+
if search == "" && ctx.Doer != nil {
3377+
// the returned posters slice only contains limited number of users,
3378+
// to make the current user (doer) can quickly filter their own issues, always add doer to the posters slice
3379+
if !util.SliceContainsFunc(posters, func(user *user_model.User) bool { return user.ID == ctx.Doer.ID }) {
3380+
posters = append(posters, ctx.Doer)
3381+
}
3382+
}
3383+
3384+
posters = makeSelfOnTop(ctx, posters)
3385+
3386+
resp := &userSearchResponse{}
3387+
resp.Results = make([]*userSearchInfo, len(posters))
3388+
for i, user := range posters {
3389+
resp.Results[i] = &userSearchInfo{UserID: user.ID, UserName: user.Name, AvatarLink: user.AvatarLink(ctx)}
3390+
if setting.UI.DefaultShowFullName {
3391+
resp.Results[i].FullName = user.FullName
3392+
}
3393+
}
3394+
ctx.JSON(http.StatusOK, resp)
3395+
}

0 commit comments

Comments
 (0)