Skip to content

Commit f8ccc68

Browse files
authored
Merge branch 'main' into api_user-settings
2 parents d89ed56 + be81dc8 commit f8ccc68

Some content is hidden

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

46 files changed

+2424
-1085
lines changed

.drone.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ name: compliance
44

55
platform:
66
os: linux
7-
arch: arm64
7+
arch: amd64
88

99
trigger:
1010
event:
@@ -27,7 +27,7 @@ steps:
2727

2828
- name: lint-backend
2929
pull: always
30-
image: gitea/test_env:linux-arm64 # https://gitea.com/gitea/test-env
30+
image: gitea/test_env:linux-amd64 # https://gitea.com/gitea/test-env
3131
commands:
3232
- make lint-backend
3333
environment:
@@ -37,7 +37,7 @@ steps:
3737

3838
- name: lint-backend-windows
3939
pull: always
40-
image: gitea/test_env:linux-arm64 # https://gitea.com/gitea/test-env
40+
image: gitea/test_env:linux-amd64 # https://gitea.com/gitea/test-env
4141
commands:
4242
- make golangci-lint vet
4343
environment:
@@ -49,7 +49,7 @@ steps:
4949

5050
- name: lint-backend-gogit
5151
pull: always
52-
image: gitea/test_env:linux-arm64 # https://gitea.com/gitea/test-env
52+
image: gitea/test_env:linux-amd64 # https://gitea.com/gitea/test-env
5353
commands:
5454
- make lint-backend
5555
environment:

