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

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