Skip to content

Commit 95c57a1

Browse files
committed
Clean up code based on lint
1 parent bea92f6 commit 95c57a1

File tree

17 files changed

+204
-520
lines changed

17 files changed

+204
-520
lines changed

models/conversations/comment.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package conversations
55
import (
66
"context"
77
"fmt"
8+
"html/template"
89

910
"code.gitea.io/gitea/models/db"
1011
repo_model "code.gitea.io/gitea/models/repo"
@@ -17,8 +18,6 @@ import (
1718
"code.gitea.io/gitea/modules/translation"
1819
"code.gitea.io/gitea/modules/util"
1920

20-
"html/template"
21-
2221
"xorm.io/builder"
2322
)
2423

@@ -527,11 +526,11 @@ func (c *Comment) UpdateAttachments(ctx context.Context, uuids []string) error {
527526
}
528527

529528
// HashTag returns unique hash tag for conversation.
530-
func (comment *Comment) HashTag() string {
531-
return fmt.Sprintf("comment-%d", comment.ID)
529+
func (c *Comment) HashTag() string {
530+
return fmt.Sprintf("comment-%d", c.ID)
532531
}
533532

534-
func (c *Comment) hashLink(ctx context.Context) string {
533+
func (c *Comment) hashLink() string {
535534
return "#" + c.HashTag()
536535
}
537536

@@ -547,7 +546,7 @@ func (c *Comment) HTMLURL(ctx context.Context) string {
547546
log.Error("loadRepo(%d): %v", c.Conversation.RepoID, err)
548547
return ""
549548
}
550-
return c.Conversation.HTMLURL() + c.hashLink(ctx)
549+
return c.Conversation.HTMLURL() + c.hashLink()
551550
}
552551

553552
// APIURL formats a API-string to the conversation-comment

models/conversations/comment_list.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,5 @@ func (comments CommentList) LoadAttributes(ctx context.Context) (err error) {
189189
return err
190190
}
191191

192-
if err = comments.LoadConversations(ctx); err != nil {
193-
return err
194-
}
195-
196-
return nil
192+
return comments.LoadConversations(ctx)
197193
}

models/conversations/conversation.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,7 @@ func (conversation *Conversation) LoadAttributes(ctx context.Context) (err error
211211
return err
212212
}
213213

214-
if err = conversation.Comments.LoadAttributes(ctx); err != nil {
215-
return err
216-
}
217-
218-
return nil
214+
return conversation.Comments.LoadAttributes(ctx)
219215
}
220216

221217
// LoadRepo loads conversation's repository

models/conversations/conversation_search.go

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ import (
77
"context"
88
"fmt"
99
"strconv"
10-
"strings"
1110

1211
"code.gitea.io/gitea/models/db"
1312
"code.gitea.io/gitea/models/organization"
1413
repo_model "code.gitea.io/gitea/models/repo"
15-
"code.gitea.io/gitea/models/unit"
1614
user_model "code.gitea.io/gitea/models/user"
1715
"code.gitea.io/gitea/modules/container"
1816
"code.gitea.io/gitea/modules/optional"
@@ -259,48 +257,6 @@ func applyConditions(sess *xorm.Session, opts *ConversationsOptions) {
259257
applyLabelsCondition(sess, opts)
260258
}
261259

262-
// teamUnitsRepoCond returns query condition for those repo id in the special org team with special units access
263-
func teamUnitsRepoCond(id string, userID, orgID, teamID int64, units ...unit.Type) builder.Cond {
264-
return builder.In(id,
265-
builder.Select("repo_id").From("team_repo").Where(
266-
builder.Eq{
267-
"team_id": teamID,
268-
}.And(
269-
builder.Or(
270-
// Check if the user is member of the team.
271-
builder.In(
272-
"team_id", builder.Select("team_id").From("team_user").Where(
273-
builder.Eq{
274-
"uid": userID,
275-
},
276-
),
277-
),
278-
// Check if the user is in the owner team of the organisation.
279-
builder.Exists(builder.Select("team_id").From("team_user").
280-
Where(builder.Eq{
281-
"org_id": orgID,
282-
"team_id": builder.Select("id").From("team").Where(
283-
builder.Eq{
284-
"org_id": orgID,
285-
"lower_name": strings.ToLower(organization.OwnerTeamName),
286-
}),
287-
"uid": userID,
288-
}),
289-
),
290-
)).And(
291-
builder.In(
292-
"team_id", builder.Select("team_id").From("team_unit").Where(
293-
builder.Eq{
294-
"`team_unit`.org_id": orgID,
295-
}.And(
296-
builder.In("`team_unit`.type", units),
297-
),
298-
),
299-
),
300-
),
301-
))
302-
}
303-
304260
func applyPosterCondition(sess *xorm.Session, posterID int64) {
305261
sess.And("conversation.poster_id=?", posterID)
306262
}

models/conversations/conversation_user.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ func GetConversationMentionIDs(ctx context.Context, conversationID int64) ([]int
6666

6767
// NewConversationUsers inserts an conversation related users
6868
func NewConversationUsers(ctx context.Context, repo *repo_model.Repository, conversation *Conversation) error {
69-
7069
// Leave a seat for poster itself to append later, but if poster is one of assignee
7170
// and just waste 1 unit is cheaper than re-allocate memory once.
7271
conversationUsers := make([]*ConversationUser, 0, 1)

models/unit/unit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const (
3131
TypeProjects // 8 Projects
3232
TypePackages // 9 Packages
3333
TypeActions // 10 Actions
34-
TypeConversations //11 Conversations
34+
TypeConversations // 11 Conversations
3535
)
3636

3737
// Value returns integer value for unit type (used by template)

modules/structs/conversation.go

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,11 @@ import (
1616
// Conversation represents an conversation in a repository
1717
// swagger:model
1818
type Conversation struct {
19-
ID int64 `json:"id"`
20-
URL string `json:"url"`
21-
HTMLURL string `json:"html_url"`
22-
Index int64 `json:"number"`
23-
Poster *User `json:"user"`
24-
OriginalAuthor string `json:"original_author"`
25-
OriginalAuthorID int64 `json:"original_author_id"`
26-
Title string `json:"title"`
27-
Body string `json:"body"`
28-
Ref string `json:"ref"`
29-
Attachments []*Attachment `json:"assets"`
30-
Labels []*Label `json:"labels"`
31-
Milestone *Milestone `json:"milestone"`
32-
// deprecated
33-
Assignee *User `json:"assignee"`
34-
Assignees []*User `json:"assignees"`
19+
ID int64 `json:"id"`
20+
URL string `json:"url"`
21+
HTMLURL string `json:"html_url"`
22+
Index int64 `json:"number"`
23+
Ref string `json:"ref"`
3524
// Whether the conversation is open or locked
3625
//
3726
// type: string
@@ -48,35 +37,12 @@ type Conversation struct {
4837
// swagger:strfmt date-time
4938
Deadline *time.Time `json:"due_date"`
5039

51-
PullRequest *PullRequestMeta `json:"pull_request"`
52-
Repo *RepositoryMeta `json:"repository"`
53-
54-
PinOrder int `json:"pin_order"`
40+
Repo *RepositoryMeta `json:"repository"`
5541
}
5642

5743
// CreateConversationOption options to create one conversation
5844
type CreateConversationOption struct {
59-
// required:true
60-
Title string `json:"title" binding:"Required"`
61-
Body string `json:"body"`
62-
Ref string `json:"ref"`
63-
// deprecated
64-
Assignee string `json:"assignee"`
65-
Assignees []string `json:"assignees"`
66-
// swagger:strfmt date-time
67-
Deadline *time.Time `json:"due_date"`
68-
// milestone id
69-
Milestone int64 `json:"milestone"`
70-
// list of label ids
71-
Labels []int64 `json:"labels"`
72-
Locked bool `json:"locked"`
73-
}
74-
75-
// EditConversationOption options for editing an conversation
76-
type EditConversationOption struct {
77-
Title string `json:"title"`
78-
Body *string `json:"body"`
79-
Ref *string `json:"ref"`
45+
Locked bool `json:"locked"`
8046
}
8147

8248
// ConversationFormFieldType defines conversation form field type, can be "markdown", "textarea", "input", "dropdown" or "checkboxes"

routers/api/v1/api.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,6 @@ func mustEnableConversations(ctx *context.APIContext) {
672672
ctx.NotFound()
673673
return
674674
}
675-
676675
}
677676

678677
func mustEnableIssuesOrPulls(ctx *context.APIContext) {
@@ -1514,7 +1513,6 @@ func Routes() *web.Router {
15141513
// m.Combo("/{id}", reqToken()).Patch(bind(api.EditIssueCommentOption{}), repo.EditIssueCommentDeprecated).
15151514
// Delete(repo.DeleteIssueCommentDeprecated)
15161515
})
1517-
15181516
}, mustEnableConversations)
15191517
})
15201518
})

0 commit comments

Comments
 (0)