github api Java_github api for java使用踩坑之getStats总是null

github有一系列api作为查询的接口,同时还有用各种语言封装的版本。详情点击这里

当我今天打算调用getStats()方法时遇到了很坑的问题:返回值总是Null

代码如下:

GitHubClient client = newGitHubClient();

client.setCredentials("username", "password");

CommitService coms= newCommitService(client);

RepositoryService service= newRepositoryService(client);

Repository repo= service.getRepository("BokunoMasayume","bootstrap-note");for(RepositoryCommit rc : coms.getCommits(repo)){

System.out.println("total: "+rc.getStats());

}

我去查了github的原始api,发现当查询一个仓库的所有commits时,返回的commit列表中的每个commit信息都有所省略,而stats这个属性正好被省略了,

而在通过commit-sha和仓库查询的单个commit信息中有stats属性

commit集:https://api.github.com/repos/BokunoMasayume/bootstrap-note/commits

特定commit:https://api.github.com/repos/BokunoMasayume/bootstrap-note/commits/3084c0a49fbca0c496abac80191f04b929141d95

于是我在代码中加了一行rc = coms.getCommit(repo, rc.getSha());,将列表中的RepositoryCommit对象变成了单独(理解意思就好)的RepositoryCommit对象,果然,再次运行getStats正常了。

1 GitHubClient client = newGitHubClient();2 client.setCredentials("username", "password");3 CommitService coms = newCommitService(client);4 RepositoryService service = newRepositoryService(client);5 Repository repo = service.getRepository("BokunoMasayume","bootstrap-note");6 for(RepositoryCommit rc : coms.getCommits(repo)){7 rc =coms.getCommit(repo, rc.getSha());8 System.out.println("total: "+rc.getStats().getTotal);9 }

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值