MCPcopy
hub / github.com/google/git-appraise / acceptReview

Function acceptReview

commands/accept.go:41–98  ·  view source on GitHub ↗

acceptReview adds an LGTM comment to the current code review.

(repo repository.Repo, args []string)

Source from the content-addressed store, hash-verified

39
40// acceptReview adds an LGTM comment to the current code review.
41func acceptReview(repo repository.Repo, args []string) error {
42 acceptFlagSet.Parse(args)
43 args = acceptFlagSet.Args()
44
45 var r *review.Review
46 var err error
47 if len(args) > 1 {
48 return errors.New("Only accepting a single review is supported.")
49 }
50
51 if len(args) == 1 {
52 r, err = review.Get(repo, args[0])
53 } else {
54 r, err = review.GetCurrent(repo)
55 }
56
57 if err != nil {
58 return fmt.Errorf("Failed to load the review: %v\n", err)
59 }
60 if r == nil {
61 return errors.New("There is no matching review.")
62 }
63
64 acceptedCommit, err := r.GetHeadCommit()
65 if err != nil {
66 return err
67 }
68 location := comment.Location{
69 Commit: acceptedCommit,
70 }
71 resolved := true
72 userEmail, err := repo.GetUserEmail()
73 if err != nil {
74 return err
75 }
76
77 if *acceptMessageFile != "" && *acceptMessage == "" {
78 *acceptMessage, err = input.FromFile(*acceptMessageFile)
79 if err != nil {
80 return err
81 }
82 }
83
84 c := comment.New(userEmail, *acceptMessage)
85 c.Location = &location
86 c.Resolved = &resolved
87 if *acceptSign {
88 key, err := repo.GetUserSigningKey()
89 if err != nil {
90 return err
91 }
92 err = gpg.Sign(key, &c)
93 if err != nil {
94 return err
95 }
96 }
97 return r.AddComment(c)
98}

Callers 1

accept.goFile · 0.85

Calls 4

GetHeadCommitMethod · 0.95
AddCommentMethod · 0.95
GetUserEmailMethod · 0.65
GetUserSigningKeyMethod · 0.65

Tested by

no test coverage detected