Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getRepositoryFileApi.getFile couldn't return the content of file #1133

Open
liangjunfeng123 opened this issue Jun 22, 2024 · 3 comments
Open
Labels

Comments

@liangjunfeng123
Copy link

liangjunfeng123 commented Jun 22, 2024

long projectId = 6;
String branch = "dev";
String readmePath = "README.md";
String appVuePath = "src/App.vue";

System.out.println(gitLabApi.getRepositoryFileApi().getFile(projectId, readmePath, branch, true));
System.out.println(gitLabApi.getRepositoryFileApi().getFile(projectId, appVuePath, branch, true));

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

@jmini
Copy link
Collaborator

jmini commented Jul 1, 2024

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));
        }
    }
}

@jmini jmini added the question label Jul 1, 2024
@liangjunfeng123
Copy link
Author

liangjunfeng123 commented Jul 4, 2024

`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

@jmini
Copy link
Collaborator

jmini commented Aug 12, 2024

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 #1109 (comment) 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants