如何仅使用Java从私有仓库下载GitHub发布资源 [英] How to download GitHub release asset from private repo using only java

查看:272
本文介绍了如何仅使用Java从私有仓库下载GitHub发布资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过如何下载有关如何从命令行下载github发布资产的信息,请使用命令行从私人仓库中发布GitHub版本,但我想知道是否有人想出如何在100%Java中做到这一点?我可以使用 https://github.com找到资产的ID,并拥有所有者和存储库名称. /kohsuke/github-api .

I've seen How to download GitHub Release from private repo using command line on how to download a github release asset from command line but I was wondering if anybody has figured how to do it in 100% java? I can find the id of the asset and the have the owner and repository name using https://github.com/kohsuke/github-api.

推荐答案

下面的代码片段显示了原理.

Following snippet shows the principle.

String credentials = "github.credentials";
GitHub gitHub = GitHubBuilder.fromPropertyFile(credentials)
        .withRateLimitHandler(RateLimitHandler.FAIL)
        .build();
GHRepository repository = gitHub.getRepository("suboptimal/examples-repo");
for (GHRelease release : repository.listReleases()) {
    System.out.println("release: " + release.getName());
    System.out.println("assets :");
    for (GHAsset asset : release.getAssets()) {
        System.out.printf("   %s - %s%n", asset.getName(),
            asset.getBrowserDownloadUrl());
    }
}

假设文件github.credentials包含

login=your_user_name
password=your_access_token

可以在 https://github.com/settings/tokens .

输出

release: v0.1
assets :
  asset-demo.txt - https://github.com/SubOptimal/examples-repo/releases/download/v0.1/asset-demo.txt

您可以在
https://api.github.com/repos/SubOptimal/examples-repo/releases/assets/28055588进行验证
(对于私人仓库,您需要登录GitHub.)

You can verify it at
https://api.github.com/repos/SubOptimal/examples-repo/releases/assets/28055588
(for a private repo you would need to be logged in into GitHub).

这篇关于如何仅使用Java从私有仓库下载GitHub发布资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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