4

我非常努力地尝试了一行简单的代码,它使用 oauth 令牌从企业 github 读取文件内容,但找不到这样的示例。

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

现在我正在尝试 egit:

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

GitHubRequest request = new GitHubRequest();

request.setUri("/readme");

GitHubResponse response = client.get(request);

然后呢?我只看到了一个getBody,也许我需要用一些json库来解析它?它必须更简单..我期待类似:repo.get(url).getContent()

4

1 回答 1

10

最后通过阅读源代码弄清楚..

    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();
    }
于 2014-07-15T03:32:40.737 回答