Open liangjunfeng123 opened 2 months ago
I can not reproduce your issue.
This works for me, with the test project https://gitlab.com/jmini/test_project/
Tested with this jbang script:
///usr/bin/env jbang "$0" "$@" ; exit $?
import org.gitlab4j.api.GitLabApi;
//DEPS org.gitlab4j:gitlab4j-api:5.6.0
//JAVA 17
public class GitlabGetFileScript {
public static void main(String[] args) throws Exception {
try (GitLabApi gitLabApi = new GitLabApi("https://gitlab.com/", null)) {
long projectId = 42335703L;
String branch = "main";
String readmePath = "README.md";
String testPath = "a_long_folder_name/test.txt";
System.out.println("README");
System.out.println(gitLabApi.getRepositoryFileApi()
.getFile(projectId, readmePath, branch, true));
System.out.println("TEST file");
System.out.println(gitLabApi.getRepositoryFileApi()
.getFile(projectId, testPath, branch, true));
}
}
}
`package org.example; //DEPS org.gitlab4j:gitlab4j-api:5.5.0
//JAVA 17 import org.gitlab4j.api.GitLabApi; import org.gitlab4j.api.GitLabApiException;
public class Main {
private static final String gitLabApiUrl = "https://www.insoft-lab.com/gitlab";
private static final String token = "";
private static final GitLabApi gitLabApi = new GitLabApi(gitLabApiUrl, token);
public static void main(String[] args) {
long projectId = 6L;
String branch = "main";
String readmePath = "README.md";
String appVuePath = "src/App.vue";
try {
System.out.println(gitLabApi.getRepositoryFileApi().getFile(projectId, readmePath, branch, true));
} catch (GitLabApiException e) {
System.err.println("Error retrieving README.md: " + e.getMessage());
}
try {
System.out.println(gitLabApi.getRepositoryFileApi().getFile(projectId, appVuePath, branch, true));
} catch (GitLabApiException e) {
System.err.println("Error retrieving App.vue: " + e.getMessage());
}
}
}
` I can not get the content of App.vue. It output Error retrieving App.vue: 404 Not Found, but my gitlab repository has that file. Is it beacause of my gitlab URL is different?Or because of the URL encoding issue? Thank you for answering me! And this is my project https://www.insoft-lab.com/gitlab/chengjiahao/staticpageforpullrequests
I can't log in to your private gitlab instance. Maybe you can try to reproduce it on a public project on gitlab.com.
I am using gitlab4j with an on-prem gitlab installation all the time.
Maybe if you log the HTTP request and response as explained in https://github.com/gitlab4j/gitlab4j-api/issues/1109#issuecomment-2051728505 this will help you to understand what is going on.
Also you will be able to execute the same queries with a tool like curl
to check if the issue comes from your server
It can return the content of README.md, but return 404 Not Found when it get the content of src/App.vue. I am pretty sure that my gitlab has 'src/App.vue' in that project and that branch