参考: 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())
   .....
}

 

posted on 2023-10-21 18:08  EZgod  阅读(6)  评论(0编辑  收藏  举报