-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathgithub.js
87 lines (83 loc) · 2.39 KB
/
github.js
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
module.exports.Repo = class Repo {
constructor (owner, repo = {}) {
this.owner = owner
this.name = repo.name
this.url = repo.url
this.description = repo.description
this.created = repo.createdAt
this.updated = repo.updatedAt
this.pushed = repo.pushedAt
this.stars = repo.stargazers.totalCount
this.watchers = repo.watchers.totalCount
this.forks = repo.forks.totalCount
this.openIssues = repo.issues.totalCount
this.license = repo.licenseInfo && (repo.licenseInfo.spdx_id || repo.licenseInfo.name)
this.language = repo.primaryLanguage ? repo.primaryLanguage.name : repo.primaryLanguage
this.homepage = repo.homepageUrl
}
}
module.exports.Issue = class Issue {
constructor (owner, repo, issue = {}) {
this.owner = owner
this.repo = repo
this.number = issue.number
this.isPullRequest = !!(issue.__typename === 'PullRequest')
this.url = issue.url
this.state = issue.state
this.title = issue.title
this.description = issue.bodyText
this.createdAt = issue.createdAt
this.updatedAt = issue.updatedAt
this.closedAt = issue.closedAt
this.mergedAt = issue.mergedAt
this.labels = issue.labels.nodes.map((l) => {
return {
name: l.name,
color: l.color
}
})
let assignee = issue.assignees.nodes[0]
if (!assignee) {
assignee = null
}
this.assignee = assignee
this.author = issue.author && {
login: issue.author.login,
avatarUrl: issue.author.avatarUrl,
url: issue.author.url
}
}
}
module.exports.Activity = class Activity {
constructor (owner, repo, activity = {}) {
this.owner = owner
this.repo = repo
this.id = activity.id
this.type = activity.type
this.createdAt = activity.created_at
this.actor = activity.actor && {
login: activity.actor.login,
avatarUrl: activity.actor.avatar_url,
url: activity.actor.url
}
this.payload = activity.payload
}
}
module.exports.Commit = class Commit {
constructor (owner, repo, commit = {}) {
this.owner = owner
this.repo = repo
this.nodeId = commit.id
this.sha = commit.oid
this.message = commit.message
this.url = commit.url
this.date = new Date(commit.authoredDate)
let author = commit.author.user || commit.committer
if (!author) {
author = {
login: commit.author.email
}
}
this.author = author
}
}