Skip to content

Commit 8ccc9d3

Browse files
authored
Merge branch 'master' into merged-status
2 parents 976737c + 66379ba commit 8ccc9d3

File tree

25 files changed

+199
-128
lines changed

25 files changed

+199
-128
lines changed

MAINTAINERS

+1
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ David Svantesson <[email protected]> (@davidsvantesson)
3939
CirnoT <[email protected]> (@CirnoT)
4040
a1012112796 <[email protected]> (@a1012112796)
4141
Karl Heinz Marbaise <[email protected]> (@khmarbaise)
42+
Norwin Roosen <[email protected]> (@noerw)

custom/conf/app.example.ini

+2
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

+2-2
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

+1-1
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/usage/fail2ban-setup.en-us.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,27 @@ on a bad authentication from the web or CLI using SSH or HTTP respectively:
2525
```log
2626
2018/04/26 18:15:54 [I] Failed authentication attempt for user from xxx.xxx.xxx.xxx
2727
```
28+
29+
```log
30+
2020/10/15 16:05:09 modules/ssh/ssh.go:143:publicKeyHandler() [W] Failed authentication attempt from xxx.xxx.xxx.xxx
31+
```
32+
33+
```log
34+
2020/10/15 16:05:09 modules/ssh/ssh.go:155:publicKeyHandler() [W] Failed authentication attempt from xxx.xxx.xxx.xxx
35+
```
36+
2837
```log
29-
2020/10/15 16:05:09 modules/ssh/ssh.go:188:publicKeyHandler() [E] SearchPublicKeyByContent: public key does not exist [id: 0] Failed authentication attempt from xxx.xxx.xxx.xxx
38+
2020/10/15 16:05:09 modules/ssh/ssh.go:198:publicKeyHandler() [W] Failed authentication attempt from xxx.xxx.xxx.xxx
3039
```
40+
41+
```log
42+
2020/10/15 16:05:09 modules/ssh/ssh.go:213:publicKeyHandler() [W] Failed authentication attempt from xxx.xxx.xxx.xxx
43+
```
44+
45+
```log
46+
2020/10/15 16:05:09 modules/ssh/ssh.go:227:publicKeyHandler() [W] Failed authentication attempt from xxx.xxx.xxx.xxx
47+
```
48+
3149
```log
3250
2020/10/15 16:08:44 ...s/context/context.go:204:HandleText() [E] invalid credentials from xxx.xxx.xxx.xxx
3351
```

models/action.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"time"
1414

1515
"code.gitea.io/gitea/modules/base"
16+
"code.gitea.io/gitea/modules/git"
1617
"code.gitea.io/gitea/modules/log"
1718
"code.gitea.io/gitea/modules/setting"
1819
"code.gitea.io/gitea/modules/timeutil"
@@ -238,7 +239,7 @@ func (a *Action) getCommentLink(e Engine) string {
238239

239240
// GetBranch returns the action's repository branch.
240241
func (a *Action) GetBranch() string {
241-
return a.RefName
242+
return strings.TrimPrefix(a.RefName, git.BranchPrefix)
242243
}
243244

244245
// GetContent returns the action's content.

modules/setting/repository.go

+2-9
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)

modules/ssh/ssh.go

+43-7
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,25 @@ func sessionHandler(session ssh.Session) {
134134
}
135135

