• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java GitHubBuilder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.kohsuke.github.GitHubBuilder的典型用法代码示例。如果您正苦于以下问题:Java GitHubBuilder类的具体用法?Java GitHubBuilder怎么用?Java GitHubBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



GitHubBuilder类属于org.kohsuke.github包,在下文中一共展示了GitHubBuilder类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getGithub

import org.kohsuke.github.GitHubBuilder; //导入依赖的package包/类
public GitHub getGithub() throws IOException {
    if (github == null) {
        GitHubBuilder ghb = new GitHubBuilder();
        String username = getGithubUsername();
        String password = getGithubPassword();
        String token = getGithubToken();
        if (Strings.notEmpty(username) && Strings.notEmpty(password)) {
            ghb.withPassword(username, password);
        } else if (Strings.notEmpty(token)) {
            if (Strings.notEmpty(username)) {
                ghb.withOAuthToken(token, username);
            } else {
                ghb.withOAuthToken(token);
            }
        }
        ghb.withRateLimitHandler(RateLimitHandler.WAIT).
                withAbuseLimitHandler(AbuseLimitHandler.WAIT);
        this.github = ghb.build();
    }
    return this.github;
}
 
开发者ID:fabric8-updatebot,项目名称:updatebot,代码行数:22,代码来源:Configuration.java


示例2: initializeDockerfileGithubUtil

import org.kohsuke.github.GitHubBuilder; //导入依赖的package包/类
public static DockerfileGitHubUtil initializeDockerfileGithubUtil(String gitApiUrl) throws IOException {
    if (gitApiUrl == null) {
        gitApiUrl = System.getenv("git_api_url");
        if (gitApiUrl == null) {
            throw new IOException("No Git API URL in environment variables.");
        }
    }
    String token = System.getenv("git_api_token");
    if (token == null) {
        log.error("Please provide GitHub token in environment variables.");
        System.exit(3);
    }

    GitHub github = new GitHubBuilder().withEndpoint(gitApiUrl)
            .withOAuthToken(token)
            .build();
    github.checkApiUrlValidity();

    GitHubUtil gitHubUtil = new GitHubUtil(github);

    return new DockerfileGitHubUtil(gitHubUtil);
}
 
开发者ID:salesforce,项目名称:dockerfile-image-update,代码行数:23,代码来源:CommandLine.java


示例3: init

import org.kohsuke.github.GitHubBuilder; //导入依赖的package包/类
public void init(int pullRequestNumber, File projectBaseDir) {
  initGitBaseDir(projectBaseDir);
  try {
    GitHub github;
    if (config.isProxyConnectionEnabled()) {
      github = new GitHubBuilder().withProxy(config.getHttpProxy()).withEndpoint(config.endpoint()).withOAuthToken(config.oauth()).build();
    } else {
      github = new GitHubBuilder().withEndpoint(config.endpoint()).withOAuthToken(config.oauth()).build();
    }
    setGhRepo(github.getRepository(config.repository()));
    setPr(ghRepo.getPullRequest(pullRequestNumber));
    LOG.info("Starting analysis of pull request: " + pr.getHtmlUrl());
    myself = github.getMyself().getLogin();
    loadExistingReviewComments();
    patchPositionMappingByFile = mapPatchPositionsToLines(pr);
  } catch (IOException e) {
    LOG.debug("Unable to perform GitHub WS operation", e);
    throw MessageException.of("Unable to perform GitHub WS operation: " + e.getMessage());
  }
}
 
开发者ID:SonarSource,项目名称:sonar-github,代码行数:21,代码来源:PullRequestFacade.java


示例4: create

import org.kohsuke.github.GitHubBuilder; //导入依赖的package包/类
@Override
public GitHubService create(final Identity identity) {

    // Precondition checks
    if (identity == null) {
        throw new IllegalArgumentException("Identity is required");
    }

    final GitHub gitHub;
    try {
        final GitHubBuilder ghb = new GitHubBuilder()
                .withConnector(new OkHttp3Connector(new OkHttpClient()));
        identity.accept(new IdentityVisitor() {
            @Override
            public void visit(TokenIdentity token) {
                ghb.withOAuthToken(token.getToken());
            }

            @Override
            public void visit(UserPasswordIdentity userPassword) {
                ghb.withPassword(userPassword.getUsername(), userPassword.getPassword());
            }
        });
        gitHub = ghb.build();
    } catch (final IOException ioe) {
        throw new RuntimeException("Could not create GitHub client", ioe);
    }
    final GitHubService ghs = new KohsukeGitHubServiceImpl(gitHub, identity);
    log.finest(() -> "Created backing GitHub client for identity using " + identity.getClass().getSimpleName());
    return ghs;
}
 
