本文整理匯總了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();
}
}
示例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;
}
示例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;
}
示例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);
}
示例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();
}
}
}
示例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);
}
示例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());
}
}
示例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;
}
示例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;
}
示例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());
}
}
}
示例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;
}
示例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");
}
}
示例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;
}
示例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));
}
}
示例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());
}