private void doCreatePullRequest( @NotNull final Project project, @NotNull final ServerContext context, @NotNull final String title, @NotNull final String description, @NotNull final String branchNameOnRemoteServer, @NotNull final GitRemoteBranch targetBranch) { // should this be a method on the serverContext object? final URI collectionURI = URI.create( String.format( "%s/%s", context.getUri().toString(), context.getTeamProjectCollectionReference().getName())); final GitHttpClient gitClient = new GitHttpClient(context.getClient(), collectionURI); try { final UUID repositoryId = context.getGitRepository().getId(); final UUID projectId = context.getTeamProjectReference().getId(); final GitPullRequest pullRequestToBeCreated = pullRequestHelper.generateGitPullRequest( title, description, branchNameOnRemoteServer, targetBranch); final GitPullRequest gitPullRequest = gitClient.createPullRequest(pullRequestToBeCreated, projectId, repositoryId); final String repositoryRemoteUrl = context.getGitRepository().getRemoteUrl(); notifySuccess( project, TfPluginBundle.message(TfPluginBundle.KEY_CREATE_PR_CREATED_TITLE), pullRequestHelper.getHtmlMsg(repositoryRemoteUrl, gitPullRequest.getPullRequestId())); } catch (Throwable t) { // catch everything so we don't bubble up to Intellij final Pair<PRCreateStatus, String> parsed = pullRequestHelper.parseException( t, branchNameOnRemoteServer, targetBranch, context, gitClient); if (parsed.getFirst() == PRCreateStatus.DUPLICATE) { notifySuccess( project, TfPluginBundle.message(TfPluginBundle.KEY_CREATE_PR_ALREADY_EXISTS_TITLE), parsed.getSecond()); } else { notifyCreateFailedError(project, parsed.getSecond()); logger.warn("Create pull request failed", t); } } }
/** * This method gets all the info we need from the server given the parse results. If some call * fails we simply return false and ignore the results. * * @param parseResult * @return */ @Override public boolean validate(UrlHelper.ParseResult parseResult) { try { final URI collectionUri = URI.create(parseResult.getCollectionUrl()); final GitHttpClient gitClient = new GitHttpClient(client, collectionUri); // Get the repository object and team project repository = gitClient.getRepository(parseResult.getProjectName(), parseResult.getRepoName()); // Get the collection object final URI serverUri = URI.create(parseResult.getServerUrl()); final CoreHttpClient coreClient = new CoreHttpClient(client, serverUri); collection = coreClient.getProjectCollection(parseResult.getCollectionName()); } catch (Throwable throwable) { // TODO Log the failure return false; } return true; }