开发者ID:fabric8-launcher,项目名称:launcher-backend,代码行数:32,代码来源:KohsukeGitHubServiceFactoryImpl.java


示例5: GitHubFacade

import org.kohsuke.github.GitHubBuilder; //导入依赖的package包/类
public GitHubFacade(GitAccount details) {
    this.details = details;

    String username = details.getUsername();
    String token = details.getToken();
    String password = details.getPassword();

    try {
        final GitHubBuilder ghb = new GitHubBuilder();
        if (Strings.isNotBlank(username) && Strings.isNotBlank(password)) {
            ghb.withPassword(username, password);
        } else if (Strings.isNotBlank(token)) {
            if (Strings.isNotBlank(username)) {
                ghb.withOAuthToken(token, username);
            } else {
                ghb.withOAuthToken(token);
            }
        }
        this.github = ghb.build();
        this.myself = this.github.getMyself();
        String login = myself.getLogin();
        if (Strings.isNotBlank(login) && !Objects.equals(login, username)) {
            LOG.debug("Switching the github user name from " + username + " to " + login);
            details.setUsername(login);
        }
        // lets always use the github email address
        String email = myself.getEmail();
        if (Strings.isNotBlank(email)) {
            details.setEmail(email);
        }
    } catch (IOException e) {
        LOG.warn("Failed to create github client for user " + details.getUsername());
    }
}
 
开发者ID:fabric8-launcher,项目名称:launcher-backend,代码行数:35,代码来源:GitHubFacade.java


示例6: getRelease

import org.kohsuke.github.GitHubBuilder; //导入依赖的package包/类
/**
 * @return a {@link GHRelease} for the latest ServerBrowser release
 * @throws IOException
 *             if there was an error querying GitHub
 */
public static Optional<GHRelease> getRelease() throws IOException {
	final GitHub gitHub = GitHubBuilder.fromEnvironment().withRateLimitHandler(RateLimitHandler.FAIL).build();
	final GHRepository repository = gitHub.getRepository("Bios-Marcel/ServerBrowser");
	final List<GHRelease> releases = repository.listReleases().asList();
	if (!releases.isEmpty()) {
		return Optional.ofNullable(releases.get(0));
	}
	return Optional.empty();
}
 
开发者ID:Bios-Marcel,项目名称:ServerBrowser,代码行数:15,代码来源:UpdateUtility.java


示例7: setUp

import org.kohsuke.github.GitHubBuilder; //导入依赖的package包/类
@BeforeClass
public void setUp() throws Exception {
    String gitApiUrl = System.getenv("git_api_url");
    String token = System.getenv("git_api_token");
    github = new GitHubBuilder().withEndpoint(gitApiUrl)
            .withOAuthToken(token)
            .build();
    github.checkApiUrlValidity();
    gitHubUtil = new GitHubUtil(github);

    cleanBefore(REPOS, DUPLICATES_CREATED_BY_GIT_HUB, STORE_NAME, github);

    GHOrganization org = github.getOrganization(ORGS.get(0));
    initializeRepos(org, REPOS, IMAGE_1, createdRepos, gitHubUtil);

    GHRepository store = github.createRepository(STORE_NAME)
            .description("Delete if this exists. If it exists, then an integration test crashed somewhere.")
            .create();
    store.createContent("{\n  \"images\": {\n" +
            "    \"" + IMAGE_1 + "\": \"" + TEST_TAG + "\",\n" +
            "    \"" + IMAGE_2 + "\": \"" + TEST_TAG + "\"\n" +
            "  }\n" +
            "}",
            "Integration Testing", "store.json");
    createdRepos.add(store);

    for (String s: ORGS) {
        org = github.getOrganization(s);
        initializeRepos(org, DUPLICATES, IMAGE_2, createdRepos, gitHubUtil);
    }
    /* We need to wait because there is a delay on the search API used in the all command; it takes time
     * for the search API to pick up recently created repositories.
     */
    checkIfSearchUpToDate("image1", IMAGE_1, REPOS.size(), github);
    checkIfSearchUpToDate("image2", IMAGE_2, DUPLICATES.size() * ORGS.size(), github);
}
 
