forked from harness/harness
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commit.go
120 lines (104 loc) · 4.2 KB
/
commit.go
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
package model
import (
"fmt"
"time"
)
type Commit struct {
ID int64 `meddler:"id,pk" json:"id"`
RepoID int64 `meddler:"repo_id" json:"-"`
Status string `meddler:"status" json:"status"`
Started time.Time `meddler:"started,utctime" json:"started"`
Finished time.Time `meddler:"finished,utctime" json:"finished"`
Duration int64 `meddler:"duration" json:"duration"`
Hash string `meddler:"hash" json:"hash"`
Branch string `meddler:"branch" json:"branch"`
PullRequest string `meddler:"pull_request" json:"pull_request"`
Author string `meddler:"author" json:"author"`
Gravatar string `meddler:"gravatar" json:"gravatar"`
Timestamp string `meddler:"timestamp" json:"timestamp"`
Message string `meddler:"message" json:"message"`
Created time.Time `meddler:"created,utctime" json:"created"`
Updated time.Time `meddler:"updated,utctime" json:"updated"`
}
// Returns the Short (--short) Commit Hash.
func (c *Commit) HashShort() string {
if len(c.Hash) > 6 {
return c.Hash[:6]
} else {
return c.Hash
}
}
// Returns the Gravatar Image URL.
func (c *Commit) Image() string { return fmt.Sprintf(GravatarPattern, c.Gravatar, 58) }
func (c *Commit) ImageSmall() string { return fmt.Sprintf(GravatarPattern, c.Gravatar, 32) }
func (c *Commit) ImageLarge() string { return fmt.Sprintf(GravatarPattern, c.Gravatar, 160) }
// Returns the Started Date as an ISO8601
// formatted string.
func (c *Commit) StartedString() string {
return c.Started.Format("2006-01-02T15:04:05Z")
}
// Returns the Created Date as an ISO8601
// formatted string.
func (c *Commit) CreatedString() string {
return c.Created.Format("2006-01-02T15:04:05Z")
}
// Returns the Started Date as an ISO8601
// formatted string.
func (c *Commit) FinishedString() string {
return c.Finished.Format("2006-01-02T15:04:05Z")
}
// Set the Author's email address and calculate the
// Gravatar hash.
func (c *Commit) SetAuthor(email string) {
c.Author = email
c.Gravatar = createGravatar(email)
}
// Combined Repository and Commit details
type RepoCommit struct {
// Repo Details
Slug string `meddler:"slug" json:"slug"`
Host string `meddler:"host" json:"host"`
Owner string `meddler:"owner" json:"owner"`
Name string `meddler:"name" json:"name"`
// Commit Details
Status string `meddler:"status" json:"status"`
Started time.Time `meddler:"started,utctime" json:"started"`
Finished time.Time `meddler:"finished,utctime" json:"finished"`
Duration int64 `meddler:"duration" json:"duration"`
Hash string `meddler:"hash" json:"hash"`
Branch string `meddler:"branch" json:"branch"`
PullRequest string `meddler:"pull_request" json:"pull_request"`
Author string `meddler:"author" json:"author"`
Gravatar string `meddler:"gravatar" json:"gravatar"`
Timestamp string `meddler:"timestamp" json:"timestamp"`
Message string `meddler:"message" json:"message"`
Created time.Time `meddler:"created,utctime" json:"created"`
Updated time.Time `meddler:"updated,utctime" json:"updated"`
}
// Returns the Short (--short) Commit Hash.
func (c *RepoCommit) HashShort() string {
if len(c.Hash) > 6 {
return c.Hash[:6]
} else {
return c.Hash
}
}
// Returns the Gravatar Image URL.
func (c *RepoCommit) Image() string { return fmt.Sprintf(GravatarPattern, c.Gravatar, 42) }
func (c *RepoCommit) ImageSmall() string { return fmt.Sprintf(GravatarPattern, c.Gravatar, 32) }
func (c *RepoCommit) ImageLarge() string { return fmt.Sprintf(GravatarPattern, c.Gravatar, 160) }
// Returns the Started Date as an ISO8601
// formatted string.
func (c *RepoCommit) StartedString() string {
return c.Started.Format("2006-01-02T15:04:05Z")
}
// Returns the Created Date as an ISO8601
// formatted string.
func (c *RepoCommit) CreatedString() string {
return c.Created.Format("2006-01-02T15:04:05Z")
}
// Returns the Started Date as an ISO8601
// formatted string.
func (c *RepoCommit) FinishedString() string {
return c.Finished.Format("2006-01-02T15:04:05Z")
}