mirror of
https://gitea.com/Sirherobrine23/tea.git
synced 2024-08-21 02:47:23 +00:00
8bb5c15745
add interactive `tea pr review` it's amazingly simple vendor gitea.com/noerw/unidiff-comments add `tea pr lgtm|reject` shorthands vendor slimmed down diff parser review diff: default to true if users want a shortcut, they can use lgtm or reject subcmds `tea pr approve`: accept optional comment Co-authored-by: Norwin Roosen <git@nroo.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/315 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-by: 6543 <6543@obermui.de> Co-Authored-By: Norwin <noerw@noreply.gitea.io> Co-Committed-By: Norwin <noerw@noreply.gitea.io>
48 lines
915 B
Go
48 lines
915 B
Go
package types
|
|
|
|
type Changeset struct {
|
|
FromHash string
|
|
ToHash string
|
|
Path string
|
|
Whitespace string
|
|
Diffs []*Diff
|
|
}
|
|
|
|
func (r Changeset) ForEachComment(callback func(*Diff, *Comment, *Comment)) {
|
|
for _, diff := range r.Diffs {
|
|
stack := make([]*Comment, 0)
|
|
parents := make(map[*Comment]*Comment)
|
|
stack = append(stack, diff.FileComments...)
|
|
stack = append(stack, diff.LineComments...)
|
|
pos := 0
|
|
|
|
for pos < len(stack) {
|
|
comment := stack[pos]
|
|
|
|
if comment.Comments != nil {
|
|
stack = append(stack, comment.Comments...)
|
|
for _, c := range comment.Comments {
|
|
parents[c] = comment
|
|
}
|
|
}
|
|
|
|
callback(diff, comment, parents[comment])
|
|
|
|
pos++
|
|
}
|
|
}
|
|
}
|
|
|
|
func (r Changeset) ForEachLine(
|
|
callback func(*Diff, *Hunk, *Segment, *Line) error,
|
|
) error {
|
|
for _, diff := range r.Diffs {
|
|
err := diff.ForEachLine(callback)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|