public GitPullRequest generateGitPullRequest( @NotNull final String title, @NotNull final String description, @NotNull final String branchNameOnRemoteServer, @NotNull final GitRemoteBranch targetBranch) { final GitPullRequest pullRequest = new GitPullRequest(); pullRequest.setTitle(title); pullRequest.setDescription(description); pullRequest.setSourceRefName(String.format(TF_REF_FORMATTER, branchNameOnRemoteServer)); pullRequest.setTargetRefName( String.format(TF_REF_FORMATTER, targetBranch.getNameForRemoteOperations())); return pullRequest; }
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); } } }