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

     1  package selfupdate
     2  
     3  import (
     4  	"time"
     5  
     6  	"code.gitea.io/sdk/gitea"
     7  )
     8  
     9  type GiteaRelease 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 NewGiteaRelease(from *gitea.Release) *GiteaRelease {
    22  	release := &GiteaRelease{
    23  		releaseID:    from.ID,
    24  		name:         from.Title,
    25  		tagName:      from.TagName,
    26  		url:          "", //FIXME: we kind of have no url ?
    27  		publishedAt:  from.PublishedAt,
    28  		releaseNotes: from.Note,
    29  		draft:        from.IsDraft,
    30  		prerelease:   from.IsPrerelease,
    31  		assets:       make([]SourceAsset, len(from.Attachments)),
    32  	}
    33  
    34  	for i, fromAsset := range from.Attachments {
    35  		release.assets[i] = NewGiteaAsset(fromAsset)
    36  	}
    37  
    38  	return release
    39  }
    40  
    41  func (r *GiteaRelease) GetID() int64 {
    42  	return r.releaseID
    43  }
    44  
    45  func (r *GiteaRelease) GetTagName() string {
    46  	return r.tagName
    47  }
    48  
    49  func (r *GiteaRelease) GetDraft() bool {
    50  	return r.draft
    51  }
    52  
    53  func (r *GiteaRelease) GetPrerelease() bool {
    54  	return r.prerelease
    55  }
    56  
    57  func (r *GiteaRelease) GetPublishedAt() time.Time {
    58  	return r.publishedAt
    59  }
    60  
    61  func (r *GiteaRelease) GetReleaseNotes() string {
    62  	return r.releaseNotes
    63  }
    64  
    65  func (r *GiteaRelease) GetName() string {
    66  	return r.name
    67  }
    68  
    69  func (r *GiteaRelease) GetURL() string {
    70  	return r.url
    71  }
    72  
    73  func (r *GiteaRelease) GetAssets() []SourceAsset {
    74  	return r.assets
    75  }
    76  
    77  type GiteaAsset struct {
    78  	id   int64
    79  	name string
    80  	size int
    81  	url  string
    82  }
    83  
    84  func NewGiteaAsset(from *gitea.Attachment) *GiteaAsset {
    85  	return &GiteaAsset{
    86  		id:   from.ID,
    87  		name: from.Name,
    88  		size: int(from.Size),
    89  		url:  from.DownloadURL,
    90  	}
    91  }
    92  
    93  func (a *GiteaAsset) GetID() int64 {
    94  	return a.id
    95  }
    96  
    97  func (a *GiteaAsset) GetName() string {
    98  	return a.name
    99  }
   100  
   101  func (a *GiteaAsset) GetSize() int {
   102  	return a.size
   103  }
   104  
   105  func (a *GiteaAsset) GetBrowserDownloadURL() string {
   106  	return a.url
   107  }
   108  
   109  // Verify interface
   110  var (
   111  	_ SourceRelease = &GiteaRelease{}
   112  	_ SourceAsset   = &GiteaAsset{}
   113  )