Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java api to get a file content for enterprise github

I tried so hard for a simple line of code that read a file content from enterprise github with oauth token, but could not find a example of such.

I tried https://github.com/jcabi/jcabi-github, but it does not support enterprise github?(maybe I am wrong)

Now i am trying egit:

GitHubClient client = new GitHubClient("enterprise url");

GitHubRequest request = new GitHubRequest();

request.setUri("/readme");

GitHubResponse response = client.get(request);

Then what? I only saw a getBody, maybe I need to parse it with some kinda json library? It has to be simpler..I am expecting something like: repo.get(url).getContent()

like image 247
user648922 Avatar asked Dec 25 '22 06:12

user648922


1 Answers

Finally figure out by reading source code..

    GitHubClient client = new GitHubClient(YOURENTERPRICEURL);
    client.setOAuth2Token(token);

    // first use token service
    RepositoryService repoService = new RepositoryService(client);

    try {
        Repository repo = repoService.getRepository(USER, REPONAME);

        // now contents service
        ContentsService contentService = new ContentsService(client);
        List<RepositoryContents> test = contentService.getContents(repo, YOURFILENAME);

        List<RepositoryContents> contentList = contentService.getContents(repo);
        for(RepositoryContents content : test){
            String fileConent = content.getContent();
            String valueDecoded= new String(Base64.decodeBase64(fileConent.getBytes() ));
            System.out.println(valueDecoded);
        }

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
like image 180
user648922 Avatar answered Jan 18 '23 22:01

user648922