【问题标题】:How to download GitHub release asset from private repo using only java如何仅使用 java 从私有仓库下载 GitHub 发布资产
【发布时间】:2017-06-24 18:53:25
【问题描述】:

我已经看到How to download GitHub Release from private repo using command line 关于如何从命令行下载 github 发布资产,但我想知道是否有人想出如何在 100% java 中做到这一点?我可以使用https://github.com/kohsuke/github-api 找到资产的 ID 以及拥有者和存储库名称。

【问题讨论】:

    标签: java git github github-api


    【解决方案1】:

    下面sn-p说明原理。

    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 为您的 GitHub 用户创建访问令牌。

    输出

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-01
      • 1970-01-01
      • 2022-11-04
      • 1970-01-01
      • 2013-12-22
      • 2015-08-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多