Skip to content

Commit 6e3b5a6

Browse files
committed
Make notifications more useful
1 parent 9f433d0 commit 6e3b5a6

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

media/github-time.svg

+1
Loading

media/github-user.svg

+1
Loading

src/github.ts

+26-14
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,8 @@ class AlertsRootItem extends GitHubTreeItem {
132132

133133
for (const alert of json) {
134134
if (alert.unread && alert.repository.owner.login === 'openjdk') {
135-
/*
136-
let alert: NotificationInfo = new NotificationInfo(notification.id, notification.subject.title,
137-
notification.repository.full_name, notification.subject.latest_comment_url,
138-
new Date(notification.updated_at));*/
139135
const notInfo = new AlertTreeItem(alert.subject.title, 'alert-' + alert.id,
140-
alert.subject.latest_comment_url, this.onDidChangeTreeDataEmitter);
136+
alert.subject.latest_comment_url, alert.subject.url, new Date(alert.updated_at), alert.repository.full_name, this.onDidChangeTreeDataEmitter);
141137
newAlerts.push(notInfo);
142138
}
143139
}
@@ -151,23 +147,39 @@ class AlertsRootItem extends GitHubTreeItem {
151147
}
152148

153149
class AlertTreeItem extends GitHubTreeItem {
154-
constructor(label: string, id: string, public commentUrl: string,
155-
onDidChangeTreeDataEmitter: vscode.EventEmitter<vscode.TreeItem | undefined>) {
150+
constructor(label: string, id: string, private commentUrl: string, private prUrl: string, private updatedAt: Date,
151+
private repository: string, onDidChangeTreeDataEmitter: vscode.EventEmitter<vscode.TreeItem | undefined>) {
156152
super(label, id, vscode.TreeItemCollapsibleState.Collapsed, false, 'github-item.svg', onDidChangeTreeDataEmitter);
157153
}
158154

159155
protected loadChildrenArrayFromWeb(): Promise<GitHubTreeItem[]> {
160156
return GitHubProvider.getGHjson(this.commentUrl, (comment: any, resolveJson: any, rejectJson: any) => {
161157
const newCommentInfo: GitHubTreeItem[] = [];
162158

163-
newCommentInfo.push(new GitHubLeafTreeItem('User: ' + comment.user.login,
164-
this.commentUrl + '+username', 'github-item.svg', this.onDidChangeTreeDataEmitter));
159+
// Stupid cleaning of html tags; will likely work ok since GitHub does the real work for us
160+
const cleanedComment = comment.body.replace(/<\/?[^>]+(>|$)/g, '').trim();
161+
162+
const prNumber = this.prUrl.split('/').pop();
163+
164+
let localeConf = vscode.workspace.getConfiguration('openjdkDevel').get('locale', '');
165+
let locale;
166+
if (localeConf === '') {
167+
locale = undefined;
168+
} else {
169+
locale = localeConf;
170+
}
171+
172+
newCommentInfo.push(new GitHubLeafTreeItem(cleanedComment,
173+
this.commentUrl + '+comment', 'github-conversation.svg', this.onDidChangeTreeDataEmitter));
174+
175+
newCommentInfo.push(new GitHubLeafTreeItem(comment.user.login,
176+
this.commentUrl + '+username', 'github-user.svg', this.onDidChangeTreeDataEmitter));
165177

166-
newCommentInfo.push(new GitHubLeafTreeItem('Comment: ' + comment.html_url,
167-
this.commentUrl + '+commentUrl', 'github-item.svg', this.onDidChangeTreeDataEmitter));
178+
newCommentInfo.push(new GitHubLeafTreeItem(this.updatedAt.toLocaleString(locale),
179+
this.commentUrl + '+date', 'github-time.svg', this.onDidChangeTreeDataEmitter));
168180

169-
newCommentInfo.push(new GitHubLeafTreeItem('Body: ' + comment.body,
170-
this.commentUrl + '+body', 'github-item.svg', this.onDidChangeTreeDataEmitter));
181+
newCommentInfo.push(new GitHubLeafTreeItem(`${this.repository}#${prNumber}`,
182+
this.commentUrl + '+pr', 'github-pullrequest.svg', this.onDidChangeTreeDataEmitter));
171183

172184
resolveJson(newCommentInfo);
173185
});
@@ -230,7 +242,7 @@ class PRTreeItem extends GitHubTreeItem {
230242
`${repo}#${prNumber} by @${author}`, 'goto' + id, 'github-conversation.svg', onDidChangeTreeDataEmitter
231243
);
232244
this.generated.push(this.convItem);
233-
// diff must be complemented from prUrl
245+
// Diff description must be complemented from prUrl, which can only be done later
234246
this.diffItem = new GitHubLeafTreeItem('Diff', 'diff' + id, 'github-diff.svg', onDidChangeTreeDataEmitter);
235247
this.generated.push(this.diffItem);
236248
if (tags) {

0 commit comments

Comments
 (0)