-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommit.ts
42 lines (38 loc) · 1.37 KB
/
commit.ts
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
export class User {
email: string | undefined = undefined
name: string | undefined = undefined
username: string | undefined = undefined
constructor(data: object) {
type key = keyof typeof data
this.email = data["email" as key]
this.name = data["name" as key]
this.username = data["username" as key]
}
}
export class Commit {
author: User | undefined = undefined
committer: User | undefined = undefined
distinct: boolean | undefined = undefined
hexsha: string | undefined = undefined
timestamp: Date | undefined = undefined
message: string | undefined = undefined
constructor(commit: object, sha = "", timestamp = "") {
type key = keyof typeof commit
this.author = new User(commit["author" as key])
this.committer = new User(commit["committer" as key])
this.distinct = commit["distinct" as key] ?? false
this.hexsha = commit["id" as key] ?? sha
const timestamp_raw = commit["timestamp" as key] ?? timestamp
if (timestamp_raw !== undefined) {
this.timestamp = new Date(timestamp_raw)
}
this.message = commit["message" as key]
}
// return empty string if message is undefined
summary(): string {
if (this.message === undefined) {
return ""
}
return this.message.split("\n", 1)[0]
}
}