當前位置: 首頁>>代碼示例>>Java>>正文


Java GitHub類代碼示例

本文整理匯總了Java中org.kohsuke.github.GitHub的典型用法代碼示例。如果您正苦於以下問題:Java GitHub類的具體用法?Java GitHub怎麽用?Java GitHub使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


GitHub類屬於org.kohsuke.github包,在下文中一共展示了GitHub類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: readGHRepo

import org.kohsuke.github.GitHub; //導入依賴的package包/類
public static Optional<GHRepository> readGHRepo() {
	try {
		GitHub github = GitHub.connect();
		String desiredRepo = System.getProperty("GITHUB_REPOSITORY");
		System.out.println("Desired Repo:" + desiredRepo);
		GHRepository repo = github.getRepository(desiredRepo);
		return Optional.of(repo);
	} catch (Exception e) {
		for (Object o : System.getProperties().keySet()) {
			System.out.println(o + ":" + System.getProperty(o + ""));
		}

		for (String env : System.getenv().keySet()) {
			System.out.println(env + ":" + System.getenv(env));
		}
		e.printStackTrace();
		return Optional.empty();
	}
}
 
開發者ID:eraether,項目名稱:WatchWordBot,代碼行數:20,代碼來源:Runner.java

示例2: checkTeamMembershipUsingPersonalAccessToken

import org.kohsuke.github.GitHub; //導入依賴的package包/類
private boolean checkTeamMembershipUsingPersonalAccessToken(LoggedInUserInfo loggedInUserInfo, AuthConfig authConfig, Map<String, List<String>> organizationAndTeamsAllowed) throws IOException {
    final GitHub gitHubForPersonalAccessToken = authConfig.gitHubConfiguration().gitHubClient();

    for (String organizationName : organizationAndTeamsAllowed.keySet()) {
        final GHOrganization organization = gitHubForPersonalAccessToken.getOrganization(organizationName);

        if (organization != null) {
            final List<String> allowedTeamsFromRole = organizationAndTeamsAllowed.get(organizationName);
            final Map<String, GHTeam> teamsFromGitHub = organization.getTeams();

            for (GHTeam team : teamsFromGitHub.values()) {
                if (allowedTeamsFromRole.contains(team.getName().toLowerCase()) && team.hasMember(loggedInUserInfo.getGitHubUser())) {
                    LOG.info(format("[MembershipChecker] User `{0}` is a member of `{1}` team.", loggedInUserInfo.getUser().username(), team.getName()));
                    return true;
                }
            }
        }
    }

    return false;
}
 
開發者ID:gocd-contrib,項目名稱:github-oauth-authorization-plugin,代碼行數:22,代碼來源:MembershipChecker.java

示例3: getGithub

import org.kohsuke.github.GitHub; //導入依賴的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

示例4: initializeDockerfileGithubUtil

import org.kohsuke.github.GitHub; //導入依賴的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

示例5: getGitHub

import org.kohsuke.github.GitHub; //導入依賴的package包/類
private GitHub getGitHub() throws IOException {
    final SettingsRepository settingsRepository = ServiceRegistry.getSettingsRepository();
    final String apiUrl = settingsRepository.getGitHubApiUrl();
    final String personalAccessToken = settingsRepository.getPersonalAccessToken();

    if (apiUrl != null) {
        if (personalAccessToken != null) {
            return GitHub.connectToEnterprise(apiUrl, personalAccessToken);
        } else {
            return GitHub.connectToEnterpriseAnonymously(apiUrl);
        }
    } else {
        if (personalAccessToken != null) {
            return GitHub.connectUsingOAuth(personalAccessToken);
        } else {
            return GitHub.connectAnonymously();
        }
    }
}
 
開發者ID:terma,項目名稱:github-pr-coverage-status,代碼行數:20,代碼來源:CachedGitHubRepository.java

示例6: runSearch

import org.kohsuke.github.GitHub; //導入依賴的package包/類
protected static void runSearch(BaseSearch... searches) throws IOException {
    GitHub github = BaseSearch.connect();

    // use a SetMultimap here to not record duplicates
    SetMultimap<String,String> versions = HashMultimap.create();
    for (BaseSearch search : searches) {
        search.search(github, versions);
    }

    System.out.println("Had " + versions.keySet().size() + " different versions for " + versions.size() + " projects");
    for(String version : versions.keySet()) {
        System.out.println("Had: " + version + ' ' + versions.get(version).size() + " times");
    }

    JSONWriter.write(DATE_FORMAT.format(new Date()), versions);
}
 
