1
1
Fork 0
mirror of https://gitea.com/gitea/tea synced 2024-05-17 13:16:08 +02:00
tea/vendor/gitea.com/noerw/unidiff-comments/types/diff.go
Norwin 8bb5c15745 Add commands for reviews (#315)
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>
2020-12-21 23:22:22 +08:00

62 lines
1.0 KiB
Go

package types
type Diff struct {
Truncated bool
Source struct {
Parent string
Name string
ToString string
}
Destination struct {
Parent string
Name string
ToString string
}
Hunks []*Hunk
FileComments CommentsTree
LineComments CommentsTree
Note string
// Lists made only for Stash API compatibility.
// TODO: move it to `ash`.
Attributes struct {
FromHash []string
ToHash []string
}
}
func (d Diff) GetHashFrom() string {
if len(d.Attributes.FromHash) > 0 {
return d.Attributes.FromHash[0]
} else {
return "???"
}
}
func (d Diff) GetHashTo() string {
if len(d.Attributes.ToHash) > 0 {
return d.Attributes.ToHash[0]
} else {
return "???"
}
}
func (d Diff) ForEachLine(
callback func(*Diff, *Hunk, *Segment, *Line) error,
) error {
for _, hunk := range d.Hunks {
for _, segment := range hunk.Segments {
for _, line := range segment.Lines {
err := callback(&d, hunk, segment, line)
if err != nil {
return err
}
}
}
}
return nil
}