当前位置: 首页>>代码示例>>Java>>正文


Java GitHubBuilder.build方法代码示例

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


在下文中一共展示了GitHubBuilder.build方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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.build方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。