開發者ID:centic9,項目名稱:github-version-statistics,代碼行數:17,代碼來源:Search.java

示例7: init

import org.kohsuke.github.GitHub; //導入依賴的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

示例8: searchUser

import org.kohsuke.github.GitHub; //導入依賴的package包/類
@Override
public List<User> searchUser(GithubPluginSettings pluginSettings, String searchTerm) {
    List<User> users = new ArrayList<User>();
    try {
        GitHub github = getGitHub(pluginSettings);

        PagedSearchIterable<GHUser> githubSearchResults = github.searchUsers().q(searchTerm).list();
        int count = 0;
        for (GHUser githubSearchResult : githubSearchResults) {
            users.add(new User(githubSearchResult.getLogin(), githubSearchResult.getName(), githubSearchResult.getEmail()));
            count++;

            if (count == 10) {
                break;
            }
        }
    } catch (Exception e) {
        LOGGER.warn("Error occurred while trying to perform user search", e);
    }
    return users;
}
 
開發者ID:gocd-contrib,項目名稱:gocd-oauth-login,代碼行數:22,代碼來源:GitHubProvider.java

示例9: isAMemberOfOrganization

import org.kohsuke.github.GitHub; //導入依賴的package包/類
private boolean isAMemberOfOrganization(GithubPluginSettings pluginSettings, User user) {
    try {
        GitHub github = getGitHub(pluginSettings);
        GHUser ghUser = github.getUser(user.getUsername());

        if(ghUser == null) return false;

        for(String orgName: pluginSettings.getGithubOrganizations()) {
            GHOrganization organization = github.getOrganization(orgName);

            if(organization != null && ghUser.isMemberOf(organization)){
                return true;
            }
        }
    } catch (Exception e) {
        LOGGER.warn("Error occurred while trying to check if user is member of organization", e);
    }
    return false;
}
 
開發者ID:gocd-contrib,項目名稱:gocd-oauth-login,代碼行數:20,代碼來源:GitHubProvider.java

示例10: listRepositoriesByAccount

