@@ -914,18 +914,7 @@ public File getRepositoryArchive(
914
914
*/
915
915
public CompareResults compare (Object projectIdOrPath , String from , String to , boolean straight )
916
916
throws GitLabApiException {
917
- Form formData = new GitLabApiForm ()
918
- .withParam ("from" , from , true )
919
- .withParam ("to" , to , true )
920
- .withParam ("straight" , straight );
921
- Response response = get (
922
- Response .Status .OK ,
923
- formData .asMap (),
924
- "projects" ,
925
- getProjectIdOrPath (projectIdOrPath ),
926
- "repository" ,
927
- "compare" );
928
- return (response .readEntity (CompareResults .class ));
917
+ return compare (projectIdOrPath , from , to , null , straight );
929
918
}
930
919
931
920
/**
@@ -942,6 +931,38 @@ public CompareResults compare(Object projectIdOrPath, String from, String to) th
942
931
return (compare (projectIdOrPath , from , to , false ));
943
932
}
944
933
934
+ /**
935
+ * Compare branches, tags or commits. This can be accessed without authentication
936
+ * if the repository is publicly accessible.
937
+ *
938
+ * @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
939
+ * @param from the commit SHA or branch name
940
+ * @param to the commit SHA or branch name
941
+ * @param fromProjectId The ID to compare from.
942
+ * @param straight specifies the comparison method, true for direct comparison between from and to (from..to),
943
+ * false to compare using merge base (from…to)
944
+ * @return a CompareResults containing the results of the comparison
945
+ * @throws GitLabApiException if any exception occurs
946
+ */
947
+ public CompareResults compare (Object projectIdOrPath , String from , String to , Object fromProjectId , boolean straight )
948
+ throws GitLabApiException {
949
+ GitLabApiForm formData = new GitLabApiForm ()
950
+ .withParam ("from" , from , true )
951
+ .withParam ("to" , to , true )
952
+ .withParam ("straight" , straight );
953
+ if (fromProjectId != null ) {
954
+ formData .withParam ("from_project_id" , fromProjectId );
955
+ }
956
+ Response response = get (
957
+ Response .Status .OK ,
958
+ formData .asMap (),
959
+ "projects" ,
960
+ getProjectIdOrPath (projectIdOrPath ),
961
+ "repository" ,
962
+ "compare" );
963
+ return (response .readEntity (CompareResults .class ));
964
+ }
965
+
945
966
/**
946
967
* Get a list of contributors from a project.
947
968
*
0 commit comments