Skip to content

Commit 5e20a94

Browse files
authored
Merge branch 'main' into fix-17077
2 parents 4016938 + 0b368aa commit 5e20a94

File tree

11 files changed

+77
-42
lines changed

11 files changed

+77
-42
lines changed

models/notification.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -772,20 +772,20 @@ func setRepoNotificationStatusReadIfUnread(e Engine, userID, repoID int64) error
772772
}
773773

774774
// SetNotificationStatus change the notification status
775-
func SetNotificationStatus(notificationID int64, user *User, status NotificationStatus) error {
775+
func SetNotificationStatus(notificationID int64, user *User, status NotificationStatus) (*Notification, error) {
776776
notification, err := getNotificationByID(x, notificationID)
777777
if err != nil {
778-
return err
778+
return notification, err
779779
}
780780

781781
if notification.UserID != user.ID {
782-
return fmt.Errorf("Can't change notification of another user: %d, %d", notification.UserID, user.ID)
782+
return nil, fmt.Errorf("Can't change notification of another user: %d, %d", notification.UserID, user.ID)
783783
}
784784

785785
notification.Status = status
786786

787787
_, err = x.ID(notificationID).Update(notification)
788-
return err
788+
return notification, err
789789
}
790790

791791
// GetNotificationByID return notification by ID

models/notification_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,15 @@ func TestSetNotificationStatus(t *testing.T) {
7676
user := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
7777
notf := AssertExistsAndLoadBean(t,
7878
&Notification{UserID: user.ID, Status: NotificationStatusRead}).(*Notification)
79-
assert.NoError(t, SetNotificationStatus(notf.ID, user, NotificationStatusPinned))
79+
_, err := SetNotificationStatus(notf.ID, user, NotificationStatusPinned)
80+
assert.NoError(t, err)
8081
AssertExistsAndLoadBean(t,
8182
&Notification{ID: notf.ID, Status: NotificationStatusPinned})
8283

83-
assert.Error(t, SetNotificationStatus(1, user, NotificationStatusRead))
84-
assert.Error(t, SetNotificationStatus(NonexistentID, user, NotificationStatusRead))
84+
_, err = SetNotificationStatus(1, user, NotificationStatusRead)
85+
assert.Error(t, err)
86+
_, err = SetNotificationStatus(NonexistentID, user, NotificationStatusRead)
87+
assert.Error(t, err)
8588
}
8689

8790
func TestUpdateNotificationStatuses(t *testing.T) {

modules/git/batch_reader.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ import (
88
"bufio"
99
"bytes"
1010
"context"
11+
"fmt"
1112
"io"
1213
"math"
14+
"runtime"
1315
"strconv"
1416
"strings"
1517

@@ -40,9 +42,14 @@ func CatFileBatchCheck(repoPath string) (WriteCloserError, *bufio.Reader, func()
4042
<-closed
4143
}
4244

45+
_, filename, line, _ := runtime.Caller(2)
46+
filename = strings.TrimPrefix(filename, callerPrefix)
47+
4348
go func() {
4449
stderr := strings.Builder{}
45-
err := NewCommandContext(ctx, "cat-file", "--batch-check").RunInDirFullPipeline(repoPath, batchStdoutWriter, &stderr, batchStdinReader)
50+
err := NewCommandContext(ctx, "cat-file", "--batch-check").
51+
SetDescription(fmt.Sprintf("%s cat-file --batch-check [repo_path: %s] (%s:%d)", GitExecutable, repoPath, filename, line)).
52+
RunInDirFullPipeline(repoPath, batchStdoutWriter, &stderr, batchStdinReader)
4653
if err != nil {
4754
_ = batchStdoutWriter.CloseWithError(ConcatenateError(err, (&stderr).String()))
4855
_ = batchStdinReader.CloseWithError(ConcatenateError(err, (&stderr).String()))
@@ -76,9 +83,14 @@ func CatFileBatch(repoPath string) (WriteCloserError, *bufio.Reader, func()) {
7683
<-closed
7784
}
7885

86+
_, filename, line, _ := runtime.Caller(2)
87+
filename = strings.TrimPrefix(filename, callerPrefix)
88+
7989
go func() {
8090
stderr := strings.Builder{}
81-
err := NewCommandContext(ctx, "cat-file", "--batch").RunInDirFullPipeline(repoPath, batchStdoutWriter, &stderr, batchStdinReader)
91+
err := NewCommandContext(ctx, "cat-file", "--batch").
92+
SetDescription(fmt.Sprintf("%s cat-file --batch [repo_path: %s] (%s:%d)", GitExecutable, repoPath, filename, line)).
93+
RunInDirFullPipeline(repoPath, batchStdoutWriter, &stderr, batchStdinReader)
8294
if err != nil {
8395
_ = batchStdoutWriter.CloseWithError(ConcatenateError(err, (&stderr).String()))
8496
_ = batchStdinReader.CloseWithError(ConcatenateError(err, (&stderr).String()))
@@ -292,3 +304,10 @@ func ParseTreeLine(rd *bufio.Reader, modeBuf, fnameBuf, shaBuf []byte) (mode, fn
292304
sha = shaBuf
293305
return
294306
}
307+
308+
var callerPrefix string
309+
310+
func init() {
311+
_, filename, _, _ := runtime.Caller(0)
312+
callerPrefix = strings.TrimSuffix(filename, "modules/git/batch_reader.go")
313+
}

options/locale/locale_el-GR.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2732,7 +2732,7 @@ comment_issue=`σχολίασε στο ζήτημα <a href="%s/issues/%s">%s#%[
27322732
comment_pull=`σχολίασε στο pull request <a href="%s/pulls/%s">%s#%[2]s</a>`
27332733
merge_pull_request=`συγχώνευσε το pull request <a href="%s/pulls/%s">%s#%[2]s</a>`
27342734
transfer_repo=μετέφερε το αποθετήριο <code>%s</code> σε <a href="%s">%s</a>
2735-
push_tag=ώθησε την ετικέτα <a href="%s/src/tag/%s">%[4]s</a> σε <a href="%[1]s">%[3]s</a>
2735+
push_tag=ώθησε την ετικέτα <a href="%s/src/tag/%s">%[4]s</a> στο <a href="%[1]s">%[3]s</a>
27362736
delete_tag=διέγραψε την ετικέτα %[2]s από <a href="%[1]s">%[3]s</a>
27372737
delete_branch=διέγραψε το κλάδο %[2]s από <a href="%[1]s">%[3]s</a>
27382738
compare_branch=Σύγκριση

routers/api/v1/notify/repo.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"code.gitea.io/gitea/modules/context"
1414
"code.gitea.io/gitea/modules/convert"
1515
"code.gitea.io/gitea/modules/log"
16+
"code.gitea.io/gitea/modules/structs"
1617
)
1718

1819
func statusStringToNotificationStatus(status string) models.NotificationStatus {
@@ -176,7 +177,7 @@ func ReadRepoNotifications(ctx *context.APIContext) {
176177
// required: false
177178
// responses:
178179
// "205":
179-
// "$ref": "#/responses/empty"
180+
// "$ref": "#/responses/NotificationThreadList"
180181

181182
lastRead := int64(0)
182183
qLastRead := ctx.FormTrim("last_read_at")
@@ -213,14 +214,16 @@ func ReadRepoNotifications(ctx *context.APIContext) {
213214
targetStatus = models.NotificationStatusRead
214215
}
215216

217+
changed := make([]*structs.NotificationThread, len(nl))
218+
216219
for _, n := range nl {
217-
err := models.SetNotificationStatus(n.ID, ctx.User, targetStatus)
220+
notif, err := models.SetNotificationStatus(n.ID, ctx.User, targetStatus)
218221
if err != nil {
219222
ctx.InternalServerError(err)
220223
return
221224
}
222-
ctx.Status(http.StatusResetContent)
225+
_ = notif.LoadAttributes()
226+
changed = append(changed, convert.ToNotificationThread(notif))
223227
}
224-
225-
ctx.Status(http.StatusResetContent)
228+
ctx.JSON(http.StatusResetContent, changed)
226229
}

routers/api/v1/notify/threads.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func ReadThread(ctx *context.APIContext) {
7171
// required: false
7272
// responses:
7373
// "205":
74-
// "$ref": "#/responses/empty"
74+
// "$ref": "#/responses/NotificationThread"
7575
// "403":
7676
// "$ref": "#/responses/forbidden"
7777
// "404":
@@ -87,12 +87,16 @@ func ReadThread(ctx *context.APIContext) {
8787
targetStatus = models.NotificationStatusRead
8888
}
8989

90-
err := models.SetNotificationStatus(n.ID, ctx.User, targetStatus)
90+
notif, err := models.SetNotificationStatus(n.ID, ctx.User, targetStatus)
9191
if err != nil {
9292
ctx.InternalServerError(err)
9393
return
9494
}
95-
ctx.Status(http.StatusResetContent)
95+
if err = notif.LoadAttributes(); err != nil {
96+
ctx.InternalServerError(err)
97+
return
98+
}
99+
ctx.JSON(http.StatusResetContent, convert.ToNotificationThread(notif))
96100
}
97101

98102
func getThread(ctx *context.APIContext) *models.Notification {

routers/api/v1/notify/user.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"code.gitea.io/gitea/models"
1212
"code.gitea.io/gitea/modules/context"
1313
"code.gitea.io/gitea/modules/convert"
14+
"code.gitea.io/gitea/modules/structs"
1415
)
1516

1617
// ListNotifications list users's notification threads
@@ -125,7 +126,7 @@ func ReadNotifications(ctx *context.APIContext) {
125126
// required: false
126127
// responses:
127128
// "205":
128-
// "$ref": "#/responses/empty"
129+
// "$ref": "#/responses/NotificationThreadList"
129130

130131
lastRead := int64(0)
131132
qLastRead := ctx.FormTrim("last_read_at")
@@ -158,14 +159,17 @@ func ReadNotifications(ctx *context.APIContext) {
158159
targetStatus = models.NotificationStatusRead
159160
}
160161

162+
changed := make([]*structs.NotificationThread, 0, len(nl))
163+
161164
for _, n := range nl {
162-
err := models.SetNotificationStatus(n.ID, ctx.User, targetStatus)
165+
notif, err := models.SetNotificationStatus(n.ID, ctx.User, targetStatus)
163166
if err != nil {
164167
ctx.InternalServerError(err)
165168
return
166169
}
167-
ctx.Status(http.StatusResetContent)
170+
_ = notif.LoadAttributes()
171+
changed = append(changed, convert.ToNotificationThread(notif))
168172
}
169173

170-
ctx.Status(http.StatusResetContent)
174+
ctx.JSON(http.StatusResetContent, changed)
171175
}

routers/api/v1/repo/file.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,15 @@ func GetArchive(ctx *context.APIContext) {
119119
// "$ref": "#/responses/notFound"
120120

121121
repoPath := models.RepoPath(ctx.Params(":username"), ctx.Params(":reponame"))
122-
gitRepo, err := git.OpenRepository(repoPath)
123-
if err != nil {
124-
ctx.Error(http.StatusInternalServerError, "OpenRepository", err)
125-
return
122+
if ctx.Repo.GitRepo == nil {
123+
gitRepo, err := git.OpenRepository(repoPath)
124+
if err != nil {
125+
ctx.Error(http.StatusInternalServerError, "OpenRepository", err)
126+
return
127+
}
128+
ctx.Repo.GitRepo = gitRepo
129+
defer gitRepo.Close()
126130
}
127-
ctx.Repo.GitRepo = gitRepo
128-
defer gitRepo.Close()
129131

130132
repo.Download(ctx.Context)
131133
}

routers/api/v1/repo/issue.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -317,27 +317,27 @@ func ListIssues(ctx *context.APIContext) {
317317
// type: string
318318
// - name: since
319319
// in: query
320-
// description: Only show notifications updated after the given time. This is a timestamp in RFC 3339 format
320+
// description: Only show items updated after the given time. This is a timestamp in RFC 3339 format
321321
// type: string
322322
// format: date-time
323323
// required: false
324324
// - name: before
325325
// in: query
326-
// description: Only show notifications updated before the given time. This is a timestamp in RFC 3339 format
326+
// description: Only show items updated before the given time. This is a timestamp in RFC 3339 format
327327
// type: string
328328
// format: date-time
329329
// required: false
330330
// - name: created_by
331331
// in: query
332-
// description: filter (issues / pulls) created to
332+
// description: Only show items which were created by the the given user
333333
// type: string
334334
// - name: assigned_by
335335
// in: query
336-
// description: filter (issues / pulls) assigned to
336+
// description: Only show items for which the given user is assigned
337337
// type: string
338338
// - name: mentioned_by
339339
// in: query
340-
// description: filter (issues / pulls) mentioning to
340+
// description: Only show items in which the given user was mentioned
341341
// type: string
342342
// - name: page
343343
// in: query

routers/web/user/notification.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func NotificationStatusPost(c *context.Context) {
160160
return
161161
}
162162

163-
if err := models.SetNotificationStatus(notificationID, c.User, status); err != nil {
163+
if _, err := models.SetNotificationStatus(notificationID, c.User, status); err != nil {
164164
c.ServerError("SetNotificationStatus", err)
165165
return
166166
}

templates/swagger/v1_json.tmpl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@
739739
],
740740
"responses": {
741741
"205": {
742-
"$ref": "#/responses/empty"
742+
"$ref": "#/responses/NotificationThreadList"
743743
}
744744
}
745745
}
@@ -822,7 +822,7 @@
822822
],
823823
"responses": {
824824
"205": {
825-
"$ref": "#/responses/empty"
825+
"$ref": "#/responses/NotificationThread"
826826
},
827827
"403": {
828828
"$ref": "#/responses/forbidden"
@@ -4334,32 +4334,32 @@
43344334
{
43354335
"type": "string",
43364336
"format": "date-time",
4337-
"description": "Only show notifications updated after the given time. This is a timestamp in RFC 3339 format",
4337+
"description": "Only show items updated after the given time. This is a timestamp in RFC 3339 format",
43384338
"name": "since",
43394339
"in": "query"
43404340
},
43414341
{
43424342
"type": "string",
43434343
"format": "date-time",
4344-
"description": "Only show notifications updated before the given time. This is a timestamp in RFC 3339 format",
4344+
"description": "Only show items updated before the given time. This is a timestamp in RFC 3339 format",
43454345
"name": "before",
43464346
"in": "query"
43474347
},
43484348
{
43494349
"type": "string",
4350-
"description": "filter (issues / pulls) created to",
4350+
"description": "Only show items which were created by the the given user",
43514351
"name": "created_by",
43524352
"in": "query"
43534353
},
43544354
{
43554355
"type": "string",
4356-
"description": "filter (issues / pulls) assigned to",
4356+
"description": "Only show items for which the given user is assigned",
43574357
"name": "assigned_by",
43584358
"in": "query"
43594359
},
43604360
{
43614361
"type": "string",
4362-
"description": "filter (issues / pulls) mentioning to",
4362+
"description": "Only show items in which the given user was mentioned",
43634363
"name": "mentioned_by",
43644364
"in": "query"
43654365
},
@@ -7058,7 +7058,7 @@
70587058
],
70597059
"responses": {
70607060
"205": {
7061-
"$ref": "#/responses/empty"
7061+
"$ref": "#/responses/NotificationThreadList"
70627062
}
70637063
}
70647064
}

0 commit comments

Comments
 (0)