mirror of
				https://github.com/go-gitea/gitea
				synced 2025-10-31 03:18:24 +00:00 
			
		
		
		
	Fix lint
This commit is contained in:
		| @@ -589,14 +589,13 @@ func (c *Comment) LoadAttachments(ctx context.Context) error { | |||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
| // UpdateAttachments update attachments by UUIDs for the comment | // UpdateCommentAttachments update attachments by UUIDs for the comment | ||||||
| func (c *Comment) UpdateAttachments(ctx context.Context, uuids []string) error { | func UpdateCommentAttachments(ctx context.Context, c *Comment, uuids []string) error { | ||||||
| 	ctx, committer, err := db.TxContext(ctx) | 	if len(uuids) == 0 { | ||||||
| 	if err != nil { | 		return nil | ||||||
| 		return err |  | ||||||
| 	} | 	} | ||||||
| 	defer committer.Close() |  | ||||||
|  |  | ||||||
|  | 	return db.WithTx(ctx, func(ctx context.Context) error { | ||||||
| 		attachments, err := repo_model.GetAttachmentsByUUIDs(ctx, uuids) | 		attachments, err := repo_model.GetAttachmentsByUUIDs(ctx, uuids) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return fmt.Errorf("getAttachmentsByUUIDs [uuids: %v]: %w", uuids, err) | 			return fmt.Errorf("getAttachmentsByUUIDs [uuids: %v]: %w", uuids, err) | ||||||
| @@ -608,7 +607,9 @@ func (c *Comment) UpdateAttachments(ctx context.Context, uuids []string) error { | |||||||
| 				return fmt.Errorf("update attachment [id: %d]: %w", attachments[i].ID, err) | 				return fmt.Errorf("update attachment [id: %d]: %w", attachments[i].ID, err) | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 	return committer.Commit() | 		c.Attachments = attachments | ||||||
|  | 		return nil | ||||||
|  | 	}) | ||||||
| } | } | ||||||
|  |  | ||||||
| // LoadAssigneeUserAndTeam if comment.Type is CommentTypeAssignees, then load assignees | // LoadAssigneeUserAndTeam if comment.Type is CommentTypeAssignees, then load assignees | ||||||
| @@ -875,7 +876,7 @@ func updateCommentInfos(ctx context.Context, opts *CreateCommentOptions, comment | |||||||
| 	// Check comment type. | 	// Check comment type. | ||||||
| 	switch opts.Type { | 	switch opts.Type { | ||||||
| 	case CommentTypeCode: | 	case CommentTypeCode: | ||||||
| 		if err = updateAttachments(ctx, opts, comment); err != nil { | 		if err = UpdateCommentAttachments(ctx, comment, opts.Attachments); err != nil { | ||||||
| 			return err | 			return err | ||||||
| 		} | 		} | ||||||
| 		if comment.ReviewID != 0 { | 		if comment.ReviewID != 0 { | ||||||
| @@ -895,7 +896,7 @@ func updateCommentInfos(ctx context.Context, opts *CreateCommentOptions, comment | |||||||
| 		} | 		} | ||||||
| 		fallthrough | 		fallthrough | ||||||
| 	case CommentTypeReview: | 	case CommentTypeReview: | ||||||
| 		if err = updateAttachments(ctx, opts, comment); err != nil { | 		if err = UpdateCommentAttachments(ctx, comment, opts.Attachments); err != nil { | ||||||
| 			return err | 			return err | ||||||
| 		} | 		} | ||||||
| 	case CommentTypeReopen, CommentTypeClose: | 	case CommentTypeReopen, CommentTypeClose: | ||||||
| @@ -907,23 +908,6 @@ func updateCommentInfos(ctx context.Context, opts *CreateCommentOptions, comment | |||||||
| 	return UpdateIssueCols(ctx, opts.Issue, "updated_unix") | 	return UpdateIssueCols(ctx, opts.Issue, "updated_unix") | ||||||
| } | } | ||||||
|  |  | ||||||
| func updateAttachments(ctx context.Context, opts *CreateCommentOptions, comment *Comment) error { |  | ||||||
| 	attachments, err := repo_model.GetAttachmentsByUUIDs(ctx, opts.Attachments) |  | ||||||
| 	if err != nil { |  | ||||||
| 		return fmt.Errorf("getAttachmentsByUUIDs [uuids: %v]: %w", opts.Attachments, err) |  | ||||||
| 	} |  | ||||||
| 	for i := range attachments { |  | ||||||
| 		attachments[i].IssueID = opts.Issue.ID |  | ||||||
| 		attachments[i].CommentID = comment.ID |  | ||||||
| 		// No assign value could be 0, so ignore AllCols(). |  | ||||||
| 		if _, err = db.GetEngine(ctx).ID(attachments[i].ID).Update(attachments[i]); err != nil { |  | ||||||
| 			return fmt.Errorf("update attachment [%d]: %w", attachments[i].ID, err) |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 	comment.Attachments = attachments |  | ||||||
| 	return nil |  | ||||||
| } |  | ||||||
|  |  | ||||||
| func createDeadlineComment(ctx context.Context, doer *user_model.User, issue *Issue, newDeadlineUnix timeutil.TimeStamp) (*Comment, error) { | func createDeadlineComment(ctx context.Context, doer *user_model.User, issue *Issue, newDeadlineUnix timeutil.TimeStamp) (*Comment, error) { | ||||||
| 	var content string | 	var content string | ||||||
| 	var commentType CommentType | 	var commentType CommentType | ||||||
|   | |||||||
| @@ -182,11 +182,10 @@ func AddDeletePRBranchComment(ctx context.Context, doer *user_model.User, repo * | |||||||
|  |  | ||||||
| // UpdateIssueAttachments update attachments by UUIDs for the issue | // UpdateIssueAttachments update attachments by UUIDs for the issue | ||||||
| func UpdateIssueAttachments(ctx context.Context, issueID int64, uuids []string) (err error) { | func UpdateIssueAttachments(ctx context.Context, issueID int64, uuids []string) (err error) { | ||||||
| 	ctx, committer, err := db.TxContext(ctx) | 	if len(uuids) == 0 { | ||||||
| 	if err != nil { | 		return nil | ||||||
| 		return err |  | ||||||
| 	} | 	} | ||||||
| 	defer committer.Close() | 	return db.WithTx(ctx, func(ctx context.Context) error { | ||||||
| 		attachments, err := repo_model.GetAttachmentsByUUIDs(ctx, uuids) | 		attachments, err := repo_model.GetAttachmentsByUUIDs(ctx, uuids) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return fmt.Errorf("getAttachmentsByUUIDs [uuids: %v]: %w", uuids, err) | 			return fmt.Errorf("getAttachmentsByUUIDs [uuids: %v]: %w", uuids, err) | ||||||
| @@ -197,7 +196,8 @@ func UpdateIssueAttachments(ctx context.Context, issueID int64, uuids []string) | |||||||
| 				return fmt.Errorf("update attachment [id: %d]: %w", attachments[i].ID, err) | 				return fmt.Errorf("update attachment [id: %d]: %w", attachments[i].ID, err) | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 	return committer.Commit() | 		return nil | ||||||
|  | 	}) | ||||||
| } | } | ||||||
|  |  | ||||||
| // NewIssueOptions represents the options of a new issue. | // NewIssueOptions represents the options of a new issue. | ||||||
| @@ -293,19 +293,6 @@ func NewIssueWithIndex(ctx context.Context, doer *user_model.User, opts NewIssue | |||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if len(opts.Attachments) > 0 { |  | ||||||
| 		attachments, err := repo_model.GetAttachmentsByUUIDs(ctx, opts.Attachments) |  | ||||||
| 		if err != nil { |  | ||||||
| 			return fmt.Errorf("getAttachmentsByUUIDs [uuids: %v]: %w", opts.Attachments, err) |  | ||||||
| 		} |  | ||||||
|  |  | ||||||
| 		for i := 0; i < len(attachments); i++ { |  | ||||||
| 			attachments[i].IssueID = opts.Issue.ID |  | ||||||
| 			if _, err = e.ID(attachments[i].ID).Update(attachments[i]); err != nil { |  | ||||||
| 				return fmt.Errorf("update attachment [id: %d]: %w", attachments[i].ID, err) |  | ||||||
| 			} |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 	if err = opts.Issue.LoadAttributes(ctx); err != nil { | 	if err = opts.Issue.LoadAttributes(ctx); err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -612,7 +612,7 @@ func updateAttachments(ctx *context.Context, item any, files []string) error { | |||||||
| 		case *issues_model.Issue: | 		case *issues_model.Issue: | ||||||
| 			err = issues_model.UpdateIssueAttachments(ctx, content.ID, files) | 			err = issues_model.UpdateIssueAttachments(ctx, content.ID, files) | ||||||
| 		case *issues_model.Comment: | 		case *issues_model.Comment: | ||||||
| 			err = content.UpdateAttachments(ctx, files) | 			err = issues_model.UpdateCommentAttachments(ctx, content, files) | ||||||
| 		default: | 		default: | ||||||
| 			return fmt.Errorf("unknown Type: %T", content) | 			return fmt.Errorf("unknown Type: %T", content) | ||||||
| 		} | 		} | ||||||
|   | |||||||
| @@ -235,6 +235,9 @@ func NewPullRequest(ctx context.Context, opts *NewPullRequestOptions) error { | |||||||
| 		notify_service.IssueChangeAssignee(ctx, issue.Poster, issue, assignee, false, assigneeCommentMap[assigneeID]) | 		notify_service.IssueChangeAssignee(ctx, issue.Poster, issue, assignee, false, assigneeCommentMap[assigneeID]) | ||||||
| 	} | 	} | ||||||
| 	permDoer, err := access_model.GetUserRepoPermission(ctx, repo, issue.Poster) | 	permDoer, err := access_model.GetUserRepoPermission(ctx, repo, issue.Poster) | ||||||
|  | 	if err != nil { | ||||||
|  | 		return err | ||||||
|  | 	} | ||||||
| 	for _, reviewer := range opts.Reviewers { | 	for _, reviewer := range opts.Reviewers { | ||||||
| 		if _, err = issue_service.ReviewRequest(ctx, pr.Issue, issue.Poster, &permDoer, reviewer, true); err != nil { | 		if _, err = issue_service.ReviewRequest(ctx, pr.Issue, issue.Poster, &permDoer, reviewer, true); err != nil { | ||||||
| 			return err | 			return err | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user