Fix issue attachment handling (#24202)
Close #24195
Some of the changes are taken from my another fix
f07b0de997
in #20147 (although that PR was discarded ....)
The bug is:
1. The old code doesn't handle `removedfile` event correctly
2. The old code doesn't provide attachments for type=CommentTypeReview
This PR doesn't intend to refactor the "upload" code to a perfect state
(to avoid making the review difficult), so some legacy styles are kept.
---------
Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: Giteabot <teabot@gitea.io>
This commit is contained in:
parent
92e07f270a
commit
de2268ffab
12 changed files with 148 additions and 153 deletions
|
@ -52,84 +52,61 @@ func (err ErrCommentNotExist) Unwrap() error {
|
|||
// CommentType defines whether a comment is just a simple comment, an action (like close) or a reference.
|
||||
type CommentType int
|
||||
|
||||
// define unknown comment type
|
||||
const (
|
||||
CommentTypeUnknown CommentType = -1
|
||||
)
|
||||
// CommentTypeUndefined is used to search for comments of any type
|
||||
const CommentTypeUndefined CommentType = -1
|
||||
|
||||
// Enumerate all the comment types
|
||||
const (
|
||||
// 0 Plain comment, can be associated with a commit (CommitID > 0) and a line (LineNum > 0)
|
||||
CommentTypeComment CommentType = iota
|
||||
CommentTypeReopen // 1
|
||||
CommentTypeClose // 2
|
||||
CommentTypeComment CommentType = iota // 0 Plain comment, can be associated with a commit (CommitID > 0) and a line (LineNum > 0)
|
||||
|
||||
CommentTypeReopen // 1
|
||||
CommentTypeClose // 2
|
||||
|
||||
CommentTypeIssueRef // 3 References.
|
||||
CommentTypeCommitRef // 4 Reference from a commit (not part of a pull request)
|
||||
CommentTypeCommentRef // 5 Reference from a comment
|
||||
CommentTypePullRef // 6 Reference from a pull request
|
||||
|
||||
CommentTypeLabel // 7 Labels changed
|
||||
CommentTypeMilestone // 8 Milestone changed
|
||||
CommentTypeAssignees // 9 Assignees changed
|
||||
CommentTypeChangeTitle // 10 Change Title
|
||||
CommentTypeDeleteBranch // 11 Delete Branch
|
||||
|
||||
CommentTypeStartTracking // 12 Start a stopwatch for time tracking
|
||||
CommentTypeStopTracking // 13 Stop a stopwatch for time tracking
|
||||
CommentTypeAddTimeManual // 14 Add time manual for time tracking
|
||||
CommentTypeCancelTracking // 15 Cancel a stopwatch for time tracking
|
||||
CommentTypeAddedDeadline // 16 Added a due date
|
||||
CommentTypeModifiedDeadline // 17 Modified the due date
|
||||
CommentTypeRemovedDeadline // 18 Removed a due date
|
||||
|
||||
CommentTypeAddDependency // 19 Dependency added
|
||||
CommentTypeRemoveDependency // 20 Dependency removed
|
||||
|
||||
CommentTypeCode // 21 Comment a line of code
|
||||
CommentTypeReview // 22 Reviews a pull request by giving general feedback
|
||||
|
||||
CommentTypeLock // 23 Lock an issue, giving only collaborators access
|
||||
CommentTypeUnlock // 24 Unlocks a previously locked issue
|
||||
|
||||
CommentTypeChangeTargetBranch // 25 Change pull request's target branch
|
||||
|
||||
CommentTypeDeleteTimeManual // 26 Delete time manual for time tracking
|
||||
|
||||
CommentTypeReviewRequest // 27 add or remove Request from one
|
||||
CommentTypeMergePull // 28 merge pull request
|
||||
CommentTypePullRequestPush // 29 push to PR head branch
|
||||
|
||||
CommentTypeProject // 30 Project changed
|
||||
CommentTypeProjectBoard // 31 Project board changed
|
||||
|
||||
CommentTypeDismissReview // 32 Dismiss Review
|
||||
|
||||
CommentTypeChangeIssueRef // 33 Change issue ref
|
||||
|
||||
CommentTypePRScheduledToAutoMerge // 34 pr was scheduled to auto merge when checks succeed
|
||||
CommentTypePRUnScheduledToAutoMerge // 35 pr was un scheduled to auto merge when checks succeed
|
||||
|
||||
// 3 References.
|
||||
CommentTypeIssueRef
|
||||
// 4 Reference from a commit (not part of a pull request)
|
||||
CommentTypeCommitRef
|
||||
// 5 Reference from a comment
|
||||
CommentTypeCommentRef
|
||||
// 6 Reference from a pull request
|
||||
CommentTypePullRef
|
||||
// 7 Labels changed
|
||||
CommentTypeLabel
|
||||
// 8 Milestone changed
|
||||
CommentTypeMilestone
|
||||
// 9 Assignees changed
|
||||
CommentTypeAssignees
|
||||
// 10 Change Title
|
||||
CommentTypeChangeTitle
|
||||
// 11 Delete Branch
|
||||
CommentTypeDeleteBranch
|
||||
// 12 Start a stopwatch for time tracking
|
||||
CommentTypeStartTracking
|
||||
// 13 Stop a stopwatch for time tracking
|
||||
CommentTypeStopTracking
|
||||
// 14 Add time manual for time tracking
|
||||
CommentTypeAddTimeManual
|
||||
// 15 Cancel a stopwatch for time tracking
|
||||
CommentTypeCancelTracking
|
||||
// 16 Added a due date
|
||||
CommentTypeAddedDeadline
|
||||
// 17 Modified the due date
|
||||
CommentTypeModifiedDeadline
|
||||
// 18 Removed a due date
|
||||
CommentTypeRemovedDeadline
|
||||
// 19 Dependency added
|
||||
CommentTypeAddDependency
|
||||
// 20 Dependency removed
|
||||
CommentTypeRemoveDependency
|
||||
// 21 Comment a line of code
|
||||
CommentTypeCode
|
||||
// 22 Reviews a pull request by giving general feedback
|
||||
CommentTypeReview
|
||||
// 23 Lock an issue, giving only collaborators access
|
||||
CommentTypeLock
|
||||
// 24 Unlocks a previously locked issue
|
||||
CommentTypeUnlock
|
||||
// 25 Change pull request's target branch
|
||||
CommentTypeChangeTargetBranch
|
||||
// 26 Delete time manual for time tracking
|
||||
CommentTypeDeleteTimeManual
|
||||
// 27 add or remove Request from one
|
||||
CommentTypeReviewRequest
|
||||
// 28 merge pull request
|
||||
CommentTypeMergePull
|
||||
// 29 push to PR head branch
|
||||
CommentTypePullRequestPush
|
||||
// 30 Project changed
|
||||
CommentTypeProject
|
||||
// 31 Project board changed
|
||||
CommentTypeProjectBoard
|
||||
// 32 Dismiss Review
|
||||
CommentTypeDismissReview
|
||||
// 33 Change issue ref
|
||||
CommentTypeChangeIssueRef
|
||||
// 34 pr was scheduled to auto merge when checks succeed
|
||||
CommentTypePRScheduledToAutoMerge
|
||||
// 35 pr was un scheduled to auto merge when checks succeed
|
||||
CommentTypePRUnScheduledToAutoMerge
|
||||
)
|
||||
|
||||
var commentStrings = []string{
|
||||
|
@ -181,7 +158,23 @@ func AsCommentType(typeName string) CommentType {
|
|||
return CommentType(index)
|
||||
}
|
||||
}
|
||||
return CommentTypeUnknown
|
||||
return CommentTypeUndefined
|
||||
}
|
||||
|
||||
func (t CommentType) HasContentSupport() bool {
|
||||
switch t {
|
||||
case CommentTypeComment, CommentTypeCode, CommentTypeReview:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (t CommentType) HasAttachmentSupport() bool {
|
||||
switch t {
|
||||
case CommentTypeComment, CommentTypeCode, CommentTypeReview:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// RoleDescriptor defines comment tag type
|
||||
|
@ -1039,7 +1032,7 @@ func (opts *FindCommentsOptions) ToConds() builder.Cond {
|
|||
if opts.Before > 0 {
|
||||
cond = cond.And(builder.Lte{"comment.updated_unix": opts.Before})
|
||||
}
|
||||
if opts.Type != CommentTypeUnknown {
|
||||
if opts.Type != CommentTypeUndefined {
|
||||
cond = cond.And(builder.Eq{"comment.type": opts.Type})
|
||||
}
|
||||
if opts.Line != 0 {
|
||||
|
|
|
@ -64,8 +64,9 @@ func TestFetchCodeComments(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAsCommentType(t *testing.T) {
|
||||
assert.Equal(t, issues_model.CommentTypeUnknown, issues_model.AsCommentType(""))
|
||||
assert.Equal(t, issues_model.CommentTypeUnknown, issues_model.AsCommentType("nonsense"))
|
||||
assert.Equal(t, issues_model.CommentType(0), issues_model.CommentTypeComment)
|
||||
assert.Equal(t, issues_model.CommentTypeUndefined, issues_model.AsCommentType(""))
|
||||
assert.Equal(t, issues_model.CommentTypeUndefined, issues_model.AsCommentType("nonsense"))
|
||||
assert.Equal(t, issues_model.CommentTypeComment, issues_model.AsCommentType("comment"))
|
||||
assert.Equal(t, issues_model.CommentTypePRUnScheduledToAutoMerge, issues_model.AsCommentType("pull_cancel_scheduled_merge"))
|
||||
}
|
||||
|
|
|
@ -269,7 +269,7 @@ func (issue *Issue) LoadPullRequest(ctx context.Context) (err error) {
|
|||
}
|
||||
|
||||
func (issue *Issue) loadComments(ctx context.Context) (err error) {
|
||||
return issue.loadCommentsByType(ctx, CommentTypeUnknown)
|
||||
return issue.loadCommentsByType(ctx, CommentTypeUndefined)
|
||||
}
|
||||
|
||||
// LoadDiscussComments loads discuss comments
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue