17
17
package com .google .copybara .git ;
18
18
19
19
import static com .google .common .truth .Truth .assertThat ;
20
- import static com .google .copybara .git .GitHubPROrigin .GITHUB_BASE_BRANCH ;
21
- import static com .google .copybara .git .GitHubPROrigin .GITHUB_BASE_BRANCH_SHA1 ;
22
- import static com .google .copybara .git .GitHubPROrigin .GITHUB_PR_ASSIGNEE ;
23
- import static com .google .copybara .git .GitHubPROrigin .GITHUB_PR_BODY ;
24
- import static com .google .copybara .git .GitHubPROrigin .GITHUB_PR_HEAD_SHA ;
25
- import static com .google .copybara .git .GitHubPROrigin .GITHUB_PR_NUMBER_LABEL ;
26
- import static com .google .copybara .git .GitHubPROrigin .GITHUB_PR_TITLE ;
27
- import static com .google .copybara .git .GitHubPROrigin .GITHUB_PR_URL ;
28
- import static com .google .copybara .git .GitHubPROrigin .GITHUB_PR_USER ;
29
- import static com .google .copybara .git .GitHubPROrigin .GITHUB_PR_USE_MERGE ;
20
+ import static com .google .copybara .git .GitHubPrOrigin .GITHUB_BASE_BRANCH ;
21
+ import static com .google .copybara .git .GitHubPrOrigin .GITHUB_BASE_BRANCH_SHA1 ;
22
+ import static com .google .copybara .git .GitHubPrOrigin .GITHUB_PR_ASSIGNEE ;
23
+ import static com .google .copybara .git .GitHubPrOrigin .GITHUB_PR_BODY ;
24
+ import static com .google .copybara .git .GitHubPrOrigin .GITHUB_PR_HEAD_SHA ;
25
+ import static com .google .copybara .git .GitHubPrOrigin .GITHUB_PR_NUMBER_LABEL ;
26
+ import static com .google .copybara .git .GitHubPrOrigin .GITHUB_PR_TITLE ;
27
+ import static com .google .copybara .git .GitHubPrOrigin .GITHUB_PR_URL ;
28
+ import static com .google .copybara .git .GitHubPrOrigin .GITHUB_PR_USER ;
29
+ import static com .google .copybara .git .GitHubPrOrigin .GITHUB_PR_USE_MERGE ;
30
30
import static com .google .copybara .testing .git .GitTestUtil .getGitEnv ;
31
31
import static com .google .copybara .testing .git .GitTestUtil .mockResponse ;
32
32
import static com .google .copybara .testing .git .GitTestUtil .mockResponseAndValidateRequest ;
@@ -206,7 +206,7 @@ public void testGitResolvePullRequestRawRef() throws Exception {
206
206
public void testGitResolveSha1 () throws Exception {
207
207
mockPullRequestAndIssue ("open" , 123 );
208
208
209
- GitHubPROrigin origin = githubPrOrigin (
209
+ GitHubPrOrigin origin = githubPrOrigin (
210
210
"url = 'https://github.com/google/example'" );
211
211
checkResolve (origin , "refs/pull/123/head" , 123 );
212
212
@@ -526,7 +526,7 @@ public void testChanges() throws Exception {
526
526
527
527
mockPullRequestAndIssue ("open" , 123 );
528
528
529
- GitHubPROrigin origin = githubPrOrigin (
529
+ GitHubPrOrigin origin = githubPrOrigin (
530
530
"url = 'https://github.com/google/example'" );
531
531
532
532
Reader <GitRevision > reader = origin .newReader (Glob .ALL_FILES , authoring );
@@ -571,7 +571,7 @@ public void testCheckout() throws Exception {
571
571
572
572
mockPullRequestAndIssue ("open" , 123 );
573
573
574
- GitHubPROrigin origin = githubPrOrigin (
574
+ GitHubPrOrigin origin = githubPrOrigin (
575
575
"url = 'https://github.com/google/example'" ,
576
576
"baseline_from_branch = True" );
577
577
@@ -753,15 +753,15 @@ public void testReviewApproversDescription() throws ValidationException {
753
753
public void testReviewApprovers () throws Exception {
754
754
GitRevision noReviews = checkReviewApprovers ();
755
755
assertThat (noReviews .associatedLabels ())
756
- .doesNotContainKey (GitHubPROrigin .GITHUB_PR_REVIEWER_APPROVER );
756
+ .doesNotContainKey (GitHubPrOrigin .GITHUB_PR_REVIEWER_APPROVER );
757
757
assertThat (noReviews .associatedLabels ())
758
- .doesNotContainKey (GitHubPROrigin .GITHUB_PR_REVIEWER_OTHER );
758
+ .doesNotContainKey (GitHubPrOrigin .GITHUB_PR_REVIEWER_OTHER );
759
759
760
760
GitRevision any = checkReviewApprovers ("review_state = 'ANY'" );
761
761
762
- assertThat (any .associatedLabels ().get (GitHubPROrigin .GITHUB_PR_REVIEWER_APPROVER ))
762
+ assertThat (any .associatedLabels ().get (GitHubPrOrigin .GITHUB_PR_REVIEWER_APPROVER ))
763
763
.containsExactly ("APPROVED_MEMBER" , "COMMENTED_OWNER" , "APPROVED_COLLABORATOR" );
764
- assertThat (any .associatedLabels ().get (GitHubPROrigin .GITHUB_PR_REVIEWER_OTHER ))
764
+ assertThat (any .associatedLabels ().get (GitHubPrOrigin .GITHUB_PR_REVIEWER_OTHER ))
765
765
.containsExactly ("COMMENTED_OTHER" );
766
766
767
767
EmptyChangeException e =
@@ -781,24 +781,24 @@ public void testReviewApprovers() throws Exception {
781
781
GitRevision hasReviewers = checkReviewApprovers ("review_state = 'ANY_COMMIT_APPROVED'" ,
782
782
"review_approvers = [\" MEMBER\" , \" OWNER\" ]" );
783
783
784
- assertThat (hasReviewers .associatedLabels ().get (GitHubPROrigin .GITHUB_PR_REVIEWER_APPROVER ))
784
+ assertThat (hasReviewers .associatedLabels ().get (GitHubPrOrigin .GITHUB_PR_REVIEWER_APPROVER ))
785
785
.containsExactly ("APPROVED_MEMBER" , "COMMENTED_OWNER" );
786
- assertThat (hasReviewers .associatedLabels ().get (GitHubPROrigin .GITHUB_PR_REVIEWER_OTHER ))
786
+ assertThat (hasReviewers .associatedLabels ().get (GitHubPrOrigin .GITHUB_PR_REVIEWER_OTHER ))
787
787
.containsExactly ("COMMENTED_OTHER" , "APPROVED_COLLABORATOR" );
788
788
789
789
GitRevision anyCommitApproved = checkReviewApprovers ("review_state = 'HAS_REVIEWERS'" ,
790
790
"review_approvers = [\" OWNER\" ]" );
791
791
792
- assertThat (anyCommitApproved .associatedLabels ().get (GitHubPROrigin .GITHUB_PR_REVIEWER_APPROVER ))
792
+ assertThat (anyCommitApproved .associatedLabels ().get (GitHubPrOrigin .GITHUB_PR_REVIEWER_APPROVER ))
793
793
.containsExactly ("COMMENTED_OWNER" );
794
- assertThat (anyCommitApproved .associatedLabels ().get (GitHubPROrigin .GITHUB_PR_REVIEWER_OTHER ))
794
+ assertThat (anyCommitApproved .associatedLabels ().get (GitHubPrOrigin .GITHUB_PR_REVIEWER_OTHER ))
795
795
.containsExactly ("APPROVED_MEMBER" , "COMMENTED_OTHER" , "APPROVED_COLLABORATOR" );
796
796
}
797
797
798
798
799
799
@ Test
800
800
public void testHttprUrl () throws Exception {
801
- GitHubPROrigin val =
801
+ GitHubPrOrigin val =
802
802
skylark .eval (
803
803
"origin" , "origin = git.github_pr_origin(url = 'http://github.com/google/example')\n " );
804
804
assertThat (val .describe (Glob .ALL_FILES ).get ("url" ))
@@ -829,7 +829,7 @@ public void requiredCheckRuns() throws Exception {
829
829
830
830
@ Test
831
831
public void testDescribeBranch () throws Exception {
832
- GitHubPROrigin val =
832
+ GitHubPrOrigin val =
833
833
skylark .eval (
834
834
"origin" , "origin = git.github_pr_origin("
835
835
+ "url = 'http://github.com/google/example', branch = 'dev')\n " );
@@ -903,12 +903,12 @@ private GitRevision checkReviewApprovers(String... configLines)
903
903
Strings .repeat ("0" , 40 ))
904
904
))));
905
905
906
- GitHubPROrigin origin = createGitHubPrOrigin (configLines );
906
+ GitHubPrOrigin origin = createGitHubPrOrigin (configLines );
907
907
908
908
return origin .resolve ("123" );
909
909
}
910
910
911
- private GitHubPROrigin createGitHubPrOrigin (String ... configLines ) throws ValidationException {
911
+ private GitHubPrOrigin createGitHubPrOrigin (String ... configLines ) throws ValidationException {
912
912
return skylark .eval ("origin" , "origin = "
913
913
+ "git.github_pr_origin(\n "
914
914
+ " url = 'https://github.com/google/example',\n "
@@ -957,7 +957,7 @@ public void testMerge() throws Exception {
957
957
remote .simpleCommand ("update-ref" , GitHubUtil .asMergeRef (123 ), remote .parseRef ("primary" ));
958
958
959
959
960
- GitHubPROrigin origin =
960
+ GitHubPrOrigin origin =
961
961
githubPrOrigin (
962
962
"url = 'https://github.com/google/example'" ,
963
963
"branch = 'primary'" ,
@@ -1009,7 +1009,7 @@ public void testCheckout_noMergeRef() throws Exception {
1009
1009
mockPullRequestAndIssue ("open" , 123 );
1010
1010
1011
1011
// Now try with merge ref
1012
- GitHubPROrigin origin = githubPrOrigin (
1012
+ GitHubPrOrigin origin = githubPrOrigin (
1013
1013
"url = 'https://github.com/google/example'" ,
1014
1014
"use_merge = True" );
1015
1015
@@ -1051,7 +1051,7 @@ public void testCheckout_noMergeRef_withForce() throws Exception {
1051
1051
1052
1052
mockPullRequestAndIssue ("open" , "main" , 123 , /*mergeable = */ true );
1053
1053
1054
- GitHubPROrigin origin =
1054
+ GitHubPrOrigin origin =
1055
1055
githubPrOrigin ("url = 'https://github.com/google/example'" , "use_merge = True" );
1056
1056
1057
1057
assertThat (origin .resolve ("123" ).getSha1 ())
@@ -1074,7 +1074,7 @@ public void testCheckout_noMergeRef_withForce() throws Exception {
1074
1074
assertThat (origin .resolve ("123" ).associatedLabel (GITHUB_PR_USE_MERGE )).containsExactly ("false" );
1075
1075
}
1076
1076
1077
- private void checkResolve (GitHubPROrigin origin , String reference , int prNumber )
1077
+ private void checkResolve (GitHubPrOrigin origin , String reference , int prNumber )
1078
1078
throws RepoException , IOException , ValidationException {
1079
1079
GitRepository remote = gitUtil .mockRemoteRepo ("github.com/google/example" );
1080
1080
addFiles (remote , "first change" , ImmutableMap .<String , String >builder ()
@@ -1113,7 +1113,7 @@ private GitRepository withTmpWorktree(GitRepository remote) throws IOException {
1113
1113
return remote .withWorkTree (Files .createTempDirectory ("temp" ));
1114
1114
}
1115
1115
1116
- private GitHubPROrigin githubPrOrigin (String ... lines ) throws ValidationException {
1116
+ private GitHubPrOrigin githubPrOrigin (String ... lines ) throws ValidationException {
1117
1117
return skylark .eval ("r" , "r = git.github_pr_origin("
1118
1118
+ " " + Joiner .on (",\n " ).join (lines ) + ",\n )" );
1119
1119
}
0 commit comments