public RepositoryResponse postTaskData()

in org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/pr/PullRequestTaskDataHandler.java [187:234]


	public RepositoryResponse postTaskData(TaskRepository repository,
			TaskData taskData, Set<TaskAttribute> oldAttributes,
			IProgressMonitor monitor) throws CoreException {
		String taskId = taskData.getTaskId();
		PullRequest pr = createPullRequest(taskData);
		RepositoryId repo = PullRequestConnector.getRepository(repository
				.getRepositoryUrl());
		try {
			GitHubClient client = IssueConnector.createClient(repository);
			boolean collaborator = isCollaborator(client, repo);
			PullRequestService prService = new PullRequestService(client);
			IssueService issueService = new IssueService(client);
			if (taskData.isNew()) {
				pr.setState(IssueService.STATE_OPEN);
				pr = prService.createPullRequest(repo, pr);
				taskId = Integer.toString(pr.getNumber());
			} else {
				// Handle new comment
				String comment = getAttributeValue(taskData,
						PullRequestAttribute.COMMENT_NEW.getMetadata());
				if (comment != null && comment.length() > 0)
					issueService.createComment(repo.getOwner(), repo.getName(),
							taskId, comment);

				boolean reporter = attributeMatchesUser(client,
						PullRequestAttribute.REPORTER.getMetadata(), taskData);
				if (collaborator || reporter) {
					// Handle state change
					TaskAttribute operationAttribute = taskData.getRoot()
							.getAttribute(TaskAttribute.OPERATION);
					if (operationAttribute != null) {
						PullRequestOperation operation = PullRequestOperation
								.fromId(operationAttribute.getValue());
						if (operation == PullRequestOperation.REOPEN)
							pr.setState(IssueService.STATE_OPEN);
						else if (operation == PullRequestOperation.CLOSE)
							pr.setState(IssueService.STATE_CLOSED);
					}
					prService.editPullRequest(repo, pr);
				}
			}
			return new RepositoryResponse(
					taskData.isNew() ? ResponseKind.TASK_CREATED
							: ResponseKind.TASK_UPDATED, taskId);
		} catch (IOException e) {
			throw new CoreException(GitHub.createWrappedStatus(e));
		}
	}