/** * Create repository id from given owner and name. * * @param owner * @param name * @return repository id */ public static RepositoryId create(String owner, String name) { return new RepositoryId(owner, name); }
/** * Get repository * * @param owner * @param name * @return repository * @throws IOException */ public Repository getRepository(final String owner, final String name) throws IOException { return getRepository(RepositoryId.create(owner, name)); }
/** * Create repository from url. * * @see #createFromId(String) * @param url * @return repository or null if parsing fails */ public static RepositoryId createFromUrl(URL url) { return url != null ? createFromId(url.getPath()) : null; }
return RepositoryId.create(owner, name); repo = RepositoryId.createFromUrl(scm.getUrl()); if (repo == null) repo = extractRepositoryFromScmUrl(scm.getConnection()); repo = RepositoryId.createFromUrl(project.getUrl());
@Override public String toString() { return generateId(); } }
/** * Create from string URL * * @see #createFromUrl(URL) * @param url * @return repository or null if it could not be parsed from URL path */ public static RepositoryId createFromUrl(String url) { if (url == null || url.length() == 0) return null; try { return createFromUrl(new URL(url)); } catch (MalformedURLException e) { return null; } }
return RepositoryId.create(owner, name); repo = RepositoryId.createFromUrl(scm.getUrl()); if (repo == null) repo = extractRepositoryFromScmUrl(scm.getConnection()); repo = RepositoryId.createFromUrl(project.getUrl());
@Override public int hashCode() { return generateId().hashCode(); }
/** * Create repository from id. The id is split on the '/' character and the * first two non-empty segments are interpreted to be the repository owner * and name. * * @param id * @return repository */ public static RepositoryId createFromId(String id) { if (id == null || id.length() == 0) return null; String owner = null; String name = null; for (String segment : id.split("/")) //$NON-NLS-1$ if (segment.length() > 0) if (owner == null) owner = segment; else if (name == null) name = segment; else break; return owner != null && owner.length() > 0 && name != null && name.length() > 0 ? new RepositoryId(owner, name) : null; }
/** * Get repository and throw a {@link MojoExecutionException} on failures * * @param project * @param owner * @param name * @return non-null repository id * @throws MojoExecutionException */ protected RepositoryId getRepository(final MavenProject project, final String owner, final String name) throws MojoExecutionException { RepositoryId repository = RepositoryUtils.getRepository(project, owner, name); if (repository == null) throw new MojoExecutionException( "No GitHub repository (owner and name) configured"); if (isDebug()) debug(MessageFormat.format("Using GitHub repository {0}", repository.generateId())); return repository; }
/** * Extra repository id from given SCM URL * * @param url * @return repository id or null if extraction fails */ public static RepositoryId extractRepositoryFromScmUrl(String url) { if (StringUtils.isEmpty(url)) return null; int ghIndex = url.indexOf(HOST_DEFAULT); if (ghIndex == -1 || ghIndex + 1 >= url.length()) return null; if (!url.endsWith(SUFFIX_GIT)) return null; url = url.substring(ghIndex + HOST_DEFAULT.length() + 1, url.length() - SUFFIX_GIT.length()); return RepositoryId.createFromId(url); }
private void forkRepo(String repoName, String repoOwner) { wizard.showMessage("Forking " + repoName + " from " + repoOwner); GitHubClient client = new GitHubClient(); client.setCredentials(githubUsername, githubPassword); RepositoryService service = new RepositoryService(); service.getClient().setCredentials(githubUsername, githubPassword); RepositoryId toBeForked = new RepositoryId(repoOwner, repoName); try { service.forkRepository(toBeForked); } catch (IOException e) { throw new IllegalStateException("Failed to fork repository", e); } }
/** * Get repository and throw a {@link MojoExecutionException} on failures * * @param project * @param owner * @param name * @return non-null repository id * @throws MojoExecutionException */ protected RepositoryId getRepository(final MavenProject project, final String owner, final String name) throws MojoExecutionException { RepositoryId repository = RepositoryUtils.getRepository(project, owner, name); if (repository == null) throw new MojoExecutionException( "No GitHub repository (owner and name) configured"); if (isDebug()) debug(MessageFormat.format("Using GitHub repository {0}", repository.generateId())); return repository; }
/** * Extra repository id from given SCM URL * * @param url * @return repository id or null if extraction fails */ public static RepositoryId extractRepositoryFromScmUrl(String url) { if (StringUtils.isEmpty(url)) return null; int ghIndex = url.indexOf(HOST_DEFAULT); if (ghIndex == -1 || ghIndex + 1 >= url.length()) return null; if (!url.endsWith(SUFFIX_GIT)) return null; url = url.substring(ghIndex + HOST_DEFAULT.length() + 1, url.length() - SUFFIX_GIT.length()); return RepositoryId.createFromId(url); }
this.password); RepositoryId repositoryId = new RepositoryId(repoOwner, repoName); if (pullRequestService.getPullRequest(repositoryId,
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) { try { RequiredParameterValidator.validate(this.getClass(), workItem); Map<String, Object> results = new HashMap<String, Object>(); String repoOwner = (String) workItem.getParameter("RepoOwner"); String repoName = (String) workItem.getParameter("RepoName"); String organization = (String) workItem.getParameter("Organization"); Repository forkedRepository; RepositoryService repoService = auth.getRespositoryService(this.userName, this.password); RepositoryId toBeForkedRepo = new RepositoryId(repoOwner, repoName); if (StringUtils.isNotEmpty(organization)) { forkedRepository = repoService.forkRepository(toBeForkedRepo, organization); } else { forkedRepository = repoService.forkRepository(toBeForkedRepo); } results.put(RESULTS_VALUE, new RepositoryInfo(forkedRepository)); workItemManager.completeWorkItem(workItem.getId(), results); } catch (Exception e) { handleException(e); } }
public GitHubCommentsProvider( ViolationsLogger violationsLogger, final ViolationCommentsToGitHubApi violationCommentsToGitHubApi) { this.violationsLogger = violationsLogger; final GitHubClient gitHubClient = createClient(violationCommentsToGitHubApi.getGitHubUrl()); if (violationCommentsToGitHubApi.getOAuth2Token() != null) { gitHubClient.setOAuth2Token(violationCommentsToGitHubApi.getOAuth2Token()); } else if (violationCommentsToGitHubApi.getUsername() != null && violationCommentsToGitHubApi.getPassword() != null) { gitHubClient.setCredentials( violationCommentsToGitHubApi.getUsername(), violationCommentsToGitHubApi.getPassword()); } repository = new RepositoryId( violationCommentsToGitHubApi.getRepositoryOwner(), violationCommentsToGitHubApi.getRepositoryName()); pullRequestService = new PullRequestService(gitHubClient); issueSerivce = new IssueService(gitHubClient); List<RepositoryCommit> commits = null; try { commits = pullRequestService.getCommits( repository, violationCommentsToGitHubApi.getPullRequestId()); } catch (final IOException e) { throw new RuntimeException(e); } pullRequestCommit = commits.get(commits.size() - 1).getSha(); this.violationCommentsToGitHubApi = violationCommentsToGitHubApi; }
GitHubClient client = new GitHubClient(); client.setOAuth2Token(gitAccessToken); RepositoryId repoID = new RepositoryId(gitRepoUser, gitRepo); IssueService issueService = new IssueService(client);