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.
Asked
Active
Viewed 1,500 times
1 Answers
-1
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());
}
}
assuming the file github.credentials
contains
login=your_user_name
password=your_access_token
The access token can be created for your GitHub user at https://github.com/settings/tokens.
output
release: v0.1
assets :
asset-demo.txt - https://github.com/SubOptimal/examples-repo/releases/download/v0.1/asset-demo.txt
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).

SubOptimal
- 22,518
- 3
- 53
- 69