Skip to content

Commit 9d7ab3c

Browse files
committed
Merge remote-tracking branch 'giteaoffical/main'
* giteaoffical/main: remove not needed (go-gitea#19128) Add warning to set SENDMAIL_ARGS to -- (go-gitea#19102) Do not send activation email if manual confirm is set (go-gitea#19119) Update tool dependencies (go-gitea#19120) Delete related notifications on issue deletion too (go-gitea#18953) nit fix (go-gitea#19116) Store the foreign ID of issues during migration (go-gitea#18446) Remove italics for `due_date_not_set` (go-gitea#19113)
2 parents 160a1c2 + 60fbaa9 commit 9d7ab3c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+476
-414
lines changed

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ XGO_VERSION := go-1.18.x
2828
MIN_GO_VERSION := 001017000
2929
MIN_NODE_VERSION := 012017000
3030

31-
AIR_PACKAGE ?= github.com/cosmtrek/air@bedc18201271882c2be66d216d0e1a275b526ec4
32-
EDITORCONFIG_CHECKER_PACKAGE ?= github.com/editorconfig-checker/editorconfig-checker/cmd/editorconfig-checker@50adf46752da119dfef66e57be3ce2693ea4aa9c
33-
ERRCHECK_PACKAGE ?= github.com/kisielk/errcheck@8ddee489636a8311a376fc92e27a6a13c6658344
31+
AIR_PACKAGE ?= github.com/cosmtrek/air@v1.29.0
32+
EDITORCONFIG_CHECKER_PACKAGE ?= github.com/editorconfig-checker/editorconfig-checker/cmd/editorconfig-checker@2.4.0
33+
ERRCHECK_PACKAGE ?= github.com/kisielk/errcheck@v1.6.0
3434
GOFUMPT_PACKAGE ?= mvdan.cc/[email protected]
3535
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/[email protected]
3636
GXZ_PAGAGE ?= github.com/ulikunitz/xz/cmd/[email protected]
3737
MISSPELL_PACKAGE ?= github.com/client9/misspell/cmd/[email protected]
38-
SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/swagger@v0.27.0
38+
SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/swagger@v0.29.0
3939
XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
4040

4141
DOCKER_IMAGE ?= gitea/gitea

custom/conf/app.example.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,6 +1533,7 @@ PATH =
15331533
;SENDMAIL_PATH = sendmail
15341534
;;
15351535
;; Specify any extra sendmail arguments
1536+
;; WARNING: if your sendmail program interprets options you should set this to "--" or terminate these args with "--"
15361537
;SENDMAIL_ARGS =
15371538
;;
15381539
;; Timeout for Sendmail

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ Define allowed algorithms and their minimum key length (use -1 to disable a type
666666
- Enabling dummy will ignore all settings except `ENABLED`, `SUBJECT_PREFIX` and `FROM`.
667667
- `SENDMAIL_PATH`: **sendmail**: The location of sendmail on the operating system (can be
668668
command or full path).
669-
- `SENDMAIL_ARGS`: **_empty_**: Specify any extra sendmail arguments.
669+
- `SENDMAIL_ARGS`: **_empty_**: Specify any extra sendmail arguments. (NOTE: you should be aware that email addresses can look like options - if your `sendmail` command takes options you must set the option terminator `--`)
670670
- `SENDMAIL_TIMEOUT`: **5m**: default timeout for sending email through sendmail
671671
- `SENDMAIL_CONVERT_CRLF`: **true**: Most versions of sendmail prefer LF line endings rather than CRLF line endings. Set this to false if your version of sendmail requires CRLF line endings.
672672
- `SEND_BUFFER_LEN`: **100**: Buffer length of mailing queue. **DEPRECATED** use `LENGTH` in `[queue.mailer]`

docs/content/doc/usage/email-setup.en-us.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ ENABLED = true
3535
3636
MAILER_TYPE = sendmail
3737
SENDMAIL_PATH = /usr/sbin/sendmail
38+
SENDMAIL_ARGS = "--" ; most "sendmail" programs take options, "--" will prevent an email address being interpreted as an option.
3839
```
3940

4041
## Using SMTP

models/fixtures/foreign_reference.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[] # empty

models/foreignreference/error.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2022 Gitea. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package foreignreference
6+
7+
import (
8+
"fmt"
9+
)
10+
11+
// ErrLocalIndexNotExist represents a "LocalIndexNotExist" kind of error.
12+
type ErrLocalIndexNotExist struct {
13+
RepoID int64
14+
ForeignIndex int64
15+
Type string
16+
}
17+
18+
// ErrLocalIndexNotExist checks if an error is a ErrLocalIndexNotExist.
19+
func IsErrLocalIndexNotExist(err error) bool {
20+
_, ok := err.(ErrLocalIndexNotExist)
21+
return ok
22+
}
23+
24+
func (err ErrLocalIndexNotExist) Error() string {
25+
return fmt.Sprintf("repository %d has no LocalIndex for ForeignIndex %d of type %s", err.RepoID, err.ForeignIndex, err.Type)
26+
}
27+
28+
// ErrForeignIndexNotExist represents a "ForeignIndexNotExist" kind of error.
29+
type ErrForeignIndexNotExist struct {
30+
RepoID int64
31+
LocalIndex int64
32+
Type string
33+
}
34+
35+
// ErrForeignIndexNotExist checks if an error is a ErrForeignIndexNotExist.
36+
func IsErrForeignIndexNotExist(err error) bool {
37+
_, ok := err.(ErrForeignIndexNotExist)
38+
return ok
39+
}
40+
41+
func (err ErrForeignIndexNotExist) Error() string {
42+
return fmt.Sprintf("repository %d has no ForeignIndex for LocalIndex %d of type %s", err.RepoID, err.LocalIndex, err.Type)
43+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2022 Gitea. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package foreignreference
6+
7+
import (
8+
"code.gitea.io/gitea/models/db"
9+
)
10+
11+
// Type* are valid values for the Type field of ForeignReference
12+
const (
13+
TypeIssue = "issue"
14+
TypePullRequest = "pull_request"
15+
TypeComment = "comment"
16+
TypeReview = "review"
17+
TypeReviewComment = "review_comment"
18+
TypeRelease = "release"
19+
)
20+
21+
// ForeignReference represents external references
22+
type ForeignReference struct {
23+
// RepoID is the first column in all indices. now we only need 2 indices: (repo, local) and (repo, foreign, type)
24+
RepoID int64 `xorm:"UNIQUE(repo_foreign_type) INDEX(repo_local)" `
25+
LocalIndex int64 `xorm:"INDEX(repo_local)"` // the resource key inside Gitea, it can be IssueIndex, or some model ID.
26+
ForeignIndex string `xorm:"INDEX UNIQUE(repo_foreign_type)"`
27+
Type string `xorm:"VARCHAR(16) INDEX UNIQUE(repo_foreign_type)"`
28+
}
29+
30+
func init() {
31+
db.RegisterModel(new(ForeignReference))
32+
}

models/issue.go

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515

1616
admin_model "code.gitea.io/gitea/models/admin"
1717
"code.gitea.io/gitea/models/db"
18+
"code.gitea.io/gitea/models/foreignreference"
1819
"code.gitea.io/gitea/models/issues"
1920
"code.gitea.io/gitea/models/perm"
2021
repo_model "code.gitea.io/gitea/models/repo"
@@ -67,11 +68,12 @@ type Issue struct {
6768
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
6869
ClosedUnix timeutil.TimeStamp `xorm:"INDEX"`
6970

70-
Attachments []*repo_model.Attachment `xorm:"-"`
71-
Comments []*Comment `xorm:"-"`
72-
Reactions ReactionList `xorm:"-"`
73-
TotalTrackedTime int64 `xorm:"-"`
74-
Assignees []*user_model.User `xorm:"-"`
71+
Attachments []*repo_model.Attachment `xorm:"-"`
72+
Comments []*Comment `xorm:"-"`
73+
Reactions ReactionList `xorm:"-"`
74+
TotalTrackedTime int64 `xorm:"-"`
75+
Assignees []*user_model.User `xorm:"-"`
76+
ForeignReference *foreignreference.ForeignReference `xorm:"-"`
7577

7678
// IsLocked limits commenting abilities to users on an issue
7779
// with write access
@@ -271,6 +273,29 @@ func (issue *Issue) loadReactions(ctx context.Context) (err error) {
271273
return nil
272274
}
273275

276+
func (issue *Issue) loadForeignReference(ctx context.Context) (err error) {
277+
if issue.ForeignReference != nil {
278+
return nil
279+
}
280+
reference := &foreignreference.ForeignReference{
281+
RepoID: issue.RepoID,
282+
LocalIndex: issue.Index,
283+
Type: foreignreference.TypeIssue,
284+
}
285+
has, err := db.GetEngine(ctx).Get(reference)
286+
if err != nil {
287+
return err
288+
} else if !has {
289+
return foreignreference.ErrForeignIndexNotExist{
290+
RepoID: issue.RepoID,
291+
LocalIndex: issue.Index,
292+
Type: foreignreference.TypeIssue,
293+
}
294+
}
295+
issue.ForeignReference = reference
296+
return nil
297+
}
298+
274299
func (issue *Issue) loadMilestone(e db.Engine) (err error) {
275300
if (issue.Milestone == nil || issue.Milestone.ID != issue.MilestoneID) && issue.MilestoneID > 0 {
276301
issue.Milestone, err = getMilestoneByRepoID(e, issue.RepoID, issue.MilestoneID)
@@ -332,6 +357,10 @@ func (issue *Issue) loadAttributes(ctx context.Context) (err error) {
332357
}
333358
}
334359

360+
if err = issue.loadForeignReference(ctx); err != nil && !foreignreference.IsErrForeignIndexNotExist(err) {
361+
return err
362+
}
363+
335364
return issue.loadReactions(ctx)
336365
}
337366

@@ -1110,6 +1139,26 @@ func GetIssueByIndex(repoID, index int64) (*Issue, error) {
11101139
return issue, nil
11111140
}
11121141

1142+
// GetIssueByForeignIndex returns raw issue by foreign ID
1143+
func GetIssueByForeignIndex(ctx context.Context, repoID, foreignIndex int64) (*Issue, error) {
1144+
reference := &foreignreference.ForeignReference{
1145+
RepoID: repoID,
1146+
ForeignIndex: strconv.FormatInt(foreignIndex, 10),
1147+
Type: foreignreference.TypeIssue,
1148+
}
1149+
has, err := db.GetEngine(ctx).Get(reference)
1150+
if err != nil {
1151+
return nil, err
1152+
} else if !has {
1153+
return nil, foreignreference.ErrLocalIndexNotExist{
1154+
RepoID: repoID,
1155+
ForeignIndex: foreignIndex,
1156+
Type: foreignreference.TypeIssue,
1157+
}
1158+
}
1159+
return GetIssueByIndex(repoID, reference.LocalIndex)
1160+
}
1161+
11131162
// GetIssueWithAttrsByIndex returns issue by index in a repository.
11141163
func GetIssueWithAttrsByIndex(repoID, index int64) (*Issue, error) {
11151164
issue, err := GetIssueByIndex(repoID, index)
@@ -2075,6 +2124,7 @@ func deleteIssue(ctx context.Context, issue *Issue) error {
20752124
&IssueDependency{},
20762125
&IssueAssignees{},
20772126
&IssueUser{},
2127+
&Notification{},
20782128
&Reaction{},
20792129
&IssueWatch{},
20802130
&Stopwatch{},

models/issue_comment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,7 @@ func deleteComment(e db.Engine, comment *Comment) error {
11631163
}
11641164

11651165
if comment.Type == CommentTypeComment {
1166-
if _, err := e.Exec("UPDATE `issue` SET num_comments = num_comments - 1 WHERE id = ?", comment.IssueID); err != nil {
1166+
if _, err := e.ID(comment.IssueID).Decr("num_comments").Update(new(Issue)); err != nil {
11671167
return err
11681168
}
11691169
}

models/issue_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ import (
88
"context"
99
"fmt"
1010
"sort"
11+
"strconv"
1112
"sync"
1213
"testing"
1314
"time"
1415

1516
"code.gitea.io/gitea/models/db"
17+
"code.gitea.io/gitea/models/foreignreference"
1618
repo_model "code.gitea.io/gitea/models/repo"
1719
"code.gitea.io/gitea/models/unittest"
1820
user_model "code.gitea.io/gitea/models/user"
@@ -534,3 +536,35 @@ func TestCorrectIssueStats(t *testing.T) {
534536
assert.NoError(t, err)
535537
assert.EqualValues(t, issueStats.OpenCount, issueAmount)
536538
}
539+
540+
func TestIssueForeignReference(t *testing.T) {
541+
assert.NoError(t, unittest.PrepareTestDatabase())
542+
issue := unittest.AssertExistsAndLoadBean(t, &Issue{ID: 4}).(*Issue)
543+
assert.NotEqualValues(t, issue.Index, issue.ID) // make sure they are different to avoid false positive
544+
545+
// it is fine for an issue to not have a foreign reference
546+
err := issue.LoadAttributes()
547+
assert.NoError(t, err)
548+
assert.Nil(t, issue.ForeignReference)
549+
550+
var foreignIndex int64 = 12345
551+
_, err = GetIssueByForeignIndex(context.Background(), issue.RepoID, foreignIndex)
552+
assert.True(t, foreignreference.IsErrLocalIndexNotExist(err))
553+
554+
_, err = db.GetEngine(db.DefaultContext).Insert(&foreignreference.ForeignReference{
555+
LocalIndex: issue.Index,
556+
ForeignIndex: strconv.FormatInt(foreignIndex, 10),
557+
RepoID: issue.RepoID,
558+
Type: foreignreference.TypeIssue,
559+
})
560+
assert.NoError(t, err)
561+
562+
err = issue.LoadAttributes()
563+
assert.NoError(t, err)
564+
565+
assert.EqualValues(t, issue.ForeignReference.ForeignIndex, strconv.FormatInt(foreignIndex, 10))
566+
567+
found, err := GetIssueByForeignIndex(context.Background(), issue.RepoID, foreignIndex)
568+
assert.NoError(t, err)
569+
assert.EqualValues(t, found.Index, issue.Index)
570+
}

models/migrate.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ func insertIssue(ctx context.Context, issue *Issue) error {
8383
}
8484
}
8585

86+
if issue.ForeignReference != nil {
87+
issue.ForeignReference.LocalIndex = issue.Index
88+
if _, err := sess.Insert(issue.ForeignReference); err != nil {
89+
return err
90+
}
91+
}
92+
8693
return nil
8794
}
8895

models/migrate_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
package models
66

77
import (
8+
"strconv"
89
"testing"
910

11+
"code.gitea.io/gitea/models/foreignreference"
1012
repo_model "code.gitea.io/gitea/models/repo"
1113
"code.gitea.io/gitea/models/unittest"
1214
user_model "code.gitea.io/gitea/models/user"
@@ -45,6 +47,7 @@ func assertCreateIssues(t *testing.T, isPull bool) {
4547
UserID: owner.ID,
4648
}
4749

50+
foreignIndex := int64(12345)
4851
title := "issuetitle1"
4952
is := &Issue{
5053
RepoID: repo.ID,
@@ -58,11 +61,20 @@ func assertCreateIssues(t *testing.T, isPull bool) {
5861
IsClosed: true,
5962
Labels: []*Label{label},
6063
Reactions: []*Reaction{reaction},
64+
ForeignReference: &foreignreference.ForeignReference{
65+
ForeignIndex: strconv.FormatInt(foreignIndex, 10),
66+
RepoID: repo.ID,
67+
Type: foreignreference.TypeIssue,
68+
},
6169
}
6270
err := InsertIssues(is)
6371
assert.NoError(t, err)
6472

6573
i := unittest.AssertExistsAndLoadBean(t, &Issue{Title: title}).(*Issue)
74+
assert.Nil(t, i.ForeignReference)
75+
err = i.LoadAttributes()
76+
assert.NoError(t, err)
77+
assert.EqualValues(t, strconv.FormatInt(foreignIndex, 10), i.ForeignReference.ForeignIndex)
6678
unittest.AssertExistsAndLoadBean(t, &Reaction{Type: "heart", UserID: owner.ID, IssueID: i.ID})
6779
}
6880

models/migrations/migrations.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,11 @@ var migrations = []Migration{
373373
NewMigration("Increase WebAuthentication CredentialID size to 410 - NO-OPED", increaseCredentialIDTo410),
374374
// v210 -> v211
375375
NewMigration("v208 was completely broken - remigrate", remigrateU2FCredentials),
376+
377+
// Gitea 1.16.2 ends at v211
378+
379+
// v211 -> v212
380+
NewMigration("Create ForeignReference table", createForeignReferenceTable),
376381
}
377382

378383
// GetCurrentDBVersion returns the current db version

models/migrations/v211.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2022 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package migrations
6+
7+
import (
8+
"fmt"
9+
10+
"xorm.io/xorm"
11+
)
12+
13+
func createForeignReferenceTable(x *xorm.Engine) error {
14+
type ForeignReference struct {
15+
// RepoID is the first column in all indices. now we only need 2 indices: (repo, local) and (repo, foreign, type)
16+
RepoID int64 `xorm:"UNIQUE(repo_foreign_type) INDEX(repo_local)" `
17+
LocalIndex int64 `xorm:"INDEX(repo_local)"` // the resource key inside Gitea, it can be IssueIndex, or some model ID.
18+
ForeignIndex string `xorm:"INDEX UNIQUE(repo_foreign_type)"`
19+
Type string `xorm:"VARCHAR(16) INDEX UNIQUE(repo_foreign_type)"`
20+
}
21+
22+
if err := x.Sync2(new(ForeignReference)); err != nil {
23+
return fmt.Errorf("Sync2: %v", err)
24+
}
25+
return nil
26+
}

modules/hostmatcher/hostmatcher.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import (
88
"net"
99
"path/filepath"
1010
"strings"
11-
12-
"code.gitea.io/gitea/modules/util"
1311
)
1412

1513
// HostMatchList is used to check if a host or IP is in a list.
@@ -104,11 +102,11 @@ func (hl *HostMatchList) checkIP(ip net.IP) bool {
104102
for _, builtin := range hl.builtins {
105103
switch builtin {
106104
case MatchBuiltinExternal:
107-
if ip.IsGlobalUnicast() && !util.IsIPPrivate(ip) {
105+
if ip.IsGlobalUnicast() && !ip.IsPrivate() {
108106
return true
109107
}
110108
case MatchBuiltinPrivate:
111-
if util.IsIPPrivate(ip) {
109+
if ip.IsPrivate() {
112110
return true
113111
}
114112
case MatchBuiltinLoopback:

0 commit comments

Comments
 (0)