github.com/creativeprojects/go-selfupdate@v1.2.0/github_release.go (about)

     1  package selfupdate
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/google/go-github/v30/github"
     7  )
     8  
     9  type GitHubRelease struct {
    10  	releaseID    int64
    11  	name         string
    12  	tagName      string
    13  	url          string
    14  	draft        bool
    15  	prerelease   bool
    16  	publishedAt  time.Time
    17  	releaseNotes string
    18  	assets       []SourceAsset
    19  }
    20  
    21  func NewGitHubRelease(from *github.RepositoryRelease) *GitHubRelease {
    22  	release := &GitHubRelease{
    23  		releaseID:    from.GetID(),
    24  		name:         from.GetName(),
    25  		tagName:      from.GetTagName(),
    26  		url:          from.GetHTMLURL(),
    27  		publishedAt:  from.GetPublishedAt().Time,
    28  		releaseNotes: from.GetBody(),
    29  		draft:        from.GetDraft(),
    30  		prerelease:   from.GetPrerelease(),
    31  		assets:       make([]SourceAsset, len(from.Assets)),
    32  	}
    33  	for i, fromAsset := range from.Assets {
    34  		release.assets[i] = NewGitHubAsset(fromAsset)
    35  	}
    36  	return release
    37  }
    38  
    39  func (a *GitHubRelease) GetID() int64 {
    40  	return a.releaseID
    41  }
    42  
    43  func (r *GitHubRelease) GetTagName() string {
    44  	return r.tagName
    45  }
    46  
    47  func (r *GitHubRelease) GetDraft() bool {
    48  	return r.draft
    49  }
    50  
    51  func (r *GitHubRelease) GetPrerelease() bool {
    52  	return r.prerelease
    53  }
    54  
    55  func (r *GitHubRelease) GetPublishedAt() time.Time {
    56  	return r.publishedAt
    57  }
    58  
    59  func (r *GitHubRelease) GetReleaseNotes() string {
    60  	return r.releaseNotes
    61  }
    62  
    63  func (r *GitHubRelease) GetName() string {
    64  	return r.name
    65  }
    66  
    67  func (r *GitHubRelease) GetURL() string {
    68  	return r.url
    69  }
    70  
    71  func (r *GitHubRelease) GetAssets() []SourceAsset {
    72  	return r.assets
    73  }
    74  
    75  type GitHubAsset struct {
    76  	id   int64
    77  	name string
    78  	size int
    79  	url  string
    80  }
    81  
    82  func NewGitHubAsset(from *github.ReleaseAsset) *GitHubAsset {
    83  	return &GitHubAsset{
    84  		id:   from.GetID(),
    85  		name: from.GetName(),
    86  		size: from.GetSize(),
    87  		url:  from.GetBrowserDownloadURL(),
    88  	}
    89  }
    90  
    91  func (a *GitHubAsset) GetID() int64 {
    92  	return a.id
    93  }
    94  
    95  func (a *GitHubAsset) GetName() string {
    96  	return a.name
    97  }
    98  
    99  func (a *GitHubAsset) GetSize() int {
   100  	return a.size
   101  }
   102  
   103  func (a *GitHubAsset) GetBrowserDownloadURL() string {
   104  	return a.url
   105  }
   106  
   107  // Verify interface
   108  var (
   109  	_ SourceRelease = &GitHubRelease{}
   110  	_ SourceAsset   = &GitHubAsset{}
   111  )