java 读取git文件,java api获取企业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()

解决方案

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 test = contentService.getContents(repo, YOURFILENAME);

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

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值