-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathgithub_release.go
111 lines (91 loc) · 2.03 KB
/
github_release.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
package selfupdate
import (
"time"
"github.com/google/go-github/v30/github"
)
type GitHubRelease struct {
releaseID int64
name string
tagName string
url string
draft bool
prerelease bool
publishedAt time.Time
releaseNotes string
assets []SourceAsset
}
func NewGitHubRelease(from *github.RepositoryRelease) *GitHubRelease {
release := &GitHubRelease{
releaseID: from.GetID(),
name: from.GetName(),
tagName: from.GetTagName(),
url: from.GetHTMLURL(),
publishedAt: from.GetPublishedAt().Time,
releaseNotes: from.GetBody(),
draft: from.GetDraft(),
prerelease: from.GetPrerelease(),
assets: make([]SourceAsset, len(from.Assets)),
}
for i, fromAsset := range from.Assets {
release.assets[i] = NewGitHubAsset(fromAsset)
}
return release
}
func (a *GitHubRelease) GetID() int64 {
return a.releaseID
}
func (r *GitHubRelease) GetTagName() string {
return r.tagName
}
func (r *GitHubRelease) GetDraft() bool {
return r.draft
}
func (r *GitHubRelease) GetPrerelease() bool {
return r.prerelease
}
func (r *GitHubRelease) GetPublishedAt() time.Time {
return r.publishedAt
}
func (r *GitHubRelease) GetReleaseNotes() string {
return r.releaseNotes
}
func (r *GitHubRelease) GetName() string {
return r.name
}
func (r *GitHubRelease) GetURL() string {
return r.url
}
func (r *GitHubRelease) GetAssets() []SourceAsset {
return r.assets
}
type GitHubAsset struct {
id int64
name string
size int
url string
}
func NewGitHubAsset(from *github.ReleaseAsset) *GitHubAsset {
return &GitHubAsset{
id: from.GetID(),
name: from.GetName(),
size: from.GetSize(),
url: from.GetBrowserDownloadURL(),
}
}
func (a *GitHubAsset) GetID() int64 {
return a.id
}
func (a *GitHubAsset) GetName() string {
return a.name
}
func (a *GitHubAsset) GetSize() int {
return a.size
}
func (a *GitHubAsset) GetBrowserDownloadURL() string {
return a.url
}
// Verify interface
var (
_ SourceRelease = &GitHubRelease{}
_ SourceAsset = &GitHubAsset{}
)