@@ -729,7 +729,8 @@ func (b *bot) importGerritChangeFromPR(ctx context.Context, pr *github.PullReque
729
729
pushOpts = "%ready"
730
730
}
731
731
732
- if cl == nil {
732
+ newCL := cl == nil
733
+ if newCL {
733
734
// Add this informational message only on CL creation.
734
735
msg := fmt .Sprintf ("This Gerrit CL corresponds to GitHub PR %s.\n \n Author: %s" , prShortLink (pr ), author )
735
736
pushOpts += ",m=" + url .QueryEscape (msg )
@@ -754,7 +755,49 @@ Please visit %s to see it.
754
755
Tip: You can toggle comments from me using the %s slash command (e.g. %s)
755
756
See the [Uncyclo page](https://golang.org/wiki/GerritBot) for more info` ,
756
757
pr .Head .GetSHA (), changeURL , "`comments`" , "`/comments off`" )
757
- return b .postGitHubMessageNoDup (ctx , repo .GetOwner ().GetLogin (), repo .GetName (), pr .GetNumber (), "" , msg )
758
+
759
+ err = b .postGitHubMessageNoDup (ctx , repo .GetOwner ().GetLogin (), repo .GetName (), pr .GetNumber (), "" , msg )
760
+ if err != nil {
761
+ return err
762
+ }
763
+
764
+ if newCL {
765
+ // Add an unresolved welcome comment to Gerrit to provide some context to the PR author
766
+ // but also to help a reviewer see the author has registered for a Gerrit account,
767
+ // knows how to reply in Gerrit, and thinks the CL is ready for review.
768
+ // TODO: consider a reminder comment with reply hints if they don't reply after something like 7 days.
769
+ // TODO: consider abandoning the CL if no reply after something like 30 days.
770
+ gcl , err := b .gerritChangeForPR (pr )
771
+ if err != nil {
772
+ return fmt .Errorf ("could not look up CL after creation: %v" , err )
773
+ }
774
+ question := fmt .Sprintf (`Hello %v, is this CL ready for review?
775
+
776
+ If so, please mark this comment as 'Done'. If not, please write a reply to this comment.
777
+
778
+ (In Gerrit code reviews, the CL author is expected to close out each piece of feedback by
779
+ marking it as 'Done' if implemented as suggested or otherwise reply to each review comment.
780
+ See the [Review](https://go.dev/doc/contribute#review) section of the Contributing Guide for details.)` ,
781
+ author )
782
+
783
+ unresolved := true
784
+ ri := gerrit.ReviewInput {
785
+ Comments : map [string ][]gerrit.CommentInput {
786
+ "/PATCHSET_LEVEL" : {{Message : question , Unresolved : & unresolved }},
787
+ },
788
+ }
789
+ // TODO: might be able to use gcl.ID instead of genChangeTriple? Note gcl.ID says it is URL encoded.
790
+ revision , err := genChangeTriple (gcl )
791
+ if err != nil {
792
+ return fmt .Errorf ("cannot add welcome comment to CL: %v" , err )
793
+ }
794
+ err = b .gerritClient .SetReview (ctx , gcl .ChangeID , revision , ri )
795
+ if err != nil {
796
+ return fmt .Errorf ("could not add welcome comment to CL: %v" , err )
797
+ }
798
+ }
799
+
800
+ return nil
758
801
}
759
802
760
803
var changeIdentRE = regexp .MustCompile (`(?m)^Change-Id: (I[0-9a-fA-F]{40})\n?` )
@@ -814,6 +857,17 @@ func genChangeID(pr *github.PullRequest) string {
814
857
return fmt .Sprintf ("I%x" , sha1 .Sum (buf .Bytes ()))
815
858
}
816
859
860
+ // genChangeTriple returns the Gerrit (project, branch, change-ID) triple
861
+ // uniquely identifying this change.
862
+ func genChangeTriple (gcl * gerrit.ChangeInfo ) (string , error ) {
863
+ // TODO: this is modified from cmd/coordinator. Consider consolidating.
864
+ if gcl .Project == "" || gcl .Branch == "" || gcl .ChangeID == "" {
865
+ return "" , fmt .Errorf ("cannot generate change triple: gcl.Project: %q, gcl.Branch: %q, gcl.ChangeID: %q" ,
866
+ gcl .Project , gcl .Branch , gcl .ChangeID )
867
+ }
868
+ return fmt .Sprintf ("%s~%s~%s" , gcl .Project , gcl .Branch , gcl .ChangeID ), nil
869
+ }
870
+
817
871
func cmdOut (cmd * exec.Cmd ) (string , error ) {
818
872
log .Printf ("Executing %v" , cmd .Args )
819
873
out , err := cmd .CombinedOutput ()
0 commit comments