in org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java [232:284]
public RepositoryResponse postTaskData(TaskRepository repository,
TaskData taskData, Set<TaskAttribute> oldAttributes,
IProgressMonitor monitor) throws CoreException {
RepositoryResponse response = null;
Gist gist = new Gist();
GitHubClient client = GistConnector.createClient(repository);
AuthenticationCredentials credentials = repository
.getCredentials(AuthenticationType.REPOSITORY);
if (credentials != null) {
if (Boolean.parseBoolean(
repository.getProperty(GitHub.PROPERTY_USE_TOKEN))) {
client.setOAuth2Token(credentials.getPassword());
} else {
client.setCredentials(credentials.getUserName(),
credentials.getPassword());
}
gist.setOwner(new User().setLogin(credentials.getUserName()));
}
GistService service = new GistService(client);
TaskAttribute root = taskData.getRoot();
gist.setId(taskData.getTaskId());
gist.setDescription(root.getAttribute(
GistAttribute.DESCRIPTION.getMetadata().getId()).getValue());
if (taskData.isNew()) {
try {
gist = service.createGist(gist);
} catch (IOException e) {
throw new CoreException(GitHub.createWrappedStatus(e));
}
response = new RepositoryResponse(ResponseKind.TASK_CREATED,
gist.getId());
} else {
try {
String newComment = root.getAttribute(
GistAttribute.COMMENT_NEW.getMetadata().getId())
.getValue();
if (newComment.length() > 0)
service.createComment(taskData.getTaskId(), newComment);
String author = GistAttribute.AUTHOR.getMetadata().getValue(
taskData);
if (isOwner(repository, author))
service.updateGist(gist);
} catch (IOException e) {
throw new CoreException(GitHub.createWrappedStatus(e));
}
response = new RepositoryResponse(ResponseKind.TASK_UPDATED,
taskData.getTaskId());
}
return response;
}