Skip to content

Commit 0eb8db8

Browse files
committed
Merge branch 'master' into ojarjur/forks
2 parents 8d0f4c5 + 98c8fb2 commit 0eb8db8

File tree

15 files changed

+678
-52
lines changed

15 files changed

+678
-52
lines changed

commands/abandon.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/google/git-appraise/repository"
2626
"github.com/google/git-appraise/review"
2727
"github.com/google/git-appraise/review/comment"
28+
"github.com/google/git-appraise/review/gpg"
2829
"github.com/google/git-appraise/review/request"
2930
)
3031

@@ -33,6 +34,9 @@ var abandonFlagSet = flag.NewFlagSet("abandon", flag.ExitOnError)
3334
var (
3435
abandonMessageFile = abandonFlagSet.String("F", "", "Take the comment from the given file. Use - to read the message from the standard input")
3536
abandonMessage = abandonFlagSet.String("m", "", "Message to attach to the review")
37+
38+
abandonSign = abandonFlagSet.Bool("S", false,
39+
"Sign the contents of the abandonment")
3640
)
3741

3842
// abandonReview adds an NMW comment to the current code review.
@@ -88,14 +92,32 @@ func abandonReview(repo repository.Repo, args []string) error {
8892
c.Location = &location
8993
c.Resolved = &resolved
9094

91-
err = r.AddComment(c)
95+
var key string
96+
if *abandonSign {
97+
key, err := repo.GetUserSigningKey()
98+
if err != nil {
99+
return err
100+
}
101+
err = gpg.Sign(key, &c)
102+
if err != nil {
103+
return err
104+
}
105+
}
92106

107+
err = r.AddComment(c)
93108
if err != nil {
94109
return err
95110
}
96111

97112
// Empty target ref indicates that request was abandoned
98113
r.Request.TargetRef = ""
114+
// (re)sign the request after clearing out `TargetRef'.
115+
if *abandonSign {
116+
err = gpg.Sign(key, &r.Request)
117+
if err != nil {
118+
return err
119+
}
120+
}
99121

100122
note, err := r.Request.Write()
101123
if err != nil {

commands/accept.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,17 @@ import (
2424
"github.com/google/git-appraise/repository"
2525
"github.com/google/git-appraise/review"
2626
"github.com/google/git-appraise/review/comment"
27+
"github.com/google/git-appraise/review/gpg"
2728
)
2829

2930
var acceptFlagSet = flag.NewFlagSet("accept", flag.ExitOnError)
3031

3132
var (
3233
acceptMessageFile = acceptFlagSet.String("F", "", "Take the comment from the given file. Use - to read the message from the standard input")
3334
acceptMessage = acceptFlagSet.String("m", "", "Message to attach to the review")
35+
36+
acceptSign = acceptFlagSet.Bool("S", false,
37+
"sign the contents of the acceptance")
3438
)
3539

3640
// acceptReview adds an LGTM comment to the current code review.
@@ -80,6 +84,16 @@ func acceptReview(repo repository.Repo, args []string) error {
8084
c := comment.New(userEmail, *acceptMessage)
8185
c.Location = &location
8286
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+
}
8397
return r.AddComment(c)
8498
}
8599

commands/comment.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/google/git-appraise/repository"
2626
"github.com/google/git-appraise/review"
2727
"github.com/google/git-appraise/review/comment"
28+
"github.com/google/git-appraise/review/gpg"
2829
)
2930

3031
var commentFlagSet = flag.NewFlagSet("comment", flag.ExitOnError)
@@ -37,6 +38,8 @@ var (
3738
commentFile = commentFlagSet.String("f", "", "File being commented upon")
3839
commentLgtm = commentFlagSet.Bool("lgtm", false, "'Looks Good To Me'. Set this to express your approval. This cannot be combined with nmw")
3940
commentNmw = commentFlagSet.Bool("nmw", false, "'Needs More Work'. Set this to express your disapproval. This cannot be combined with lgtm")
41+
commentSign = commentFlagSet.Bool("S", false,
42+
"Sign the contents of the comment")
4043
)
4144

4245
func init() {
@@ -129,6 +132,18 @@ func commentOnReview(repo repository.Repo, args []string) error {
129132
resolved := *commentLgtm
130133
c.Resolved = &resolved
131134
}
135+
136+
if *commentSign {
137+
key, err := repo.GetUserSigningKey()
138+
if err != nil {
139+
return err
140+
}
141+
err = gpg.Sign(key, &c)
142+
if err != nil {
143+
return err
144+
}
145+
}
146+
132147
return r.AddComment(c)
133148
}
134149

commands/pull.go

Lines changed: 67 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,34 +23,18 @@ import (
2323

2424
"github.com/google/git-appraise/fork"
2525
"github.com/google/git-appraise/repository"
26+
"github.com/google/git-appraise/review"
2627
"golang.org/x/sync/errgroup"
2728
)
2829

