Skip to content

Commit 202a5bf

Browse files
authored
Merge branch 'master' into fix-13996-webhook-migration
2 parents 9325b77 + 80a299d commit 202a5bf

File tree

18 files changed

+153
-61
lines changed

18 files changed

+153
-61
lines changed

.github/issue_template.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
<!--
44
1. Please speak English, this is the language all maintainers can speak and write.
5-
2. Please ask questions or configuration/deploy problems on our Discord
5+
2. Please ask questions or configuration/deploy problems on our Discord
66
server (https://discord.gg/gitea) or forum (https://discourse.gitea.io).
77
3. Please take a moment to check that your issue doesn't already exist.
8-
4. Please give all relevant information below for bug reports, because
8+
4. Make sure it's not mentioned in the FAQ (https://docs.gitea.io/en-us/faq)
9+
5. Please give all relevant information below for bug reports, because
910
incomplete details will be handled as an invalid report.
1011
-->
1112

cmd/admin.go

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"errors"
1111
"fmt"
1212
"os"
13+
"strings"
1314
"text/tabwriter"
1415

1516
"code.gitea.io/gitea/models"
@@ -125,9 +126,22 @@ var (
125126
}
126127

127128
microcmdUserDelete = cli.Command{
128-
Name: "delete",
129-
Usage: "Delete specific user",
130-
Flags: []cli.Flag{idFlag},
129+
Name: "delete",
130+
Usage: "Delete specific user by id, name or email",
131+
Flags: []cli.Flag{
132+
cli.Int64Flag{
133+
Name: "id",
134+
Usage: "ID of user of the user to delete",
135+
},
136+
cli.StringFlag{
137+
Name: "username,u",
138+
Usage: "Username of the user to delete",
139+
},
140+
cli.StringFlag{
141+
Name: "email,e",
142+
Usage: "Email of the user to delete",
143+
},
144+
},
131145
Action: runDeleteUser,
132146
}
133147

@@ -463,18 +477,33 @@ func runListUsers(c *cli.Context) error {
463477
}
464478

465479
func runDeleteUser(c *cli.Context) error {
466-
if !c.IsSet("id") {
467-
return fmt.Errorf("--id flag is missing")
480+
if !c.IsSet("id") && !c.IsSet("username") && !c.IsSet("email") {
481+
return fmt.Errorf("You must provide the id, username or email of a user to delete")
468482
}
469483

470484
if err := initDB(); err != nil {
471485
return err
472486
}
473487

474-
user, err := models.GetUserByID(c.Int64("id"))
488+
var err error
489+
var user *models.User
490+
if c.IsSet("email") {
491+
user, err = models.GetUserByEmail(c.String("email"))
492+
} else if c.IsSet("username") {
493+
user, err = models.GetUserByName(c.String("username"))
494+
} else {
495+
user, err = models.GetUserByID(c.Int64("id"))
496+
}
475497
if err != nil {
476498
return err
477499
}
500+
if c.IsSet("username") && user.LowerName != strings.ToLower(strings.TrimSpace(c.String("username"))) {
501+
return fmt.Errorf("The user %s who has email %s does not match the provided username %s", user.Name, c.String("email"), c.String("username"))
502+
}
503+
504+
if c.IsSet("id") && user.ID != c.Int64("id") {
505+
return fmt.Errorf("The user %s does not match the provided id %d", user.Name, c.Int64("id"))
506+
}
478507

479508
return models.DeleteUser(user)
480509
}

custom/conf/app.example.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ PROJECT_BOARD_BASIC_KANBAN_TYPE = To Do, In Progress, Done
1717
PROJECT_BOARD_BUG_TRIAGE_TYPE = Needs Triage, High Priority, Low Priority, Closed
1818

1919
[repository]
20+
; Root path for storing all repository data. It must be an absolute path. By default it is stored in a sub-directory of `APP_DATA_PATH`.
2021
ROOT =
22+
; The script type this server supports. Usually this is `bash`, but some users report that only `sh` is available.
2123
SCRIPT_TYPE = bash
2224
; DETECTED_CHARSETS_ORDER tie-break order for detected charsets.
2325
; If the charsets have equal confidence, tie-breaking will be done by order in this list

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
4242

4343
## Repository (`repository`)
4444

45-
- `ROOT`: **~/gitea-repositories/**: Root path for storing all repository data. It must be
46-
an absolute path.
45+
- `ROOT`: **data/gitea-repositories/**: Root path for storing all repository data. It must be
46+
an absolute path. By default it is stored in a sub-directory of `APP_DATA_PATH`.
4747
- `SCRIPT_TYPE`: **bash**: The script type this server supports. Usually this is `bash`,
4848
but some users report that only `sh` is available.
4949
- `DETECTED_CHARSETS_ORDER`: **UTF-8, UTF-16BE, UTF-16LE, UTF-32BE, UTF-32LE, ISO-8859, windows-1252, ISO-8859, windows-1250, ISO-8859, ISO-8859, ISO-8859, windows-1253, ISO-8859, windows-1255, ISO-8859, windows-1251, windows-1256, KOI8-R, ISO-8859, windows-1254, Shift_JIS, GB18030, EUC-JP, EUC-KR, Big5, ISO-2022, ISO-2022, ISO-2022, IBM424_rtl, IBM424_ltr, IBM420_rtl, IBM420_ltr**: Tie-break order of detected charsets - if the detected charsets have equal confidence, charsets earlier in the list will be chosen in preference to those later. Adding `defaults` will place the unnamed charsets at that point.

docs/content/doc/help/faq.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ https://github.com/loganinak/MigrateGitlabToGogs
6464
- Windows: Environment variable `USERPROFILE`, else environment variables `HOMEDRIVE`+`HOMEPATH`
6565
- RepoRootPath
6666
- `ROOT` in `app.ini`
67-
- Else `%(HomeDir)/gitea-repositories`
67+
- Else `%(AppDataPath)/gitea-repositories`
6868
- INI (config file)
6969
- `-c` flag
7070
- Else `%(CustomPath)/conf/app.ini`

docs/content/doc/installation/with-docker.en-us.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ services:
9191
- /etc/timezone:/etc/timezone:ro
9292
- /etc/localtime:/etc/localtime:ro
9393
ports:
94-
- - "3000:3000"
95-
- - "222:22"
96-
+ - "8080:3000"
97-
+ - "2221:22"
94+
- - "3000:3000"
95+
- - "222:22"
96+
+ - "8080:3000"
97+
+ - "2221:22"
9898
```
9999

100100
## Databases
@@ -118,11 +118,11 @@ services:
118118
environment:
119119
- USER_UID=1000
120120
- USER_GID=1000
121-
+ - DB_TYPE=mysql
122-
+ - DB_HOST=db:3306
123-
+ - DB_NAME=gitea
124-
+ - DB_USER=gitea
125-
+ - DB_PASSWD=gitea
121+
+ - DB_TYPE=mysql
122+
+ - DB_HOST=db:3306
123+
+ - DB_NAME=gitea
124+
+ - DB_USER=gitea
125+
+ - DB_PASSWD=gitea
126126
restart: always
127127
networks:
128128
- gitea
@@ -169,11 +169,11 @@ services:
169169
environment:
170170
- USER_UID=1000
171171
- USER_GID=1000
172-
+ - DB_TYPE=postgres
173-
+ - DB_HOST=db:5432
174-
+ - DB_NAME=gitea
175-
+ - DB_USER=gitea
176-
+ - DB_PASSWD=gitea
172+
+ - DB_TYPE=postgres
173+
+ - DB_HOST=db:5432
174+
+ - DB_NAME=gitea
175+
+ - DB_USER=gitea
176+
+ - DB_PASSWD=gitea
177177
restart: always
178178
networks:
179179
- gitea
@@ -226,8 +226,8 @@ services:
226226
networks:
227227
- gitea
228228
volumes:
229-
- - ./gitea:/data
230-
+ - gitea:/data
229+
- - ./gitea:/data
230+
+ - gitea:/data
231231
- /etc/timezone:/etc/timezone:ro
232232
- /etc/localtime:/etc/localtime:ro
233233
ports:

docs/content/doc/usage/command-line.en-us.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ Admin operations:
6969
- `gitea admin user list`
7070
- `delete`:
7171
- Options:
72-
- `--id`: ID of user to be deleted. Required.
72+
- `--email`: Email of the user to be deleted.
73+
- `--username`: Username of user to be deleted.
74+
- `--id`: ID of user to be deleted.
75+
- One of `--id`, `--username` or `--email` is required. If more than one is provided then all have to match.
7376
- Examples:
7477
- `gitea admin user delete --id 1`
7578
- `create`: - Options: - `--name value`: Username. Required. As of gitea 1.9.0, use the `--username` flag instead. - `--username value`: Username. Required. New in gitea 1.9.0. - `--password value`: Password. Required. - `--email value`: Email. Required. - `--admin`: If provided, this makes the user an admin. Optional. - `--access-token`: If provided, an access token will be created for the user. Optional. (default: false). - `--must-change-password`: If provided, the created user will be required to choose a newer password after

models/user.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ func (u *User) GetOwnedOrganizations() (err error) {
538538
}
539539

540540
// GetOrganizations returns paginated organizations that user belongs to.
541+
// TODO: does not respect All and show orgs you privately participate
541542
func (u *User) GetOrganizations(opts *SearchOrganizationsOptions) error {
542543
sess := x.NewSession()
543544
defer sess.Close()

modules/git/command.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ func (c *Command) RunInDirTimeoutEnvFullPipelineFunc(env []string, timeout time.
153153
err := fn(ctx, cancel)
154154
if err != nil {
155155
cancel()
156+
_ = cmd.Wait()
156157
return err
157158
}
158159
}

modules/setting/repository.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import (
1010
"strings"
1111

1212
"code.gitea.io/gitea/modules/log"
13-
14-
"github.com/unknwon/com"
1513
)
1614

1715
// enumerates all the policy repository creating
@@ -249,19 +247,14 @@ var (
249247
)
250248

251249
func newRepository() {
252-
homeDir, err := com.HomeDir()
253-
if err != nil {
254-
log.Fatal("Failed to get home directory: %v", err)
255-
}
256-
homeDir = strings.ReplaceAll(homeDir, "\\", "/")
257-
250+
var err error
258251
// Determine and create root git repository path.
259252
sec := Cfg.Section("repository")
260253
Repository.DisableHTTPGit = sec.Key("DISABLE_HTTP_GIT").MustBool()
261254
Repository.UseCompatSSHURI = sec.Key("USE_COMPAT_SSH_URI").MustBool()
262255
Repository.MaxCreationLimit = sec.Key("MAX_CREATION_LIMIT").MustInt(-1)
263256
Repository.DefaultBranch = sec.Key("DEFAULT_BRANCH").MustString(Repository.DefaultBranch)
264-
RepoRootPath = sec.Key("ROOT").MustString(path.Join(homeDir, "gitea-repositories"))
257+
RepoRootPath = sec.Key("ROOT").MustString(path.Join(AppDataPath, "gitea-repositories"))
265258
forcePathSeparator(RepoRootPath)
266259
if !filepath.IsAbs(RepoRootPath) {
267260
RepoRootPath = filepath.Join(AppWorkPath, RepoRootPath)

routers/api/v1/org/org.go

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,28 @@ import (
1717
"code.gitea.io/gitea/routers/api/v1/utils"
1818
)
1919

20-
func listUserOrgs(ctx *context.APIContext, u *models.User, all bool) {
21-
if err := u.GetOrganizations(&models.SearchOrganizationsOptions{
22-
ListOptions: utils.GetListOptions(ctx),
23-
All: all,
24-
}); err != nil {
25-
ctx.Error(http.StatusInternalServerError, "GetOrganizations", err)
20+
func listUserOrgs(ctx *context.APIContext, u *models.User) {
21+
22+
listOptions := utils.GetListOptions(ctx)
23+
showPrivate := ctx.IsSigned && (ctx.User.IsAdmin || ctx.User.ID == u.ID)
24+
25+
orgs, err := models.GetOrgsByUserID(u.ID, showPrivate)
26+
if err != nil {
27+
ctx.Error(http.StatusInternalServerError, "GetOrgsByUserID", err)
2628
return
2729
}
30+
maxResults := len(orgs)
31+
32+
orgs = utils.PaginateUserSlice(orgs, listOptions.Page, listOptions.PageSize)
2833

29-
apiOrgs := make([]*api.Organization, len(u.Orgs))
30-
for i := range u.Orgs {
31-
apiOrgs[i] = convert.ToOrganization(u.Orgs[i])
34+
apiOrgs := make([]*api.Organization, len(orgs))
35+
for i := range orgs {
36+
apiOrgs[i] = convert.ToOrganization(orgs[i])
3237
}
38+
39+
ctx.SetLinkHeader(int(maxResults), listOptions.PageSize)
40+
ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", maxResults))
41+
ctx.Header().Set("Access-Control-Expose-Headers", "X-Total-Count, Link")
3342
ctx.JSON(http.StatusOK, &apiOrgs)
3443
}
3544

@@ -53,7 +62,7 @@ func ListMyOrgs(ctx *context.APIContext) {
5362
// "200":
5463
// "$ref": "#/responses/OrganizationList"
5564

56-
listUserOrgs(ctx, ctx.User, true)
65+
listUserOrgs(ctx, ctx.User)
5766
}
5867

5968
// ListUserOrgs list user's orgs
@@ -85,7 +94,7 @@ func ListUserOrgs(ctx *context.APIContext) {
8594
if ctx.Written() {
8695
return
8796
}
88-
listUserOrgs(ctx, u, ctx.User != nil && (ctx.User.IsAdmin || ctx.User.ID == u.ID))
97+
listUserOrgs(ctx, u)
8998
}
9099

91100
// GetAll return list of all public organizations

routers/api/v1/utils/utils.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,22 @@ func GetListOptions(ctx *context.APIContext) models.ListOptions {
6666
PageSize: convert.ToCorrectPageSize(ctx.QueryInt("limit")),
6767
}
6868
}
69+
70+
// PaginateUserSlice cut a slice of Users as per pagination options
71+
// TODO: make it generic
72+
func PaginateUserSlice(items []*models.User, page, pageSize int) []*models.User {
73+
if page != 0 {
74+
page--
75+
}
76+
77+
if page*pageSize >= len(items) {
78+
return items[len(items):]
79+
}
80+
81+
items = items[page*pageSize:]
82+
83+
if len(items) > pageSize {
84+
return items[:pageSize]
85+
}
86+
return items
87+
}

services/pull/review.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,16 +167,16 @@ func createCodeComment(doer *models.User, repo *models.Repository, issue *models
167167

168168
// Only fetch diff if comment is review comment
169169
if len(patch) == 0 && reviewID != 0 {
170+
headCommitID, err := gitRepo.GetRefCommitID(pr.GetGitRefName())
171+
if err != nil {
172+
return nil, fmt.Errorf("GetRefCommitID[%s]: %v", pr.GetGitRefName(), err)
173+
}
170174
if len(commitID) == 0 {
171-
commitID, err = gitRepo.GetRefCommitID(pr.GetGitRefName())
172-
if err != nil {
173-
return nil, fmt.Errorf("GetRefCommitID[%s]: %v", pr.GetGitRefName(), err)
174-
}
175+
commitID = headCommitID
175176
}
176-
177177
patchBuf := new(bytes.Buffer)
178-
if err := git.GetRepoRawDiffForFile(gitRepo, pr.MergeBase, commitID, git.RawDiffNormal, treePath, patchBuf); err != nil {
179-
return nil, fmt.Errorf("GetRawDiffForLine[%s, %s, %s, %s]: %v", gitRepo.Path, pr.MergeBase, commitID, treePath, err)
178+
if err := git.GetRepoRawDiffForFile(gitRepo, pr.MergeBase, headCommitID, git.RawDiffNormal, treePath, patchBuf); err != nil {
179+
return nil, fmt.Errorf("GetRawDiffForLine[%s, %s, %s, %s]: %v", gitRepo.Path, pr.MergeBase, headCommitID, treePath, err)
180180
}
181181
patch = git.CutDiffAroundLine(patchBuf, int64((&models.Comment{Line: line}).UnsignedLine()), line < 0, setting.UI.CodeCommentLines)
182182
}

services/release/release.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,15 @@ func DeleteReleaseByID(id int64, doer *models.User, delTag bool) error {
152152
return fmt.Errorf("git tag -d: %v", err)
153153
}
154154

155+
notification.NotifyPushCommits(
156+
doer, repo,
157+
&repository.PushUpdateOptions{
158+
RefFullName: git.TagPrefix + rel.TagName,
159+
OldCommitID: rel.Sha1,
160+
NewCommitID: git.EmptySHA,
161+
}, repository.NewPushCommits())
162+
notification.NotifyDeleteRef(doer, repo, "tag", git.TagPrefix+rel.TagName)
163+
155164
if err := models.DeleteReleaseByID(id); err != nil {
156165
return fmt.Errorf("DeleteReleaseByID: %v", err)
157166
}

services/repository/push.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
9696
return fmt.Errorf("Old and new revisions are both %s", git.EmptySHA)
9797
}
9898
var commits = &repo_module.PushCommits{}
99-
if opts.IsTag() { // If is tag reference {
99+
if opts.IsTag() { // If is tag reference
100100
if pusher == nil || pusher.ID != opts.PusherID {
101101
var err error
102102
if pusher, err = models.GetUserByID(opts.PusherID); err != nil {
@@ -105,9 +105,25 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
105105
}
106106
tagName := opts.TagName()
107107
if opts.IsDelRef() {
108+
notification.NotifyPushCommits(
109+
pusher, repo,
110+
&repo_module.PushUpdateOptions{
111+
RefFullName: git.TagPrefix + tagName,
112+
OldCommitID: opts.OldCommitID,
113+
NewCommitID: git.EmptySHA,
114+
}, repo_module.NewPushCommits())
115+
108116
delTags = append(delTags, tagName)
109117
notification.NotifyDeleteRef(pusher, repo, "tag", opts.RefFullName)
110118
} else { // is new tag
119+
notification.NotifyPushCommits(
120+
pusher, repo,
121+
&repo_module.PushUpdateOptions{
122+
RefFullName: git.TagPrefix + tagName,
123+
OldCommitID: git.EmptySHA,
124+
NewCommitID: opts.NewCommitID,
125+
}, repo_module.NewPushCommits())
126+
111127
addTags = append(addTags, tagName)
112128
notification.NotifyCreateRef(pusher, repo, "tag", opts.RefFullName)
113129
}

snap/snapcraft.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ architectures:
1818

1919
environment:
2020
GITEA_CUSTOM: "$SNAP_COMMON"
21-
GITEA_WORK_DIR: "$SNAP_DATA"
21+
GITEA_WORK_DIR: "$SNAP_COMMON"
2222
GIT_TEMPLATE_DIR: "$SNAP/usr/share/git-core/templates"
2323
GIT_EXEC_PATH: "$SNAP/usr/lib/git-core"
2424

0 commit comments

Comments
 (0)