import org.kohsuke.github.GitHub; //導入依賴的package包/類
@GET
@Path("list/account")
@Produces(MediaType.APPLICATION_JSON)
public GitHubRepositoryList listRepositoriesByAccount(
    @QueryParam("account") String account, @HeaderParam(AUTH_HEADER_NAME) String oauthToken)
    throws ApiException {
  GitHub gitHub = gitHubFactory.oauthConnect(oauthToken);
  try {
    // First, try to retrieve organization repositories:
    return gitHubDTOFactory.createRepositoriesList(
        gitHub.getOrganization(account).listRepositories());
  } catch (IOException ioException) {
    LOG.error("Get list repositories by account fail", ioException);
    // If account is not organization, then try by user name:
    try {
      return gitHubDTOFactory.createRepositoriesList(gitHub.getUser(account).listRepositories());
    } catch (IOException exception) {
      LOG.error("Get list repositories by account fail", exception);
      throw new ServerException(exception.getMessage());
    }
  }
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:23,代碼來源:GitHubService.java

示例11: deleteRepository

import org.kohsuke.github.GitHub; //導入依賴的package包/類
/**
 * ɾ��ָ����repository
 * @param strRepoName Ҫɾ����github����
 * @return void
 */
public void deleteRepository(String strRepoName){
	GitHub github;
	GHRepository repo;
	try {
		System.out.println("Delete repo started!\t"+strRepoName);
		github = GitHub.connectToEnterprise(getApiUrl(), getUserId(), getPassword());
		
		repo = github.getRepository(strRepoName);
		repo.delete();

		System.out.println("Delete repo finished!");

	} catch (IOException e) {
		// TODO Auto-generated catch block
		errHandle(e.getMessage());
	}
	bFinished = true;
}
 
開發者ID:appbank2020,項目名稱:GitRobot,代碼行數:24,代碼來源:GitRobot.java

示例12: removeRepo

import org.kohsuke.github.GitHub; //導入依賴的package包/類
public synchronized static void removeRepo(String owner, String repoName) throws KaramelException {

    try {
      GitHub gitHub = GitHub.connectUsingPassword(GithubApi.getUser(), GithubApi.getPassword());
      if (!gitHub.isCredentialValid()) {
        throw new KaramelException("Invalid GitHub credentials");
      }
      GHRepository repo = null;
      if (owner.compareToIgnoreCase(GithubApi.getUser()) != 0) {
        GHOrganization org = gitHub.getOrganization(owner);
        repo = org.getRepository(repoName);
      } else {
        repo = gitHub.getRepository(owner + "/" + repoName);
      }
      repo.delete();

    } catch (IOException ex) {
      throw new KaramelException("Problem authenticating with gihub-api when trying to remove a repository");
    }
  }
 
開發者ID:karamelchef,項目名稱:karamel,代碼行數:21,代碼來源:GithubApi.java

示例13: createGitHubClient

import org.kohsuke.github.GitHub; //導入依賴的package包/類
GitHub createGitHubClient(String usernameToUse, String passwordToUse, String oauthAccessTokenToUse, String endPointToUse) throws Exception {
    GitHub github = null;
    if (usernameAndPasswordIsAvailable(usernameToUse, passwordToUse)) {
        if (endPointIsAvailable(endPointToUse)) {
            github = GitHub.connectToEnterprise(endPointToUse, usernameToUse, passwordToUse);
        } else {
            github = GitHub.connectUsingPassword(usernameToUse, passwordToUse);
        }
    }
    if (oAuthTokenIsAvailable(oauthAccessTokenToUse)) {
        if (endPointIsAvailable(endPointToUse)) {
            github = GitHub.connectUsingOAuth(endPointToUse, oauthAccessTokenToUse);
        } else {
            github = GitHub.connectUsingOAuth(oauthAccessTokenToUse);
        }
    }
    if (github == null) {
        github = GitHub.connect();
    }
    return github;
}
 
開發者ID:gocd-contrib,項目名稱:gocd-build-status-notifier,代碼行數:22,代碼來源:GitHubProvider.java

示例14: extractPullRequestInfo

import org.kohsuke.github.GitHub; //導入依賴的package包/類
private PullRequestInfo extractPullRequestInfo(GHEvent event, String payload, GitHub gh) throws IOException {
    switch (event) {
        case ISSUE_COMMENT: {
            IssueComment commentPayload = gh.parseEventPayload(new StringReader(payload), IssueComment.class);

            int prNumber = commentPayload.getIssue().getNumber();

            return new PullRequestInfo(commentPayload.getRepository().getFullName(), prNumber);
        }

        case PULL_REQUEST: {
            PullRequest pr = gh.parseEventPayload(new StringReader(payload), PullRequest.class);

            return new PullRequestInfo(pr.getPullRequest().getRepository().getFullName(), pr.getNumber());
        }

        default:
            throw new IllegalStateException(format("Did you add event %s in events() method?", event));
    }
}
 
開發者ID:KostyaSha,項目名稱:github-integration-plugin,代碼行數:21,代碼來源:GHPullRequestSubscriber.java

示例15: getGitHub

import org.kohsuke.github.GitHub; //導入依賴的package包/類
@Nonnull
@Override
public synchronized GitHub getGitHub(GitHubTrigger trigger) {
    if (isTrue(cacheConnection) && nonNull(gitHub)) {
        return gitHub;
    }

    final GitHubRepositoryName repoFullName = trigger.getRepoFullName();

    Optional<GitHub> client = from(GitHubPlugin.configuration().findGithubConfig(withHost(repoFullName.getHost())))
        .firstMatch(withPermission(repoFullName, getRepoPermission()));
    if (client.isPresent()) {
        gitHub = client.get();
        return gitHub;
    }

    throw new GHPluginConfigException("GitHubPluginRepoProvider can't find appropriate client for github repo " +
        "<%s>. Probably you didn't configure 'GitHub Plugin' global 'GitHub Server Settings' or there is no tokens" +
        "with %s access to this repository.",
        repoFullName.toString(), getRepoPermission());
}
 
開發者ID:KostyaSha,項目名稱:github-integration-plugin,代碼行數:22,代碼來源:GitHubPluginRepoProvider.java


注:本文中的org.kohsuke.github.GitHub類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。