参考: GitHub API for Java – (kohsuke.org)
依赖:
<dependency> <groupId>org.kohsuke</groupId> <artifactId>github-api</artifactId> <version>1.135</version> </dependency>
public GithubClient(String accessToken){ try{ github=GitHub.connectToEnterpriseWithOAuth("https://domain/api/v3",null,accessToken); userid=github.getMyself().getLogin(); userName=github.getMyself()/getName(); }..... }
public getRepository(String org,String repo){
try{
return github.getOrganization(org).getRepository(repo);
}....
}
public static String loadBranchFileContent(String org,String repo,String branchName,String path){
GHBranch branch=gitrepo.getBranch(branchName);
String branchRef=branch.getSHA1;
GHContent content=gitrepo.getFileContent(path,branchref);
Systom.out.println(content.getDownloadUrl())
.....
}