custom/conf/app.example.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,8 +1387,8 @@ PATH =
13871387
;; Mail server
13881388
;; Gmail: smtp.gmail.com:587
13891389
;; QQ: smtp.qq.com:465
1390-
;; Using STARTTLS on port 587 is recommended per RFC 6409.
1391-
;; Note, if the port ends with "465", SMTPS will be used.
1390+
;; As per RFC 8314 using Implicit TLS/SMTPS on port 465 (if supported) is recommended,
1391+
;; otherwise STARTTLS on port 587 should be used.
13921392
;HOST =
13931393
;;
13941394
;; Disable HELO operation when hostnames are different.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,9 +550,9 @@ Define allowed algorithms and their minimum key length (use -1 to disable a type
550550
- `DISABLE_HELO`: **\<empty\>**: Disable HELO operation.
551551
- `HELO_HOSTNAME`: **\<empty\>**: Custom hostname for HELO operation.
552552
- `HOST`: **\<empty\>**: SMTP mail host address and port (example: smtp.gitea.io:587).
553-
- Using opportunistic TLS via STARTTLS on port 587 is recommended per RFC 6409.
553+
- As per RFC 8314, if supported, Implicit TLS/SMTPS on port 465 is recommended, otherwise opportunistic TLS via STARTTLS on port 587 should be used.
554554
- `IS_TLS_ENABLED` : **false** : Forcibly use TLS to connect even if not on a default SMTPS port.
555-
- Note, if the port ends with `465` SMTPS/SMTP over TLS will be used despite this setting.
555+
- Note, if the port ends with `465` Implicit TLS/SMTPS/SMTP over TLS will be used despite this setting.
556556
- Otherwise if `IS_TLS_ENABLED=false` and the server supports `STARTTLS` this will be used. Thus if `STARTTLS` is preferred you should set `IS_TLS_ENABLED=false`.
557557
- `FROM`: **\<empty\>**: Mail from address, RFC 5322. This can be just an email address, or
558558
the "Name" \<email@example.com\> format.

integrations/api_team_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ func TestAPITeamSearch(t *testing.T) {
144144
var results TeamSearchResults
145145

146146
session := loginUser(t, user.Name)
147+
csrf := GetCSRF(t, session, "/"+org.Name)
147148
req := NewRequestf(t, "GET", "/api/v1/orgs/%s/teams/search?q=%s", org.Name, "_team")
149+
req.Header.Add("X-Csrf-Token", csrf)
148150
resp := session.MakeRequest(t, req, http.StatusOK)
149151
DecodeJSON(t, resp, &results)
150152
assert.NotEmpty(t, results.Data)
@@ -154,7 +156,9 @@ func TestAPITeamSearch(t *testing.T) {
154156
// no access if not organization member
155157
user5 := models.AssertExistsAndLoadBean(t, &models.User{ID: 5}).(*models.User)
156158
session = loginUser(t, user5.Name)
159+
csrf = GetCSRF(t, session, "/"+org.Name)
157160
req = NewRequestf(t, "GET", "/api/v1/orgs/%s/teams/search?q=%s", org.Name, "team")
161+
req.Header.Add("X-Csrf-Token", csrf)
158162
resp = session.MakeRequest(t, req, http.StatusForbidden)
159163

160164
}

models/action.go

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,32 @@ type ActionType int
2626

2727
// Possible action types.
2828
const (
29-
ActionCreateRepo ActionType = iota + 1 // 1
30-
ActionRenameRepo // 2
31-
ActionStarRepo // 3
32-
ActionWatchRepo // 4
33-
ActionCommitRepo // 5
34-
ActionCreateIssue // 6
35-
ActionCreatePullRequest // 7
36-
ActionTransferRepo // 8
37-
ActionPushTag // 9
38-
ActionCommentIssue // 10
39-
ActionMergePullRequest // 11
40-
ActionCloseIssue // 12
41-
ActionReopenIssue // 13
42-
ActionClosePullRequest // 14
43-
ActionReopenPullRequest // 15
44-
ActionDeleteTag // 16
45-
ActionDeleteBranch // 17
46-
ActionMirrorSyncPush // 18
47-
ActionMirrorSyncCreate // 19
48-
ActionMirrorSyncDelete // 20
49-
ActionApprovePullRequest // 21
50-
ActionRejectPullRequest // 22
51-
ActionCommentPull // 23
52-
ActionPublishRelease // 24
53-
ActionPullReviewDismissed // 25
29+
ActionCreateRepo ActionType = iota + 1 // 1
30+
ActionRenameRepo // 2
31+
ActionStarRepo // 3
32+
ActionWatchRepo // 4
33+
ActionCommitRepo // 5
34+
ActionCreateIssue // 6
35+
ActionCreatePullRequest // 7
36+
ActionTransferRepo // 8
37+
ActionPushTag // 9
38+
ActionCommentIssue // 10
39+
ActionMergePullRequest // 11
40+
ActionCloseIssue // 12
41+
ActionReopenIssue // 13
42+
ActionClosePullRequest // 14
43+
ActionReopenPullRequest // 15
44+
ActionDeleteTag // 16
45+
ActionDeleteBranch // 17
46+
ActionMirrorSyncPush // 18
47+
ActionMirrorSyncCreate // 19
48+
ActionMirrorSyncDelete // 20
49+
ActionApprovePullRequest // 21
50+
ActionRejectPullRequest // 22
51+
ActionCommentPull // 23
52+
ActionPublishRelease // 24
53+
ActionPullReviewDismissed // 25
54+
ActionPullRequestReadyForReview // 26
5455
)
5556

5657
// Action represents user operation type and other information to

models/consistency.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ func (milestone *Milestone) checkForConsistency(t *testing.T) {
141141
actual := getCount(t, x.Where("is_closed=?", true), &Issue{MilestoneID: milestone.ID})
142142
assert.EqualValues(t, milestone.NumClosedIssues, actual,
143143
"Unexpected number of closed issues for milestone %+v", milestone)
144+
145+
completeness := 0
146+
if milestone.NumIssues > 0 {
147+
completeness = milestone.NumClosedIssues * 100 / milestone.NumIssues
148+
}
149+
assert.Equal(t, completeness, milestone.Completeness)
144150
}
145151

146152
func (label *Label) checkForConsistency(t *testing.T) {

models/issue.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -647,8 +647,10 @@ func (issue *Issue) doChangeStatus(e *xorm.Session, doer *User, isMergePull bool
647647
}
648648

649649
// Update issue count of milestone
650-
if err := updateMilestoneClosedNum(e, issue.MilestoneID); err != nil {
651-
return nil, err
650+
if issue.MilestoneID > 0 {
651+
if err := updateMilestoneCounters(e, issue.MilestoneID); err != nil {
652+
return nil, err
653+
}
652654
}
653655

654656
if err := issue.updateClosedNum(e); err != nil {
@@ -907,7 +909,7 @@ func newIssue(e *xorm.Session, doer *User, opts NewIssueOptions) (err error) {
907909
}
908910

909911
if opts.Issue.MilestoneID > 0 {
910-
if _, err = e.Exec("UPDATE `milestone` SET num_issues=num_issues+1 WHERE id=?", opts.Issue.MilestoneID); err != nil {
912+
if err := updateMilestoneCounters(e, opts.Issue.MilestoneID); err != nil {
911913
return err
912914
}
913915

models/issue_milestone.go

Lines changed: 25 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,12 @@ func GetMilestoneByRepoIDANDName(repoID int64, name string) (*Milestone, error)
129129

130130
// GetMilestoneByID returns the milestone via id .
131131
func GetMilestoneByID(id int64) (*Milestone, error) {
132+
return getMilestoneByID(x, id)
133+
}
134+
135+
func getMilestoneByID(e Engine, id int64) (*Milestone, error) {
132136
var m Milestone
133-
has, err := x.ID(id).Get(&m)
137+
has, err := e.ID(id).Get(&m)
134138
if err != nil {
135139
return nil, err
136140
} else if !has {
@@ -155,10 +159,6 @@ func UpdateMilestone(m *Milestone, oldIsClosed bool) error {
155159
return err
156160
}
157161

158-
if err := updateMilestoneCompleteness(sess, m.ID); err != nil {
159-
return err
160-
}
161-
162162
// if IsClosed changed, update milestone numbers of repository
163163
if oldIsClosed != m.IsClosed {
164164
if err := updateRepoMilestoneNum(sess, m.RepoID); err != nil {
@@ -171,23 +171,31 @@ func UpdateMilestone(m *Milestone, oldIsClosed bool) error {
171171

172172
func updateMilestone(e Engine, m *Milestone) error {
173173
m.Name = strings.TrimSpace(m.Name)
174-
_, err := e.ID(m.ID).AllCols().
174+
_, err := e.ID(m.ID).AllCols().Update(m)
175+
if err != nil {
176+
return err
177+
}
178+
return updateMilestoneCounters(e, m.ID)
179+
}
180+
181+
// updateMilestoneCounters calculates NumIssues, NumClosesIssues and Completeness
182+
func updateMilestoneCounters(e Engine, id int64) error {
183+
_, err := e.ID(id).
175184
SetExpr("num_issues", builder.Select("count(*)").From("issue").Where(
176-
builder.Eq{"milestone_id": m.ID},
185+
builder.Eq{"milestone_id": id},
177186
)).
178187
SetExpr("num_closed_issues", builder.Select("count(*)").From("issue").Where(
179188
builder.Eq{
180-
"milestone_id": m.ID,
189+
"milestone_id": id,
181190
"is_closed": true,
182191
},
183192
)).
184-
Update(m)
185-
return err
186-
}
187-
188-
func updateMilestoneCompleteness(e Engine, milestoneID int64) error {
189-
_, err := e.Exec("UPDATE `milestone` SET completeness=100*num_closed_issues/(CASE WHEN num_issues > 0 THEN num_issues ELSE 1 END) WHERE id=?",
190-
milestoneID,
193+
Update(&Milestone{})
194+
if err != nil {
195+
return err
196+
}
197+
_, err = e.Exec("UPDATE `milestone` SET completeness=100*num_closed_issues/(CASE WHEN num_issues > 0 THEN num_issues ELSE 1 END) WHERE id=?",
198+
id,
191199
)
192200
return err
193201
}
@@ -256,25 +264,15 @@ func changeMilestoneAssign(e *xorm.Session, doer *User, issue *Issue, oldMilesto
256264
}
257265

258266
if oldMilestoneID > 0 {
259-
if err := updateMilestoneTotalNum(e, oldMilestoneID); err != nil {
267+
if err := updateMilestoneCounters(e, oldMilestoneID); err != nil {
260268
return err
261269
}
262-
if issue.IsClosed {
263-
if err := updateMilestoneClosedNum(e, oldMilestoneID); err != nil {
264-
return err
265-
}
266-
}
267270
}
268271

269272
if issue.MilestoneID > 0 {
270-
if err := updateMilestoneTotalNum(e, issue.MilestoneID); err != nil {
273+
if err := updateMilestoneCounters(e, issue.MilestoneID); err != nil {
271274
return err
272275
}
273-
if issue.IsClosed {
274-
if err := updateMilestoneClosedNum(e, issue.MilestoneID); err != nil {
275-
return err
276-
}
277-
}
278276
}
279277

280278
if oldMilestoneID > 0 || issue.MilestoneID > 0 {
@@ -622,29 +620,6 @@ func updateRepoMilestoneNum(e Engine, repoID int64) error {
622620
return err
623621
}
624622

625-
func updateMilestoneTotalNum(e Engine, milestoneID int64) (err error) {
626-
if _, err = e.Exec("UPDATE `milestone` SET num_issues=(SELECT count(*) FROM issue WHERE milestone_id=?) WHERE id=?",
627-
milestoneID,
628-
milestoneID,
629-
); err != nil {
630-
return
631-
}
632-
633-
return updateMilestoneCompleteness(e, milestoneID)
634-
}
635-
636-
func updateMilestoneClosedNum(e Engine, milestoneID int64) (err error) {
637-
if _, err = e.Exec("UPDATE `milestone` SET num_closed_issues=(SELECT count(*) FROM issue WHERE milestone_id=? AND is_closed=?) WHERE id=?",
638-
milestoneID,
639-
true,
640-
milestoneID,
641-
); err != nil {
642-
return
643-
}
644-
645-
return updateMilestoneCompleteness(e, milestoneID)
646-
}
647-
648623
// _____ _ _ _____ _
649624
// |_ _| __ __ _ ___| | _____ __| |_ _(_)_ __ ___ ___ ___
650625
// | || '__/ _` |/ __| |/ / _ \/ _` | | | | | '_ ` _ \ / _ \/ __|

models/issue_milestone_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ func TestChangeMilestoneStatus(t *testing.T) {
215215
CheckConsistencyFor(t, &Repository{ID: milestone.RepoID}, &Milestone{})
216216
}
217217

218-
func TestUpdateMilestoneClosedNum(t *testing.T) {
218+
func TestUpdateMilestoneCounters(t *testing.T) {
219219
assert.NoError(t, PrepareTestDatabase())
220220
issue := AssertExistsAndLoadBean(t, &Issue{MilestoneID: 1},
221221
"is_closed=0").(*Issue)
@@ -224,14 +224,14 @@ func TestUpdateMilestoneClosedNum(t *testing.T) {
224224
issue.ClosedUnix = timeutil.TimeStampNow()
225225
_, err := x.ID(issue.ID).Cols("is_closed", "closed_unix").Update(issue)
226226
assert.NoError(t, err)
227-
assert.NoError(t, updateMilestoneClosedNum(x, issue.MilestoneID))
227+
assert.NoError(t, updateMilestoneCounters(x, issue.MilestoneID))
228228
CheckConsistencyFor(t, &Milestone{})
229229

230230
issue.IsClosed = false
231231
issue.ClosedUnix = 0
232232
_, err = x.ID(issue.ID).Cols("is_closed", "closed_unix").Update(issue)
233233
assert.NoError(t, err)
234-
assert.NoError(t, updateMilestoneClosedNum(x, issue.MilestoneID))
234+
assert.NoError(t, updateMilestoneCounters(x, issue.MilestoneID))
235235
CheckConsistencyFor(t, &Milestone{})
236236
}
237237

models/notification.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,14 @@ func createOrUpdateIssueNotifications(e Engine, issueID, commentID, notification
207207
for _, id := range issueWatches {
208208
toNotify[id] = struct{}{}
209209
}
210-
211-
repoWatches, err := getRepoWatchersIDs(e, issue.RepoID)
212-
if err != nil {
213-
return err
214-
}
215-
for _, id := range repoWatches {
216-
toNotify[id] = struct{}{}
210+
if !(issue.IsPull && HasWorkInProgressPrefix(issue.Title)) {
211+
repoWatches, err := getRepoWatchersIDs(e, issue.RepoID)
212+
if err != nil {
213+
return err
214+
}
215+
for _, id := range repoWatches {
216+
toNotify[id] = struct{}{}
217+
}
217218
}
218219
issueParticipants, err := issue.getParticipantIDsByIssue(e)
219220
if err != nil {

models/pull.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,9 +595,13 @@ func (pr *PullRequest) IsWorkInProgress() bool {
595595
log.Error("LoadIssue: %v", err)
596596
return false
597597
}
598+
return HasWorkInProgressPrefix(pr.Issue.Title)
599+
}
598600

601+
// HasWorkInProgressPrefix determines if the given PR title has a Work In Progress prefix
602+
func HasWorkInProgressPrefix(title string) bool {
599603
for _, prefix := range setting.Repository.PullRequest.WorkInProgressPrefixes {
600-
if strings.HasPrefix(strings.ToUpper(pr.Issue.Title), prefix) {
604+
if strings.HasPrefix(strings.ToUpper(title), prefix) {
601605
return true
602606
}
603607
}

modules/markup/html.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -304,27 +304,26 @@ func postProcess(ctx *RenderContext, procs []processor, input io.Reader, output
304304
_, _ = res.WriteString("</body></html>")
305305

306306
// parse the HTML
307-
nodes, err := html.ParseFragment(res, nil)
307+
node, err := html.Parse(res)
308308
if err != nil {
309309
return &postProcessError{"invalid HTML", err}
310310
}
311311

312-
for _, node := range nodes {
313-
visitNode(ctx, procs, node, true)
312+
if node.Type == html.DocumentNode {
313+
node = node.FirstChild
314314
}
315315

316-
newNodes := make([]*html.Node, 0, len(nodes))
316+
visitNode(ctx, procs, node, true)
317317

318-
for _, node := range nodes {
319-
if node.Data == "html" {
320-
node = node.FirstChild
321-
for node != nil && node.Data != "body" {
322-
node = node.NextSibling
323-
}
324-
}
325-
if node == nil {
326-
continue
318+
newNodes := make([]*html.Node, 0, 5)
319+
320+
if node.Data == "html" {
321+
node = node.FirstChild
322+
for node != nil && node.Data != "body" {
323+
node = node.NextSibling
327324
}
325+
}
326+
if node != nil {
328327
if node.Data == "body" {
329328
child := node.FirstChild
330329
for child != nil {

0 commit comments

Comments
 (0)