开发者ID:salesforce,项目名称:dockerfile-image-update,代码行数:37,代码来源:AllCommandTest.java


示例8: getHub

import org.kohsuke.github.GitHubBuilder; //导入依赖的package包/类
public GitHub getHub() throws IOException {
  if (token == null) {
    return null;
  }
  return new GitHubBuilder()
      .withEndpoint(config.gitHubApiUrl)
      .withOAuthToken(token.accessToken)
      .withConnector(httpConnector)
      .build();
}
 
开发者ID:GerritCodeReview,项目名称:plugins_github,代码行数:11,代码来源:GitHubLogin.java


示例9: getBuilder

import org.kohsuke.github.GitHubBuilder; //导入依赖的package包/类
private static GitHubBuilder getBuilder(Item context, String serverAPIUrl, String credentialsId) {
    GitHubBuilder builder = new GitHubBuilder()
        .withEndpoint(serverAPIUrl)
        .withConnector(new HttpConnectorWithJenkinsProxy());
    String contextName = context == null ? "(Jenkins.instance)" : context.getFullDisplayName();
    
    if (StringUtils.isEmpty(credentialsId)) {
        logger.log(Level.WARNING, "credentialsId not set for context {0}, using anonymous connection", contextName);
        return builder;
    }

    StandardCredentials credentials = Ghprc.lookupCredentials(context, credentialsId, serverAPIUrl);
    if (credentials == null) {
        logger.log(Level.SEVERE, "Failed to look up credentials for context {0} using id: {1}",
                new Object[] { contextName, credentialsId });
    } else if (credentials instanceof StandardUsernamePasswordCredentials) {
        logger.log(Level.INFO, "Using username/password for context {0}", contextName);
        StandardUsernamePasswordCredentials upCredentials = (StandardUsernamePasswordCredentials) credentials;
        builder.withPassword(upCredentials.getUsername(), upCredentials.getPassword().getPlainText());
    } else if (credentials instanceof StringCredentials) {
        logger.log(Level.INFO, "Using OAuth token for context {0}", contextName);
        StringCredentials tokenCredentials = (StringCredentials) credentials;
        builder.withOAuthToken(tokenCredentials.getSecret().getPlainText());
    } else {
        logger.log(Level.SEVERE, "Unknown credential type for context {0} using id: {1}: {2}",
                new Object[] { contextName, credentialsId, credentials.getClass().getName() });
        return null;
    }
    return builder;
}
 
开发者ID:bratchenko,项目名称:jenkins-github-pull-request-comments,代码行数:31,代码来源:GhprcGitHubAuth.java


示例10: getConnection

import org.kohsuke.github.GitHubBuilder; //导入依赖的package包/类
public GitHub getConnection(Item context) throws IOException {
    GitHub gh = null;
    GitHubBuilder builder = getBuilder(context, serverAPIUrl, credentialsId);
    if (builder == null) {
      logger.log(Level.SEVERE, "Unable to get builder using credentials: {0}", credentialsId);
      return null;
    }
    try {
        gh = builder.build();
    } catch (IOException e) {
        logger.log(Level.SEVERE, "Unable to connect using credentials: " + credentialsId, e);
    }
    
    return gh;
}
 
开发者ID:bratchenko,项目名称:jenkins-github-pull-request-comments,代码行数:16,代码来源:GhprcGitHubAuth.java


示例11: doCheckRepoAccess