2930
var (
30-
pullFlagSet = flag.NewFlagSet("pull", flag.ExitOnError)
31+
pullFlagSet = flag.NewFlagSet("pull", flag.ExitOnError)
32+
pullVerify = pullFlagSet.Bool("verify-signatures", false,
33+
"verify the signatures of pulled reviews")
3134
pullIncludeForks = pullFlagSet.Bool("include-forks", true, "Also pull reviews and comments from forks.")
3235
)
3336

34-
// pull updates the local git-notes used for reviews with those from a remote repo.
35-
func pull(repo repository.Repo, args []string) error {
36-
pullFlagSet.Parse(args)
37-
args = pullFlagSet.Args()
38-
39-
if len(args) > 1 {
40-
return errors.New("Only pulling from one remote at a time is supported.")
41-
}
42-
43-
remote := "origin"
44-
if len(args) == 1 {
45-
remote = args[0]
46-
}
47-
48-
if !*pullIncludeForks {
49-
return repo.PullNotesAndArchive(remote, notesRefPattern, archiveRefPattern)
50-
}
51-
if err := repo.PullNotesForksAndArchive(remote, notesRefPattern, fork.Ref, archiveRefPattern); err != nil {
52-
return fmt.Errorf("failure pulling review metadata from the remote %q: %v", remote, err)
53-
}
37+
func pullFromForks(repo repository.Repo) error {
5438
forks, err := fork.List(repo)
5539
if err != nil {
5640
return fmt.Errorf("failure listing the forks: %v", err)
@@ -86,6 +70,68 @@ func pull(repo repository.Repo, args []string) error {
8670
return nil
8771
}
8872

73+
// pull updates the local git-notes used for reviews with those from a remote
74+
// repo.
75+
func pull(repo repository.Repo, args []string) error {
76+
pullFlagSet.Parse(args)
77+
pullArgs := pullFlagSet.Args()
78+
79+
if len(pullArgs) > 1 {
80+
return errors.New(
81+
"Only pulling from one remote at a time is supported.")
82+
}
83+
84+
remote := "origin"
85+
if len(pullArgs) == 1 {
86+
remote = pullArgs[0]
87+
}
88+
89+
if !*pullVerify {
90+
if !*pullIncludeForks {
91+
return repo.PullNotesAndArchive(remote, notesRefPattern, archiveRefPattern)
92+
}
93+
if err := repo.PullNotesForksAndArchive(remote, notesRefPattern, fork.Ref, archiveRefPattern); err != nil {
94+
return fmt.Errorf("failure pulling review metadata from the remote %q: %v", remote, err)
95+
}
96+
return pullFromForks(repo)
97+
}
98+
99+
// We collect the fetched reviewed revisions (their hashes), get
100+
// their reviews, and then one by one, verify them. If we make it through
101+
// the set, _then_ we merge the remote reference into the local branch.
102+
revisions, err := repo.FetchAndReturnNewReviewHashes(remote,
103+
notesRefPattern, archiveRefPattern)
104+
if err != nil {
105+
return err
106+
}
107+
for _, revision := range revisions {
108+
rvw, err := review.GetSummaryViaRefs(repo,
109+
"refs/notes/"+remote+"/devtools/reviews",
110+
"refs/notes/"+remote+"/devtools/discuss", revision)
111+
if err != nil {
112+
return err
113+
}
114+
err = rvw.Verify()
115+
if err != nil {
116+
return err
117+
}
118+
fmt.Println("verified review:", revision)
119+
}
120+
if err := repo.MergeNotes(remote, notesRefPattern); err != nil {
121+
return err
122+
}
123+
if err := repo.MergeArchives(remote, archiveRefPattern); err != nil {
124+
return err
125+
}
126+
if !*pullIncludeForks {
127+
return nil
128+
}
129+
if err := repo.MergeForks(remote, fork.Ref); err != nil {
130+
return err
131+
}
132+
return pullFromForks(repo)
133+
}
134+
89135
var pullCmd = &Command{
90136
Usage: func(arg0 string) {
91137
fmt.Printf("Usage: %s pull [<option>...] [<remote>]\n\nOptions:\n", arg0)

commands/rebase.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ var rebaseFlagSet = flag.NewFlagSet("rebase", flag.ExitOnError)
2929

3030
var (
3131
rebaseArchive = rebaseFlagSet.Bool("archive", true, "Prevent the original commit from being garbage collected.")
32+
rebaseSign = rebaseFlagSet.Bool("S", false,
33+
"Sign the contents of the request after the rebase")
3234
)
3335

3436
// Validate that the user's request to rebase a review makes sense.
@@ -80,6 +82,9 @@ func rebaseReview(repo repository.Repo, args []string) error {
8082
if err != nil {
8183
return err
8284
}
85+
if *rebaseSign {
86+
return r.RebaseAndSign(*rebaseArchive)
87+
}
8388
return r.Rebase(*rebaseArchive)
8489
}
8590

commands/reject.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,17 @@ import (
2525
"github.com/google/git-appraise/repository"
2626
"github.com/google/git-appraise/review"
2727
"github.com/google/git-appraise/review/comment"
28+
"github.com/google/git-appraise/review/gpg"
2829
)
2930

3031
var rejectFlagSet = flag.NewFlagSet("reject", flag.ExitOnError)
3132

3233
var (
3334
rejectMessageFile = rejectFlagSet.String("F", "", "Take the comment from the given file. Use - to read the message from the standard input")
3435
rejectMessage = rejectFlagSet.String("m", "", "Message to attach to the review")
36+
37+
rejectSign = rejectFlagSet.Bool("S", false,
38+
"Sign the contents of the rejection")
3539
)
3640

3741
// rejectReview adds an NMW comment to the current code review.
@@ -90,6 +94,16 @@ func rejectReview(repo repository.Repo, args []string) error {
9094
c := comment.New(userEmail, *rejectMessage)
9195
c.Location = &location
9296
c.Resolved = &resolved
97+
if *rejectSign {
98+
key, err := repo.GetUserSigningKey()
99+
if err != nil {
100+
return err
101+
}
102+
err = gpg.Sign(key, &c)
103+
if err != nil {
104+
return err
105+
}
106+
}
93107
return r.AddComment(c)
94108
}
95109

commands/request.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ import (
2020
"errors"
2121
"flag"
2222
"fmt"
23+
"strings"
24+
2325
"github.com/google/git-appraise/commands/input"
2426
"github.com/google/git-appraise/repository"
27+
"github.com/google/git-appraise/review/gpg"
2528
"github.com/google/git-appraise/review/request"
26-
"strings"
2729
)
2830

2931
// Template for the "request" subcommand's output.
@@ -44,6 +46,8 @@ var (
4446
requestTarget = requestFlagSet.String("target", "refs/heads/master", "Revision against which to review")
4547
requestQuiet = requestFlagSet.Bool("quiet", false, "Suppress review summary output")
4648
requestAllowUncommitted = requestFlagSet.Bool("allow-uncommitted", false, "Allow uncommitted local changes.")
49+
requestSign = requestFlagSet.Bool("S", false,
50+
"GPG sign the content of the request")
4751
)
4852

4953
// Build the template review request based solely on the parsed flag values.
@@ -145,7 +149,16 @@ func requestReview(repo repository.Repo, args []string) error {
145149
}
146150
r.Description = description
147151
}
148-
152+
if *requestSign {
153+
key, err := repo.GetUserSigningKey()
154+
if err != nil {
155+
return err
156+
}
157+
err = gpg.Sign(key, &r)
158+
if err != nil {
159+
return err
160+
}
161+
}
149162
note, err := r.Write()
150163
if err != nil {
151164
return err

commands/submit.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ var (
3232
submitFastForward = submitFlagSet.Bool("fast-forward", false, "Create a merge using the default fast-forward mode.")
3333
submitTBR = submitFlagSet.Bool("tbr", false, "(To be reviewed) Force the submission of a review that has not been accepted.")
3434
submitArchive = submitFlagSet.Bool("archive", true, "Prevent the original commit from being garbage collected; only affects rebased submits.")
35+
36+
submitSign = submitFlagSet.Bool("S", false,
37+
"Sign the contents of the submission")
3538
)
3639

3740
// Submit the current code review request.
@@ -105,9 +108,16 @@ func submitReview(repo repository.Repo, args []string) error {
105108
}
106109

107110
if *submitRebase {
108-
if err := r.Rebase(*submitArchive); err != nil {
111+
var err error
112+
if *submitSign {
113+
err = r.RebaseAndSign(*submitArchive)
114+
} else {
115+
err = r.Rebase(*submitArchive)
116+
}
117+
if err != nil {
109118
return err
110119
}
120+
111121
source, err = r.GetHeadCommit()
112122
if err != nil {
113123
return err
@@ -119,9 +129,19 @@ func submitReview(repo repository.Repo, args []string) error {
119129
}
120130
if *submitMerge {
121131
submitMessage := fmt.Sprintf("Submitting review %.12s", r.Revision)
122-
return repo.MergeRef(source, false, submitMessage, r.Request.Description)
132+
if *submitSign {
133+
return repo.MergeAndSignRef(source, false, submitMessage,
134+
r.Request.Description)
135+
} else {
136+
return repo.MergeRef(source, false, submitMessage,
137+
r.Request.Description)
138+
}
123139
} else {
124-
return repo.MergeRef(source, true)
140+
if *submitSign {
141+
return repo.MergeAndSignRef(source, true)
142+
} else {
143+
return repo.MergeRef(source, true)
144+
}
125145
}
126146
}
127147

0 commit comments

Comments
 (0)