-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjquery.github-activity.js
More file actions
170 lines (139 loc) · 4.69 KB
/
jquery.github-activity.js
File metadata and controls
170 lines (139 loc) · 4.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
var githubURL = 'https://github.com/'
function userLink(user) {
return $('<a>', {
text: user.login,
href: githubURL + user.login
})
}
function repositoryLink(repo) {
return $('<a>', {
text: repo.name,
href: githubURL + repo.full_name
})
}
function branchName(ref) {
return ref.split('refs/heads/')[1]
}
function issueLink(issue) {
return $('<a>', {
text: 'issue ' + issue.number,
href: issue.html_url
})
}
function pullRequestLink(pull_request, comment) {
var url = pull_request.html_url
if(typeof comment !== 'undefined') {
url += '#issuecomment-' + comment.id
}
return $('<a>', {
text: 'pull request ' + pull_request.number,
href: url
})
}
function tag(payload) {
return $('<b>', {
text: payload.ref,
})
}
function releaseName(release) {
return $('<a>', {
text: release.name,
href: release.html_url
})
}
function createEventAction(event) {
if(event.payload.ref_type != 'tag')
return 'created respository ' + repositoryLink(event.repo).prop('outerHTML')
else
return 'created tag ' + tag(event.payload).prop('outerHTML') + ' in ' + repositoryLink(event.repo).prop('outerHTML')
}
function followEventAction(event) {
return 'started following ' + userLink(event.payload.target).prop('outerHTML')
}
function watchEventAction(event) {
return event.payload.action + ' watching ' + repositoryLink(event.repo).prop('outerHTML')
}
function pushEventAction(event) {
return 'pushed to ' + branchName(event.payload.ref) + ' at ' + repositoryLink(event.repo).prop('outerHTML')
}
function issueCommentEventAction(event) {
return 'commented on ' + issueLink(event.payload.issue, event.payload.comment).prop('outerHTML') + ' on ' + repositoryLink(event.repo).prop('outerHTML')
}
function pullRequestEventAction(event) {
return 'opened ' + pullRequestLink(event.payload.pull_request).prop('outerHTML') + ' on ' + repositoryLink(event.repo).prop('outerHTML')
}
function deleteEventAction(event) {
return 'deleted ' + event.payload.ref_type + ' ' + event.payload.ref + ' at ' + repositoryLink(event.repo).prop('outerHTML')
}
function commitCommentEventAction(event) {
return 'commented on ' + repositoryLink(event.repo).prop('outerHTML')
}
function issueEventAction(event) {
return event.payload.action + issueLink(event.payload.issue).prop('outerHTML') + ' on ' + repositoryLink(event.repo).prop('outerHTML')
}
function forkEventAction(event) {
return 'forked ' + repositoryLink(event.repo).prop('outerHTML')
}
function releaseEventAction(event) {
return 'created release ' + releaseName(event.payload.release).prop('outerHTML') + ' on ' + repositoryLink(event.repo).prop('outerHTML')
}
function gollumEventAction(event) {
return 'updated wiki of repository ' + repositoryLink(event.repository).prop('outerHTML')
}
function memberEventAction(event) {
return event.action + ' ' + userLink(event.member) + ' to ' + repositoryLink(event.repository)
}
function publicEventAction(event) {
return 'set the repository ' + repositoryLink(event.repository).prop('outerHTML') + ' public'
}
function addEventAction(event) {
}
(function($) {
$.fn.githubActivityFor = function(username, params) {
var githubURL = 'https://github.com/'
var params = params || {}
if('wrap' in params == false) {
params['wrap'] = function(item) { return item }
}
var renderer = {
'CreateEvent': function(event) {
if(event.payload.ref_type != 'tag')
return 'created respository ' + repositoryLink(event.repo).prop('outerHTML')
else
return 'created tag ' + tag(event.payload).prop('outerHTML') + ' in ' + repositoryLink(event.repo).prop('outerHTML')
},
'FollowEvent': followEventAction,
'WatchEvent': watchEventAction,
'PushEvent': pushEventAction,
'IssueCommentEvent': issueCommentEventAction,
'PullRequestEvent': pullRequestEventAction,
'DeleteEvent': deleteEventAction,
'CommitCommentEvent': commitCommentEventAction,
'IssuesEvent': issueEventAction,
'ForkEvent': forkEventAction,
'ReleaseEvent': releaseEventAction,
'GollumEvent': gollumEventAction,
'MemberEvent': memberEventAction,
'PublicEvent': publicEventAction
}
this.each(function() {
var el = $(this)
$.get('https://api.github.com/users/' + username + '/events?callback=?', function(activity) {
$.each(activity.data, function(index, event) {
if('limit' in params && index == params['limit']) {
return false
}
if(event.type in renderer) {
el.append(params.wrap($('<li>', {
html: userLink(event.actor).prop('outerHTML') + ' ' + renderer[event.type](event) + ' ' + jQuery.timeago(new Date(event.created_at))
})))
}
else {
console.log('No renderer for ' + event.type + ' implemented.')
console.log(event)
}
})
}, "json")
})
}
})(jQuery)