Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions custom/conf/app.example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1767,6 +1767,12 @@ LEVEL = Info
;;
;; convert \r\n to \n for Sendmail
;SENDMAIL_CONVERT_CRLF = true
;;
;; convert links of attached images to inline images. Only for images hosted in this gitea instance.
;BASE64_EMBED_IMAGES = false
;;
;; The maximum size of sum of all images in a single email. Default is 9.5MB
;BASE64_EMBED_IMAGES_MAX_SIZE_PER_EMAIL = 9961472

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down
13 changes: 13 additions & 0 deletions models/fixtures/attachment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,16 @@
download_count: 0
size: 0
created_unix: 946684800

-
id: 13
uuid: 1b267670-1793-4cd0-abc1-449269b7cff9
repo_id: 1
issue_id: 23
release_id: 0
uploader_id: 0
comment_id: 2
name: gitea.png
download_count: 0
size: 1458
created_unix: 946684800
17 changes: 17 additions & 0 deletions models/fixtures/issue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -372,3 +372,20 @@
created_unix: 1707270422
updated_unix: 1707270422
is_locked: false

-
id: 23
repo_id: 1
index: 6
poster_id: 1
original_author_id: 0
name: issue23
content: 'content including this image: <image alt="gitea.png" src="attachments/1b267670-1793-4cd0-abc1-449269b7cff9" /> with some more content behind it'
milestone_id: 0
priority: 0
is_closed: false
is_pull: false
num_comments: 0
created_unix: 946684801
updated_unix: 978307201
is_locked: false
2 changes: 1 addition & 1 deletion models/fixtures/issue_index.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-
group_id: 1
max_index: 5
max_index: 6

-
group_id: 2
Expand Down
2 changes: 1 addition & 1 deletion models/fixtures/repository.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
num_watches: 4
num_stars: 0
num_forks: 0
num_issues: 2
num_issues: 3
num_closed_issues: 1
num_pulls: 3
num_closed_pulls: 0
Expand Down
10 changes: 5 additions & 5 deletions models/issues/issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func Test_GetIssueIDsByRepoID(t *testing.T) {

ids, err := issues_model.GetIssueIDsByRepoID(db.DefaultContext, 1)
assert.NoError(t, err)
assert.Len(t, ids, 5)
assert.Len(t, ids, 6)
}