import org.kohsuke.github.GitHubBuilder; //导入依赖的package包/类
public FormValidation doCheckRepoAccess(
        @QueryParameter("serverAPIUrl") final String serverAPIUrl, 
        @QueryParameter("credentialsId") final String credentialsId,
        @QueryParameter("repo") final String repo) {
    try {
        GitHubBuilder builder = getBuilder(null, serverAPIUrl, credentialsId);
        if (builder == null) {
            return FormValidation.error("Unable to look up GitHub credentials using ID: " + credentialsId + "!!");
        }
        GitHub gh = builder.build();
        GHRepository repository = gh.getRepository(repo);
        StringBuilder sb = new StringBuilder();
        sb.append("User has access to: ");
        List<String> permissions = new ArrayList<String>(3);
        if (repository.hasAdminAccess()) {
            permissions.add("Admin");
        }
        if (repository.hasPushAccess()) {
            permissions.add("Push");
        }
        if (repository.hasPullAccess()) {
            permissions.add("Pull");
        }
        sb.append(Joiner.on(", ").join(permissions));
        
        return FormValidation.ok(sb.toString());
    } catch (Exception ex) {
        return FormValidation.error("Unable to connect to GitHub API: " + ex);
    }
}
 
开发者ID:bratchenko,项目名称:jenkins-github-pull-request-comments,代码行数:31,代码来源:GhprcGitHubAuth.java


示例12: doTestGithubAccess

import org.kohsuke.github.GitHubBuilder; //导入依赖的package包/类
public FormValidation doTestGithubAccess(
        @QueryParameter("serverAPIUrl") final String serverAPIUrl, 
        @QueryParameter("credentialsId") final String credentialsId) {
    try {
        GitHubBuilder builder = getBuilder(null, serverAPIUrl, credentialsId);
        if (builder == null) {
            return FormValidation.error("Unable to look up GitHub credentials using ID: " + credentialsId + "!!");
        }
        GitHub gh = builder.build();
        GHMyself me = gh.getMyself();
        return FormValidation.ok("Connected to " + serverAPIUrl + " as " + me.getName());
    } catch (Exception ex) {
        return FormValidation.error("Unable to connect to GitHub API: " + ex);
    }
}
 
开发者ID:bratchenko,项目名称:jenkins-github-pull-request-comments,代码行数:16,代码来源:GhprcGitHubAuth.java


示例13: doCreateApiToken

import org.kohsuke.github.GitHubBuilder; //导入依赖的package包/类
public FormValidation doCreateApiToken(
        @QueryParameter("serverAPIUrl") final String serverAPIUrl, 
        @QueryParameter("credentialsId") final String credentialsId, 
        @QueryParameter("username") final String username, 
        @QueryParameter("password") final String password) {
    try {

        GitHubBuilder builder = new GitHubBuilder()
                    .withEndpoint(serverAPIUrl)
                    .withConnector(new HttpConnectorWithJenkinsProxy());
        
        if (StringUtils.isEmpty(credentialsId)) {
            if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) {
                return FormValidation.error("Username and Password required");
            }

            builder.withPassword(username, password);
        } else {
            StandardCredentials credentials = Ghprc.lookupCredentials(null, credentialsId, serverAPIUrl);
            if (credentials instanceof StandardUsernamePasswordCredentials) {
                StandardUsernamePasswordCredentials upCredentials = (StandardUsernamePasswordCredentials) credentials;
                builder.withPassword(upCredentials.getUsername(), upCredentials.getPassword().getPlainText());
            } else {
                return FormValidation.error("No username/password credentials provided");
            }
        }
        GitHub gh = builder.build();
        GHAuthorization token = gh.createToken(Arrays.asList(GHAuthorization.REPO_STATUS, 
                GHAuthorization.REPO), "Jenkins GitHub Pull Request Comments", null);
        String tokenId;
        try {
            tokenId = Ghprc.createCredentials(serverAPIUrl, token.getToken());
        } catch (Exception e) {
            tokenId = "Unable to create credentials: " + e.getMessage();
        }
        
        return FormValidation.ok("Access token created: " + token.getToken() + " token CredentialsID: " + tokenId);
    } catch (IOException ex) {
        return FormValidation.error("GitHub API token couldn't be created: " + ex.getMessage());
    }
}
 
开发者ID:bratchenko,项目名称:jenkins-github-pull-request-comments,代码行数:42,代码来源:GhprcGitHubAuth.java



注:本文中的org.kohsuke.github.GitHubBuilder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java RpcKind类代码示例发布时间:2022-05-22
下一篇:
Java CastExpression类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap