diff options
author | Kevin Sawicki | 2011-08-04 00:06:57 +0000 |
---|---|---|
committer | Kevin Sawicki | 2011-08-04 00:06:57 +0000 |
commit | 10482115d73c0a675a05bf3a59373e60f83b1f5f (patch) | |
tree | 9d4f4dd64e26ea63a3003808e2ff62176a188627 /org.eclipse.mylyn.github.core/src/org/eclipse | |
parent | 5877fc23dcb98f6eeb4190efc9fe9aeaadd0d47e (diff) | |
download | egit-github-10482115d73c0a675a05bf3a59373e60f83b1f5f.tar.gz egit-github-10482115d73c0a675a05bf3a59373e60f83b1f5f.tar.xz egit-github-10482115d73c0a675a05bf3a59373e60f83b1f5f.zip |
Add summary field that uses text from description.
Previously only the number of files and total size was
shown in the summary attribute. Now either the first line
or the first 80 characters of the first line is shown
following by the file count and size count in parentheses.
Change-Id: Ideb6586fdb08ab7127d4d1c1891179c3dfddda8f
Signed-off-by: Kevin Sawicki <kevin@github.com>
Diffstat (limited to 'org.eclipse.mylyn.github.core/src/org/eclipse')
2 files changed, 35 insertions, 6 deletions
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java index 72dff8d2..0f837584 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java @@ -45,6 +45,11 @@ import org.eclipse.mylyn.tasks.core.data.TaskData; public class GistTaskDataHandler extends GitHubTaskDataHandler { /** + * SUMMARY_LENGTH + */ + public static final int SUMMARY_LENGTH = 80; + + /** * Fill task data with comments * * @param repository @@ -148,13 +153,37 @@ public class GistTaskDataHandler extends GitHubTaskDataHandler { TaskAttribute summary = GistAttribute.SUMMARY.getMetadata() .create(data); - mapper.setValue(summary, generateSummary(fileCount, sizeCount)); + mapper.setValue(summary, + generateSummary(fileCount, sizeCount, gist.getDescription())); return data; } - private String generateSummary(int files, long size) { + private String generateSummary(int files, long size, String description) { StringBuilder summaryText = new StringBuilder(); + if (description != null && description.length() > 0) { + description = description.trim(); + int firstLine = description.indexOf('\n'); + if (firstLine != -1) + description = description.substring(0, firstLine).trim(); + if (description.length() > SUMMARY_LENGTH) { + // Break on last whitespace if maximum length is in the middle + // of a word + if (!Character.isWhitespace(description.charAt(SUMMARY_LENGTH)) + && !Character.isWhitespace(description + .charAt(SUMMARY_LENGTH - 1))) { + int lastWhitespace = description.lastIndexOf(' '); + if (lastWhitespace > 0) + description = description.substring(0, lastWhitespace); + else + description = description.substring(0, SUMMARY_LENGTH); + } else + description = description.substring(0, SUMMARY_LENGTH); + description = description.trim(); + } + if (description.length() > 0) + summaryText.append(description).append(' '); + } if (files != 1) summaryText.append(MessageFormat.format( Messages.GistTaskDataHandler_FilesMultiple, files)); diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/messages.properties b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/messages.properties index e416f05b..4535d1bb 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/messages.properties +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/messages.properties @@ -10,10 +10,10 @@ GistAttribute_LabelNewComment=New Comment GistAttribute_LabelSummary=Summary GistAttribute_LabelUrl=Url GistConnector_LabelConnector=GitHub Gists -GistTaskDataHandler_FilesMultiple={0} files -GistTaskDataHandler_FilesSingle=1 file -GistTaskDataHandler_SizeByte=1 byte -GistTaskDataHandler_SizeBytes=0 bytes +GistTaskDataHandler_FilesMultiple=({0} files +GistTaskDataHandler_FilesSingle=(1 file +GistTaskDataHandler_SizeByte=1 byte) +GistTaskDataHandler_SizeBytes=0 bytes) GistTaskDataHandler_SizeGigabytes=0.00 GB GistTaskDataHandler_SizeKilobytes=0.00 KB GistTaskDataHandler_SizeMegabytes=0.00 MB |