func TestIssueAPIURL(t *testing.T) {
Expand Down Expand Up @@ -170,7 +170,7 @@ func TestIssues(t *testing.T) {
PageSize: 4,
},
},
[]int64{1, 2, 3, 5},
[]int64{1, 23, 2, 3},
},
{
issues_model.IssuesOptions{
Expand Down Expand Up @@ -249,11 +249,11 @@ func TestIssue_InsertIssue(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())

// there are 5 issues and max index is 5 on repository 1, so this one should 6
issue := testInsertIssue(t, "my issue1", "special issue's comments?", 6)
issue := testInsertIssue(t, "my issue1", "special issue's comments?", 7)
_, err := db.DeleteByID[issues_model.Issue](db.DefaultContext, issue.ID)
assert.NoError(t, err)

issue = testInsertIssue(t, `my issue2, this is my son's love \n \r \ `, "special issue's '' comments?", 7)
issue = testInsertIssue(t, `my issue2, this is my son's love \n \r \ `, "special issue's '' comments?", 8)
_, err = db.DeleteByID[issues_model.Issue](db.DefaultContext, issue.ID)
assert.NoError(t, err)
}
Expand Down Expand Up @@ -380,7 +380,7 @@ func TestCountIssues(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
count, err := issues_model.CountIssues(db.DefaultContext, &issues_model.IssuesOptions{})
assert.NoError(t, err)
assert.EqualValues(t, 22, count)
assert.EqualValues(t, 23, count)
}

func TestIssueLoadAttributes(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion models/issues/issue_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func Test_NewIssueUsers(t *testing.T) {
newIssue := &issues_model.Issue{
RepoID: repo.ID,
PosterID: 4,
Index: 6,
Index: 7,
Title: "newTestIssueTitle",
Content: "newTestIssueContent",
}
Expand Down
2 changes: 1 addition & 1 deletion models/repo/attachment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestDeleteAttachments(t *testing.T) {

count, err = repo_model.DeleteAttachmentsByComment(db.DefaultContext, 2, false)
assert.NoError(t, err)
assert.Equal(t, 2, count)
assert.Equal(t, 3, count)

err = repo_model.DeleteAttachment(db.DefaultContext, &repo_model.Attachment{ID: 8}, false)
assert.NoError(t, err)
Expand Down
4 changes: 4 additions & 0 deletions models/unittest/testdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func InitSettings() {
setting.CustomConf = filepath.Join(setting.CustomPath, "conf/app-unittest-tmp.ini")
_ = os.Remove(setting.CustomConf)
}
log.Info("CustomConf: %s", setting.CustomConf)
setting.InitCfgProvider(setting.CustomConf)
setting.LoadCommonSettings()

Expand All @@ -72,6 +73,7 @@ type TestOptions struct {
// MainTest a reusable TestMain(..) function for unit tests that need to use a
// test database. Creates the test database, and sets necessary settings.
func MainTest(m *testing.M, testOptsArg ...*TestOptions) {
log.Info("MainTest Alive: %v\n", testOptsArg)
testOpts := util.OptionalArg(testOptsArg, &TestOptions{})
giteaRoot = test.SetupGiteaRoot()
setting.CustomPath = filepath.Join(giteaRoot, "custom")
Expand Down Expand Up @@ -101,12 +103,14 @@ func MainTest(m *testing.M, testOptsArg ...*TestOptions) {
if err != nil {
fatalTestError("TempDir: %v\n", err)
}
log.Info("Appdata Findme: %s", appDataPath)
setting.AppDataPath = appDataPath
setting.AppWorkPath = giteaRoot
setting.StaticRootPath = giteaRoot
setting.GravatarSource = "https://secure.gravatar.com/avatar/"

setting.Attachment.Storage.Path = filepath.Join(setting.AppDataPath, "attachments")
log.Info("Attachment Path: %s", setting.Attachment.Storage.Path)

setting.LFS.Storage.Path = filepath.Join(setting.AppDataPath, "lfs")

Expand Down
26 changes: 13 additions & 13 deletions modules/indexer/issues/indexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func searchIssueWithKeyword(t *testing.T) {
Keyword: "issue2",
RepoIDs: []int64{1},
},
[]int64{2},
[]int64{2, 23},
},
{
SearchOptions{
Expand Down Expand Up @@ -106,7 +106,7 @@ func searchIssueByIndex(t *testing.T) {
Keyword: "2",
RepoIDs: []int64{1, 2, 3, 32},
},
[]int64{17, 12, 7, 2},
[]int64{17, 12, 7, 2, 23},
},
{
SearchOptions{
Expand All @@ -133,7 +133,7 @@ func searchIssueInRepo(t *testing.T) {
SearchOptions{
RepoIDs: []int64{1},
},
[]int64{11, 5, 3, 2, 1},
[]int64{11, 5, 3, 2, 23, 1},
},
{
SearchOptions{
Expand Down Expand Up @@ -177,7 +177,7 @@ func searchIssueByID(t *testing.T) {
opts: SearchOptions{
PosterID: optional.Some(int64(1)),
},
expectedIDs: []int64{11, 6, 3, 2, 1},
expectedIDs: []int64{11, 6, 3, 2, 23, 1},
},
{
opts: SearchOptions{
Expand All @@ -188,7 +188,7 @@ func searchIssueByID(t *testing.T) {
{
// NOTE: This tests no assignees filtering and also ToSearchOptions() to ensure it will set AssigneeID to 0 when it is passed as -1.
opts: *ToSearchOptions("", &issues.IssuesOptions{AssigneeID: optional.Some(db.NoConditionID)}),
expectedIDs: []int64{22, 21, 16, 15, 14, 13, 12, 11, 20, 5, 19, 18, 10, 7, 4, 9, 8, 3, 2},
expectedIDs: []int64{22, 21, 16, 15, 14, 13, 12, 11, 20, 5, 19, 18, 10, 7, 4, 9, 8, 3, 2, 23},
},
{
opts: SearchOptions{
Expand All @@ -212,7 +212,7 @@ func searchIssueByID(t *testing.T) {
opts: SearchOptions{
SubscriberID: optional.Some(int64(1)),
},
expectedIDs: []int64{11, 6, 5, 3, 2, 1},
expectedIDs: []int64{11, 6, 5, 3, 2, 23, 1},
},
{
// issue 20 request user 15 and team 5 which user 15 belongs to
Expand Down Expand Up @@ -247,7 +247,7 @@ func searchIssueIsPull(t *testing.T) {
SearchOptions{
IsPull: optional.Some(false),
},
[]int64{17, 16, 15, 14, 13, 6, 5, 18, 10, 7, 4, 1},
[]int64{17, 16, 15, 14, 13, 6, 5, 18, 10, 7, 4, 23, 1},
},
{
SearchOptions{
Expand All @@ -272,7 +272,7 @@ func searchIssueIsClosed(t *testing.T) {
SearchOptions{
IsClosed: optional.Some(false),
},
[]int64{22, 21, 17, 16, 15, 14, 13, 12, 11, 20, 6, 19, 18, 10, 7, 9, 8, 3, 2, 1},
[]int64{22, 21, 17, 16, 15, 14, 13, 12, 11, 20, 6, 19, 18, 10, 7, 9, 8, 3, 2, 23, 1},
},
{
SearchOptions{
Expand All @@ -297,7 +297,7 @@ func searchIssueIsArchived(t *testing.T) {
SearchOptions{
IsArchived: optional.Some(false),
},
[]int64{22, 21, 17, 16, 15, 13, 12, 11, 20, 6, 5, 19, 18, 10, 7, 4, 9, 8, 3, 2, 1},
[]int64{22, 21, 17, 16, 15, 13, 12, 11, 20, 6, 5, 19, 18, 10, 7, 4, 9, 8, 3, 2, 23, 1},
},
{
SearchOptions{
Expand Down Expand Up @@ -359,7 +359,7 @@ func searchIssueByLabelID(t *testing.T) {
SearchOptions{
ExcludedLabelIDs: []int64{1},
},
[]int64{22, 21, 17, 16, 15, 14, 13, 12, 11, 20, 6, 5, 19, 18, 10, 7, 4, 9, 8, 3},
[]int64{22, 21, 17, 16, 15, 14, 13, 12, 11, 20, 6, 5, 19, 18, 10, 7, 4, 9, 8, 3, 23},
},
}
for _, test := range tests {
Expand All @@ -378,7 +378,7 @@ func searchIssueByTime(t *testing.T) {
SearchOptions{
UpdatedAfterUnix: optional.Some(int64(0)),
},
[]int64{22, 21, 17, 16, 15, 14, 13, 12, 11, 20, 6, 5, 19, 18, 10, 7, 4, 9, 8, 3, 2, 1},
[]int64{22, 21, 17, 16, 15, 14, 13, 12, 11, 20, 6, 5, 19, 18, 10, 7, 4, 9, 8, 3, 2, 23, 1},
},
}
for _, test := range tests {
Expand All @@ -397,7 +397,7 @@ func searchIssueWithOrder(t *testing.T) {
SearchOptions{
SortBy: internal.SortByCreatedAsc,
},
[]int64{1, 2, 3, 8, 9, 4, 7, 10, 18, 19, 5, 6, 20, 11, 12, 13, 14, 15, 16, 17, 21, 22},
[]int64{1, 23, 2, 3, 8, 9, 4, 7, 10, 18, 19, 5, 6, 20, 11, 12, 13, 14, 15, 16, 17, 21, 22},
},
}
for _, test := range tests {
Expand Down Expand Up @@ -451,7 +451,7 @@ func searchIssueWithPaginator(t *testing.T) {
},
},
[]int64{22, 21, 17, 16, 15},
22,
23,
},
}
for _, test := range tests {
Expand Down
24 changes: 14 additions & 10 deletions modules/setting/mailer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,23 @@ import (

"code.gitea.io/gitea/modules/log"

shellquote "github.com/kballard/go-shellquote"
"github.com/kballard/go-shellquote"
)

// Mailer represents mail service.
type Mailer struct {
// Mailer
Name string `ini:"NAME"`
From string `ini:"FROM"`
EnvelopeFrom string `ini:"ENVELOPE_FROM"`
OverrideEnvelopeFrom bool `ini:"-"`
FromName string `ini:"-"`
FromEmail string `ini:"-"`
SendAsPlainText bool `ini:"SEND_AS_PLAIN_TEXT"`
SubjectPrefix string `ini:"SUBJECT_PREFIX"`
OverrideHeader map[string][]string `ini:"-"`
Name string `ini:"NAME"`
From string `ini:"FROM"`
EnvelopeFrom string `ini:"ENVELOPE_FROM"`
OverrideEnvelopeFrom bool `ini:"-"`
FromName string `ini:"-"`
FromEmail string `ini:"-"`
SendAsPlainText bool `ini:"SEND_AS_PLAIN_TEXT"`
SubjectPrefix string `ini:"SUBJECT_PREFIX"`
OverrideHeader map[string][]string `ini:"-"`
Base64EmbedImages bool `ini:"BASE64_EMBED_IMAGES"`
Base64EmbedImagesMaxSizePerEmail int64 `ini:"BASE64_EMBED_IMAGES_MAX_SIZE_PER_EMAIL"`

// SMTP sender
Protocol string `ini:"PROTOCOL"`
Expand Down Expand Up @@ -150,6 +152,8 @@ func loadMailerFrom(rootCfg ConfigProvider) {
sec.Key("SENDMAIL_TIMEOUT").MustDuration(5 * time.Minute)
sec.Key("SENDMAIL_CONVERT_CRLF").MustBool(true)
sec.Key("FROM").MustString(sec.Key("USER").String())
sec.Key("BASE64_EMBED_IMAGES").MustBool(false)
sec.Key("BASE64_EMBED_IMAGES_MAX_SIZE_PER_EMAIL").MustInt64(9.5 * 1024 * 1024)

// Now map the values on to the MailService
MailService = &Mailer{}
Expand Down
1 change: 1 addition & 0 deletions modules/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
// For quickstart, the parent directories should be created automatically for first startup (eg: a flag or a check of INSTALL_LOCK).
// Now we can take the first step to do correctly (using Mkdir) in other packages, and prepare the AppDataPath here, then make a refactor in future.

fmt.Printf("AppDataPath: %s\n", AppDataPath)

Check failure on line 69 in modules/setting/setting.go

View workflow job for this annotation

GitHub Actions / lint-backend

use of `fmt.Printf` forbidden by pattern `^(fmt\.Print(|f|ln)|print|println)$` (forbidigo)

Check failure on line 69 in modules/setting/setting.go

View workflow job for this annotation

GitHub Actions / lint-go-gogit

use of `fmt.Printf` forbidden by pattern `^(fmt\.Print(|f|ln)|print|println)$` (forbidigo)

Check failure on line 69 in modules/setting/setting.go

View workflow job for this annotation

GitHub Actions / lint-go-windows

use of `fmt.Printf` forbidden by pattern `^(fmt\.Print(|f|ln)|print|println)$` (forbidigo)
st, err := os.Stat(AppDataPath)
if os.IsNotExist(err) {
err = os.MkdirAll(AppDataPath, os.ModePerm)
Expand Down
1 change: 1 addition & 0 deletions modules/storage/azureblob.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ func (a *AzureBlobStorage) Open(path string) (Object, error) {

// Save saves a file to azure blob storage
func (a *AzureBlobStorage) Save(path string, r io.Reader, size int64) (int64, error) {
log.Info("AzureBlobStorage.Save(%s, %d)\n", path, size)
rd := util.NewCountingReader(r)
_, err := a.client.UploadStream(
a.ctx,
Expand Down
2 changes: 2 additions & 0 deletions modules/storage/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
package storage

import (
"code.gitea.io/gitea/modules/log"

Check failure on line 7 in modules/storage/helper.go

View workflow job for this annotation

GitHub Actions / lint-backend

File is not properly formatted (gofumpt)

Check failure on line 7 in modules/storage/helper.go

View workflow job for this annotation

GitHub Actions / lint-go-gogit

File is not properly formatted (gofumpt)

Check failure on line 7 in modules/storage/helper.go

View workflow job for this annotation

GitHub Actions / lint-go-windows

File is not properly formatted (gofumpt)
"fmt"
"io"
"net/url"
"os"

Check failure on line 11 in modules/storage/helper.go

View workflow job for this annotation

GitHub Actions / lint-backend

File is not properly formatted (gofumpt)

Check failure on line 11 in modules/storage/helper.go

View workflow job for this annotation

GitHub Actions / lint-go-gogit

File is not properly formatted (gofumpt)

Check failure on line 11 in modules/storage/helper.go

View workflow job for this annotation

GitHub Actions / lint-go-windows

File is not properly formatted (gofumpt)
)

var uninitializedStorage = discardStorage("uninitialized storage")
Expand All @@ -19,6 +20,7 @@
}

func (s discardStorage) Save(_ string, _ io.Reader, _ int64) (int64, error) {
log.Info("DiscardStorage.Save(%s)\n", s)
return 0, fmt.Errorf("%s", s)
}

Expand Down
1 change: 1 addition & 0 deletions modules/storage/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func (l *LocalStorage) Open(path string) (Object, error) {

// Save a file
func (l *LocalStorage) Save(path string, r io.Reader, size int64) (int64, error) {
log.Info("LocalStorage.Save(%s, %d) local\n", path, size)
p := l.buildLocalPath(path)
if err := os.MkdirAll(filepath.Dir(p), os.ModePerm); err != nil {
return 0, err
Expand Down
1 change: 1 addition & 0 deletions modules/storage/minio.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ func (m *MinioStorage) Open(path string) (Object, error) {

// Save saves a file to minio
func (m *MinioStorage) Save(path string, r io.Reader, size int64) (int64, error) {
log.Info("MinioStorage.Save(%s, %d)\n", path, size)
uploadInfo, err := m.client.PutObject(
m.ctx,
m.bucket,
Expand Down
9 changes: 9 additions & 0 deletions modules/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,21 @@ func initAvatars() (err error) {
}

func initAttachments() (err error) {
log.Info("initAttachments")
if !setting.Attachment.Enabled {
Attachments = discardStorage("Attachment isn't enabled")
return nil
}
log.Info("Initialising Attachment storage with type: %s", setting.Attachment.Storage.Type)
Attachments, err = NewStorage(setting.Attachment.Storage.Type, setting.Attachment.Storage)
log.Info("storage FINDME: %v\n", setting.Attachment.Storage.Path)
// check if directory exists and print the result human readable
if _, err := os.Stat(setting.Attachment.Storage.Path); os.IsNotExist(err) {
log.Info("Attachment storage path does not exist: %s\n", setting.Attachment.Storage.Path)
} else {
log.Info("Attachment storage path exists: %s\n", setting.Attachment.Storage.Path)
}

return err
}

Expand Down
Loading
Loading