java api获取企业github的文件内容 [英] java api to get a file content for enterprise github

查看:288
本文介绍了java api获取企业github的文件内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我非常努力地编写了简单的代码行,该代码使用oauth令牌从企业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.

我尝试了 https://github.com/jcabi/jcabi-github ,但是它不支持企业github吗?(也许我错了)

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

现在我正在尝试自闭:

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

GitHubRequest request = new GitHubRequest();

request.setUri("/readme");

GitHubResponse response = client.get(request);

那又是什么?我只看到一个getBody,也许我需要用某种json库解析它?它必须更简单..我期望像这样的东西:repo.get(url).getContent()

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()

推荐答案

最后通过阅读源代码找出答案.

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

这篇关于java api获取企业github的文件内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