136136
func publicKeyHandler(ctx ssh.Context, key ssh.PublicKey) bool {
137+
if log.IsDebug() { // <- FingerprintSHA256 is kinda expensive so only calculate it if necessary
138+
log.Debug("Handle Public Key: Fingerprint: %s from %s", gossh.FingerprintSHA256(key), ctx.RemoteAddr())
139+
}
140+
137141
if ctx.User() != setting.SSH.BuiltinServerUser {
138-
log.Warn("Permission Denied: Invalid SSH username %s - must use %s for all git operations via ssh", ctx.User(), setting.SSH.BuiltinServerUser)
142+
log.Warn("Invalid SSH username %s - must use %s for all git operations via ssh", ctx.User(), setting.SSH.BuiltinServerUser)
143+
log.Warn("Failed authentication attempt from %s", ctx.RemoteAddr())
139144
return false
140145
}
141146

142147
// check if we have a certificate
143148
if cert, ok := key.(*gossh.Certificate); ok {
149+
if log.IsDebug() { // <- FingerprintSHA256 is kinda expensive so only calculate it if necessary
150+
log.Debug("Handle Certificate: %s Fingerprint: %s is a certificate", ctx.RemoteAddr(), gossh.FingerprintSHA256(key))
151+
}
152+
144153
if len(setting.SSH.TrustedUserCAKeys) == 0 {
154+
log.Warn("Certificate Rejected: No trusted certificate authorities for this server")
155+
log.Warn("Failed authentication attempt from %s", ctx.RemoteAddr())
145156
return false
146157
}
147158

@@ -151,7 +162,7 @@ func publicKeyHandler(ctx ssh.Context, key ssh.PublicKey) bool {
151162
pkey, err := models.SearchPublicKeyByContentExact(principal)
152163
if err != nil {
153164
if models.IsErrKeyNotExist(err) {
154-
log.Debug("Principal Rejected: Unknown Principal: %s", principal)
165+
log.Debug("Principal Rejected: %s Unknown Principal: %s", ctx.RemoteAddr(), principal)
155166
continue principalLoop
156167
}
157168
log.Error("SearchPublicKeyByContentExact: %v", err)
@@ -172,33 +183,58 @@ func publicKeyHandler(ctx ssh.Context, key ssh.PublicKey) bool {
172183

173184
// check the CA of the cert
174185
if !c.IsUserAuthority(cert.SignatureKey) {
175-
log.Debug("Principal Rejected: Untrusted Authority Signature Fingerprint %s for Principal: %s", gossh.FingerprintSHA256(cert.SignatureKey), principal)
186+
if log.IsDebug() {
187+
log.Debug("Principal Rejected: %s Untrusted Authority Signature Fingerprint %s for Principal: %s", ctx.RemoteAddr(), gossh.FingerprintSHA256(cert.SignatureKey), principal)
188+
}
176189
continue principalLoop
177190
}
178191

179192
// validate the cert for this principal
180193
if err := c.CheckCert(principal, cert); err != nil {
181-
// User is presenting an invalid cerficate - STOP any further processing
182-
log.Error("Permission Denied: Invalid Certificate KeyID %s with Signature Fingerprint %s presented for Principal: %s", cert.KeyId, gossh.FingerprintSHA256(cert.SignatureKey), principal)
194+
// User is presenting an invalid certificate - STOP any further processing
195+
if log.IsError() {
196+
log.Error("Invalid Certificate KeyID %s with Signature Fingerprint %s presented for Principal: %s from %s", cert.KeyId, gossh.FingerprintSHA256(cert.SignatureKey), principal, ctx.RemoteAddr())
197+
}
198+
log.Warn("Failed authentication attempt from %s", ctx.RemoteAddr())
199+
183200
return false
184201
}
185202

203+
if log.IsDebug() { // <- FingerprintSHA256 is kinda expensive so only calculate it if necessary
204+
log.Debug("Successfully authenticated: %s Certificate Fingerprint: %s Principal: %s", ctx.RemoteAddr(), gossh.FingerprintSHA256(key), principal)
205+
}
186206
ctx.SetValue(giteaKeyID, pkey.ID)
187207

188208
return true
189209
}
210+
211+
if log.IsWarn() {
212+
log.Warn("From %s Fingerprint: %s is a certificate, but no valid principals found", ctx.RemoteAddr(), gossh.FingerprintSHA256(key))
213+
log.Warn("Failed authentication attempt from %s", ctx.RemoteAddr())
214+
}
215+
return false
216+
}
217+
218+
if log.IsDebug() { // <- FingerprintSHA256 is kinda expensive so only calculate it if necessary
219+
log.Debug("Handle Public Key: %s Fingerprint: %s is not a certificate", ctx.RemoteAddr(), gossh.FingerprintSHA256(key))
190220
}
191221

192222
pkey, err := models.SearchPublicKeyByContent(strings.TrimSpace(string(gossh.MarshalAuthorizedKey(key))))
193223
if err != nil {
194224
if models.IsErrKeyNotExist(err) {
195-
log.Warn("Permission Denied: Unknown public key : %s", gossh.FingerprintSHA256(key))
225+
if log.IsWarn() {
226+
log.Warn("Unknown public key: %s from %s", gossh.FingerprintSHA256(key), ctx.RemoteAddr())
227+
log.Warn("Failed authentication attempt from %s", ctx.RemoteAddr())
228+
}
196229
return false
197230
}
198-
log.Error("SearchPublicKeyByContent: %v Failed authentication attempt from %s", err, ctx.RemoteAddr())
231+
log.Error("SearchPublicKeyByContent: %v", err)
199232
return false
200233
}
201234

235+
if log.IsDebug() { // <- FingerprintSHA256 is kinda expensive so only calculate it if necessary
236+
log.Debug("Successfully authenticated: %s Public Key Fingerprint: %s", ctx.RemoteAddr(), gossh.FingerprintSHA256(key))
237+
}
202238
ctx.SetValue(giteaKeyID, pkey.ID)
203239

204240
return true

modules/structs/issue.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ type Issue struct {
5050
Ref string `json:"ref"`
5151
Labels []*Label `json:"labels"`
5252
Milestone *Milestone `json:"milestone"`
53-
Assignee *User `json:"assignee"`
54-
Assignees []*User `json:"assignees"`
53+
// deprecated
54+
Assignee *User `json:"assignee"`
55+
Assignees []*User `json:"assignees"`
5556
// Whether the issue is open or closed
5657
//
5758
// type: string
@@ -83,7 +84,8 @@ type CreateIssueOption struct {
8384
// required:true
8485
Title string `json:"title" binding:"Required"`
8586
Body string `json:"body"`
86-
// username of assignee
87+
Ref string `json:"ref"`
88+
// deprecated
8789
Assignee string `json:"assignee"`
8890
Assignees []string `json:"assignees"`
8991
// swagger:strfmt date-time
@@ -97,8 +99,10 @@ type CreateIssueOption struct {
9799

98100
// EditIssueOption options for editing an issue
99101
type EditIssueOption struct {
100-
Title string `json:"title"`
101-
Body *string `json:"body"`
102+
Title string `json:"title"`
103+
Body *string `json:"body"`
104+
Ref *string `json:"ref"`
105+
// deprecated
102106
Assignee *string `json:"assignee"`
103107
Assignees []string `json:"assignees"`
104108
Milestone *int64 `json:"milestone"`

routers/api/v1/repo/issue.go

+8
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) {
486486
PosterID: ctx.User.ID,
487487
Poster: ctx.User,
488488
Content: form.Body,
489+
Ref: form.Ref,
489490
DeadlineUnix: deadlineUnix,
490491
}
491492

@@ -625,6 +626,13 @@ func EditIssue(ctx *context.APIContext, form api.EditIssueOption) {
625626
if form.Body != nil {
626627
issue.Content = *form.Body
627628
}
629+
if form.Ref != nil {
630+
err = issue_service.ChangeIssueRef(issue, ctx.User, *form.Ref)
631+
if err != nil {
632+
ctx.Error(http.StatusInternalServerError, "UpdateRef", err)
633+
return
634+
}
635+
}
628636

629637
// Update or remove the deadline, only if set and allowed
630638
if (form.Deadline != nil || form.RemoveDeadline != nil) && canWrite {

routers/repo/issue.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -1649,7 +1649,7 @@ func UpdateIssueContent(ctx *context.Context) {
16491649

16501650
ctx.JSON(200, map[string]interface{}{
16511651
"content": string(markdown.Render([]byte(issue.Content), ctx.Query("context"), ctx.Repo.Repository.ComposeMetas())),
1652-
"attachments": attachmentsHTML(ctx, issue.Attachments),
1652+
"attachments": attachmentsHTML(ctx, issue.Attachments, issue.Content),
16531653
})
16541654
}
16551655

@@ -2065,7 +2065,7 @@ func UpdateCommentContent(ctx *context.Context) {
20652065

20662066
ctx.JSON(200, map[string]interface{}{
20672067
"content": string(markdown.Render([]byte(comment.Content), ctx.Query("context"), ctx.Repo.Repository.ComposeMetas())),
2068-
"attachments": attachmentsHTML(ctx, comment.Attachments),
2068+
"attachments": attachmentsHTML(ctx, comment.Attachments, comment.Content),
20692069
})
20702070
}
20712071

@@ -2399,10 +2399,11 @@ func updateAttachments(item interface{}, files []string) error {
23992399
return err
24002400
}
24012401

2402-
func attachmentsHTML(ctx *context.Context, attachments []*models.Attachment) string {
2402+
func attachmentsHTML(ctx *context.Context, attachments []*models.Attachment, content string) string {
24032403
attachHTML, err := ctx.HTMLString(string(tplAttachment), map[string]interface{}{
24042404
"ctx": ctx.Data,
24052405
"Attachments": attachments,
2406+
"Content": content,
24062407
})
24072408
if err != nil {
24082409
ctx.ServerError("attachmentsHTML.HTMLString", err)

services/pull/review.go

+7-7
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/repository/push.go

+17-1
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

+1-1
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

templates/repo/icon.tmpl

-5
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@
44
{{else}}
55
{{if $.IsPrivate}}
66
{{svg "octicon-lock" 32}}
7-
{{else if and (not $.IsMirror) (not $.IsFork) ($.Owner)}}
8-
{{svg "octicon-repo" 32}}
9-
{{if $.Owner.Visibility.IsPrivate}}
10-
{{avatar $.Owner}}
11-
{{end}}
127
{{else if $.IsMirror}}
138
{{svg "octicon-mirror" 32}}
149
{{else if $.IsFork}}

templates/repo/issue/view_content.tmpl

+3-8
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,9 @@
6666
</div>
6767
<div id="comment-{{.Issue.ID}}" class="raw-content hide">{{.Issue.Content}}</div>
6868
<div class="edit-content-zone hide" data-write="issue-{{.Issue.ID}}-write" data-preview="issue-{{.Issue.ID}}-preview" data-update-url="{{$.RepoLink}}/issues/{{.Issue.Index}}/content" data-context="{{.RepoLink}}" data-attachment-url="{{$.RepoLink}}/issues/{{.Issue.Index}}/attachments" data-view-attachment-url="{{$.RepoLink}}/issues/{{.Issue.Index}}/view-attachments"></div>
69-
{{if .Issue.Attachments}}
70-
<div class="dropzone-attachments">
71-
<div class="ui clearing divider"></div>
72-
<div class="ui middle aligned padded grid">
73-
{{template "repo/issue/view_content/attachments" Dict "ctx" $ "Attachments" .Issue.Attachments}}
74-
</div>
75-
</div>
76-
{{end}}
69+
{{if .Issue.Attachments}}
70+
{{template "repo/issue/view_content/attachments" Dict "ctx" $ "Attachments" .Issue.Attachments "Content" .Issue.RenderedContent}}
71+
{{end}}
7772
</div>
7873
{{$reactions := .Issue.Reactions.GroupByType}}
7974
{{if $reactions}}

0 commit comments

Comments
 (0)