Include resource state events in Gitlab downloads (#29382)

Some specific events on Gitlab issues and merge requests are stored
separately from comments as "resource state events". With this change,
all relevant resource state events are downloaded during issue and merge
request migration, and converted to comments.

This PR also updates the template used to render comments to add support
for migrated comments of these types.

ref: https://docs.gitlab.com/ee/api/resource_state_events.html
pull/29417/head^2
Sebastian Brückner 9 months ago committed by GitHub
parent 65952417a8
commit 17f170ee37
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 6
      services/migrations/gitea_uploader.go
  2. 54
      services/migrations/gitlab.go
  3. 55
      templates/repo/issue/view_content/comments.tmpl
  4. 11
      templates/repo/issue/view_content/comments_authorlink.tmpl

@ -483,6 +483,10 @@ func (g *GiteaLocalUploader) CreateComments(comments ...*base.Comment) error {
}
switch cm.Type {
case issues_model.CommentTypeReopen:
cm.Content = ""
case issues_model.CommentTypeClose:
cm.Content = ""
case issues_model.CommentTypeAssignees:
if assigneeID, ok := comment.Meta["AssigneeID"].(int); ok {
cm.AssigneeID = int64(assigneeID)
@ -503,6 +507,8 @@ func (g *GiteaLocalUploader) CreateComments(comments ...*base.Comment) error {
cm.NewRef = fmt.Sprint(comment.Meta["NewRef"])
cm.Content = ""
}
case issues_model.CommentTypeMergePull:
cm.Content = ""
case issues_model.CommentTypePRScheduledToAutoMerge, issues_model.CommentTypePRUnScheduledToAutoMerge:
cm.Content = ""
default:

@ -517,6 +517,60 @@ func (g *GitlabDownloader) GetComments(commentable base.Commentable) ([]*base.Co
}
page = resp.NextPage
}
page = 1
for {
var stateEvents []*gitlab.StateEvent
var resp *gitlab.Response
var err error
if context.IsMergeRequest {
stateEvents, resp, err = g.client.ResourceStateEvents.ListMergeStateEvents(g.repoID, int(commentable.GetForeignIndex()), &gitlab.ListStateEventsOptions{
ListOptions: gitlab.ListOptions{
Page: page,
PerPage: g.maxPerPage,
},
}, nil, gitlab.WithContext(g.ctx))
} else {
stateEvents, resp, err = g.client.ResourceStateEvents.ListIssueStateEvents(g.repoID, int(commentable.GetForeignIndex()), &gitlab.ListStateEventsOptions{
ListOptions: gitlab.ListOptions{
Page: page,
PerPage: g.maxPerPage,
},
}, nil, gitlab.WithContext(g.ctx))
}
if err != nil {
return nil, false, fmt.Errorf("error while listing state events: %v %w", g.repoID, err)
}
for _, stateEvent := range stateEvents {
comment := &base.Comment{
IssueIndex: commentable.GetLocalIndex(),
Index: int64(stateEvent.ID),
PosterID: int64(stateEvent.User.ID),
PosterName: stateEvent.User.Username,
Content: "",
Created: *stateEvent.CreatedAt,
}
switch stateEvent.State {
case gitlab.ClosedEventType:
comment.CommentType = issues_model.CommentTypeClose.String()
case gitlab.MergedEventType:
comment.CommentType = issues_model.CommentTypeMergePull.String()
case gitlab.ReopenedEventType:
comment.CommentType = issues_model.CommentTypeReopen.String()
default:
// Ignore other event types
continue
}
allComments = append(allComments, comment)
}
if resp.NextPage == 0 {
break
}
page = resp.NextPage
}
return allComments, true, nil
}

@ -81,9 +81,11 @@
{{else if eq .Type 1}}
<div class="timeline-item event" id="{{.HashTag}}">
<span class="badge gt-bg-green gt-text-white">{{svg "octicon-dot-fill"}}</span>
{{template "shared/user/avatarlink" dict "user" .Poster}}
{{if not .OriginalAuthor}}
{{template "shared/user/avatarlink" dict "user" .Poster}}
{{end}}
<span class="text grey muted-links">
{{template "shared/user/authorlink" .Poster}}
{{template "repo/issue/view_content/comments_authorlink" dict "ctxData" $ "comment" .}}
{{if .Issue.IsPull}}
{{ctx.Locale.Tr "repo.pulls.reopened_at" .EventTag $createdStr}}
{{else}}
@ -94,9 +96,11 @@
{{else if eq .Type 2}}
<div class="timeline-item event" id="{{.HashTag}}">
<span class="badge gt-bg-red gt-text-white">{{svg "octicon-circle-slash"}}</span>
{{template "shared/user/avatarlink" dict "user" .Poster}}
{{if not .OriginalAuthor}}
{{template "shared/user/avatarlink" dict "user" .Poster}}
{{end}}
<span class="text grey muted-links">
{{template "shared/user/authorlink" .Poster}}
{{template "repo/issue/view_content/comments_authorlink" dict "ctxData" $ "comment" .}}
{{if .Issue.IsPull}}
{{ctx.Locale.Tr "repo.pulls.closed_at" .EventTag $createdStr}}
{{else}}
@ -107,9 +111,11 @@
{{else if eq .Type 28}}
<div class="timeline-item event" id="{{.HashTag}}">
<span class="badge gt-bg-purple gt-text-white">{{svg "octicon-git-merge"}}</span>
{{template "shared/user/avatarlink" dict "user" .Poster}}
{{if not .OriginalAuthor}}
{{template "shared/user/avatarlink" dict "user" .Poster}}
{{end}}
<span class="text grey muted-links">
{{template "shared/user/authorlink" .Poster}}
{{template "repo/issue/view_content/comments_authorlink" dict "ctxData" $ "comment" .}}
{{$link := printf "%s/commit/%s" $.Repository.Link ($.Issue.PullRequest.MergedCommitID|PathEscape)}}
{{if eq $.Issue.PullRequest.Status 3}}
{{ctx.Locale.Tr "repo.issues.comment_manually_pull_merged_at" (HTMLFormat `<a class="ui sha" href="%[1]s"><b>%[2]s</b></a>` $link (ShortSha $.Issue.PullRequest.MergedCommitID)) (HTMLFormat "<b>%[1]s</b>" $.BaseTarget) $createdStr}}
@ -375,18 +381,7 @@
{{end}}
<span class="badge{{if eq .Review.Type 1}} gt-bg-green gt-text-white{{else if eq .Review.Type 3}} gt-bg-red gt-text-white{{end}}">{{svg (printf "octicon-%s" .Review.Type.Icon)}}</span>
<span class="text grey muted-links">
{{if .OriginalAuthor}}
<span class="text black">
{{svg (MigrationIcon $.Repository.GetOriginalURLHostname)}}
{{.OriginalAuthor}}
</span>
{{if $.Repository.OriginalURL}}
<span class="migrate">({{ctx.Locale.Tr "repo.migrated_from" $.Repository.OriginalURL $.Repository.GetOriginalURLHostname}})</span>
{{end}}
{{else}}
{{template "shared/user/authorlink" .Poster}}
{{end}}
{{template "repo/issue/view_content/comments_authorlink" dict "ctxData" $ "comment" .}}
{{if eq .Review.Type 1}}
{{ctx.Locale.Tr "repo.issues.review.approve" $createdStr}}
{{else if eq .Review.Type 2}}
@ -498,17 +493,7 @@
{{template "shared/user/avatarlink" dict "user" .Poster}}
{{end}}
<span class="text grey muted-links">
{{if .OriginalAuthor}}
<span class="text black">
{{svg (MigrationIcon $.Repository.GetOriginalURLHostname)}}
{{.OriginalAuthor}}
</span>
{{if $.Repository.OriginalURL}}
<span class="migrate">({{ctx.Locale.Tr "repo.migrated_from" $.Repository.OriginalURL $.Repository.GetOriginalURLHostname}})</span>
{{end}}
{{else}}
{{template "shared/user/authorlink" .Poster}}
{{end}}
{{template "repo/issue/view_content/comments_authorlink" dict "ctxData" $ "comment" .}}
{{ctx.Locale.Tr "repo.pulls.change_target_branch_at" .OldRef .NewRef $createdStr}}
</span>
</div>
@ -675,17 +660,7 @@
<div class="timeline-item event" id="{{.HashTag}}">
<span class="badge">{{svg "octicon-git-merge" 16}}</span>
<span class="text grey muted-links">
{{if .OriginalAuthor}}
<span class="text black">
{{svg (MigrationIcon $.Repository.GetOriginalURLHostname)}}
{{.OriginalAuthor}}
</span>
{{if $.Repository.OriginalURL}}
<span class="migrate">({{ctx.Locale.Tr "repo.migrated_from" $.Repository.OriginalURL $.Repository.GetOriginalURLHostname}})</span>
{{end}}
{{else}}
{{template "shared/user/authorlink" .Poster}}
{{end}}
{{template "repo/issue/view_content/comments_authorlink" dict "ctxData" $ "comment" .}}
{{if eq .Type 34}}{{ctx.Locale.Tr "repo.pulls.auto_merge_newly_scheduled_comment" $createdStr}}
{{else}}{{ctx.Locale.Tr "repo.pulls.auto_merge_canceled_schedule_comment" $createdStr}}{{end}}
</span>

@ -0,0 +1,11 @@
{{if .comment.OriginalAuthor}}
<span class="text black">
{{svg (MigrationIcon .ctxData.Repository.GetOriginalURLHostname)}}
{{.comment.OriginalAuthor}}
</span>
{{if .ctxData.Repository.OriginalURL}}
<span class="migrate">({{ctx.Locale.Tr "repo.migrated_from" .ctxData.Repository.OriginalURL .ctxData.Repository.GetOriginalURLHostname}})</span>
{{end}}
{{else}}
{{template "shared/user/authorlink" .comment.Poster}}
{{end}}
Loading…
Cancel
Save