@@ -866,4 +866,123 @@ public void getLastCommitStatus() throws Exception {
866866 assertThat (status .getState (), equalTo (GHCommitState .SUCCESS ));
867867 assertThat (status .getContext (), equalTo ("ci/circleci: build" ));
868868 }
869+
870+ @ Test
871+ public void listCommitsBetween () throws Exception {
872+ GHRepository repository = getRepository ();
873+ int startingCount = mockGitHub .getRequestCount ();
874+ GHCompare compare = repository .getCompare ("e46a9f3f2ac55db96de3c5c4706f2813b3a96465" ,
875+ "8051615eff597f4e49f4f47625e6fc2b49f26bfc" );
876+ int actualCount = 0 ;
877+ for (GHCompare .Commit item : compare .listCommits ().withPageSize (5 )) {
878+ assertThat (item , notNullValue ());
879+ actualCount ++;
880+ }
881+ assertThat (compare .getTotalCommits (), is (9 ));
882+ assertThat (actualCount , is (9 ));
883+ assertThat (mockGitHub .getRequestCount (), equalTo (startingCount + 1 ));
884+ }
885+
886+ @ Test
887+ public void listCommitsBetweenPaginated () throws Exception {
888+ GHRepository repository = getRepository ();
889+ int startingCount = mockGitHub .getRequestCount ();
890+ repository .setCompareUsePaginatedCommits (true );
891+ GHCompare compare = repository .getCompare ("e46a9f3f2ac55db96de3c5c4706f2813b3a96465" ,
892+ "8051615eff597f4e49f4f47625e6fc2b49f26bfc" );
893+ int actualCount = 0 ;
894+ for (GHCompare .Commit item : compare .listCommits ().withPageSize (5 )) {
895+ assertThat (item , notNullValue ());
896+ actualCount ++;
897+ }
898+ assertThat (compare .getTotalCommits (), is (9 ));
899+ assertThat (actualCount , is (9 ));
900+ assertThat (mockGitHub .getRequestCount (), equalTo (startingCount + 3 ));
901+ }
902+
903+ @ Test
904+ public void getCommitsBetweenOver250 () throws Exception {
905+ GHRepository repository = getRepository ();
906+ int startingCount = mockGitHub .getRequestCount ();
907+ GHCompare compare = repository .getCompare ("4261c42949915816a9f246eb14c3dfd21a637bc2" ,
908+ "94ff089e60064bfa43e374baeb10846f7ce82f40" );
909+ int actualCount = 0 ;
910+ for (GHCompare .Commit item : compare .getCommits ()) {
911+ assertThat (item , notNullValue ());
912+ actualCount ++;
913+ }
914+ assertThat (compare .getTotalCommits (), is (283 ));
915+ assertThat (actualCount , is (250 ));
916+ assertThat (mockGitHub .getRequestCount (), equalTo (startingCount + 1 ));
917+
918+ // Additional GHCompare checks
919+ assertThat (compare .getAheadBy (), equalTo (283 ));
920+ assertThat (compare .getBehindBy (), equalTo (0 ));
921+ assertThat (compare .getStatus (), equalTo (GHCompare .Status .ahead ));
922+ assertThat (compare .getDiffUrl ().toString (),
923+ endsWith (
924+ "compare/4261c42949915816a9f246eb14c3dfd21a637bc2...94ff089e60064bfa43e374baeb10846f7ce82f40.diff" ));
925+ assertThat (compare .getHtmlUrl ().toString (),
926+ endsWith (
927+ "compare/4261c42949915816a9f246eb14c3dfd21a637bc2...94ff089e60064bfa43e374baeb10846f7ce82f40" ));
928+ assertThat (compare .getPatchUrl ().toString (),
929+ endsWith (
930+ "compare/4261c42949915816a9f246eb14c3dfd21a637bc2...94ff089e60064bfa43e374baeb10846f7ce82f40.patch" ));
931+ assertThat (compare .getPermalinkUrl ().toString (),
932+ endsWith ("compare/hub4j-test-org:4261c42...hub4j-test-org:94ff089" ));
933+ assertThat (compare .getUrl ().toString (),
934+ endsWith (
935+ "compare/4261c42949915816a9f246eb14c3dfd21a637bc2...94ff089e60064bfa43e374baeb10846f7ce82f40" ));
936+
937+ assertThat (compare .getBaseCommit ().getSHA1 (), equalTo ("4261c42949915816a9f246eb14c3dfd21a637bc2" ));
938+
939+ assertThat (compare .getMergeBaseCommit ().getSHA1 (), equalTo ("4261c42949915816a9f246eb14c3dfd21a637bc2" ));
940+ // it appears this field is not present in the returned JSON. Strange.
941+ assertThat (compare .getMergeBaseCommit ().getCommit ().getSha (), nullValue ());
942+ assertThat (compare .getMergeBaseCommit ().getCommit ().getUrl (),
943+ endsWith ("/commits/4261c42949915816a9f246eb14c3dfd21a637bc2" ));
944+ assertThat (compare .getMergeBaseCommit ().getCommit ().getMessage (),
945+ endsWith ("[maven-release-plugin] prepare release github-api-1.123" ));
946+ assertThat (compare .getMergeBaseCommit ().getCommit ().getAuthor ().getName (), equalTo ("Liam Newman" ));
947+ assertThat (compare .getMergeBaseCommit ().getCommit ().getCommitter ().getName (), equalTo ("Liam Newman" ));
948+
949+ assertThat (compare .getMergeBaseCommit ().getCommit ().getTree ().getSha (),
950+ equalTo ("5da98090976978c93aba0bdfa550e05675543f99" ));
951+ assertThat (compare .getMergeBaseCommit ().getCommit ().getTree ().getUrl (),
952+ endsWith ("/git/trees/5da98090976978c93aba0bdfa550e05675543f99" ));
953+
954+ assertThat (compare .getFiles ().length , equalTo (300 ));
955+ assertThat (compare .getFiles ()[0 ].getFileName (), equalTo (".github/PULL_REQUEST_TEMPLATE.md" ));
956+ assertThat (compare .getFiles ()[0 ].getLinesAdded (), equalTo (8 ));
957+ assertThat (compare .getFiles ()[0 ].getLinesChanged (), equalTo (15 ));
958+ assertThat (compare .getFiles ()[0 ].getLinesDeleted (), equalTo (7 ));
959+ assertThat (compare .getFiles ()[0 ].getFileName (), equalTo (".github/PULL_REQUEST_TEMPLATE.md" ));
960+ assertThat (compare .getFiles ()[0 ].getPatch (), startsWith ("@@ -1,15 +1,16 @@" ));
961+ assertThat (compare .getFiles ()[0 ].getPreviousFilename (), nullValue ());
962+ assertThat (compare .getFiles ()[0 ].getStatus (), equalTo ("modified" ));
963+ assertThat (compare .getFiles ()[0 ].getSha (), equalTo ("e4234f5f6f39899282a6ef1edff343ae1269222e" ));
964+
965+ assertThat (compare .getFiles ()[0 ].getBlobUrl ().toString (),
966+ endsWith ("/blob/94ff089e60064bfa43e374baeb10846f7ce82f40/.github/PULL_REQUEST_TEMPLATE.md" ));
967+ assertThat (compare .getFiles ()[0 ].getRawUrl ().toString (),
968+ endsWith ("/raw/94ff089e60064bfa43e374baeb10846f7ce82f40/.github/PULL_REQUEST_TEMPLATE.md" ));
969+ }
970+
971+ @ Test
972+ public void getCommitsBetweenPaged () throws Exception {
973+ GHRepository repository = getRepository ();
974+ int startingCount = mockGitHub .getRequestCount ();
975+ repository .setCompareUsePaginatedCommits (true );
976+ GHCompare compare = repository .getCompare ("4261c42949915816a9f246eb14c3dfd21a637bc2" ,
977+ "94ff089e60064bfa43e374baeb10846f7ce82f40" );
978+ int actualCount = 0 ;
979+ for (GHCompare .Commit item : compare .getCommits ()) {
980+ assertThat (item , notNullValue ());
981+ actualCount ++;
982+ }
983+ assertThat (compare .getTotalCommits (), is (283 ));
984+ assertThat (actualCount , is (283 ));
985+ assertThat (mockGitHub .getRequestCount (), equalTo (startingCount + 4 ));
986+ }
987+
869988}
0 commit comments