@@ -26,30 +26,28 @@ var osMap = map[string]string{
2626
2727type RepoRegistry interface {
2828 GetLatestReleaseInfo (ctx context.Context ) (* ReleaseInfo , error )
29- GetLatestRelease () (string , error )
30- DownloadReleaseBinary (packageName string , version string , dstPath string ) error
29+ GetLatestRelease (ctx context. Context ) (string , error )
30+ DownloadReleaseBinary (ctx context. Context , packageName string , version string , dstPath string ) error
3131 GetPackageName (os string , arch string ) (string , error )
3232 GetDownloadURL (repoURI string , packageName string , version string ) string
3333}
3434
3535type GithubRegistry struct {
3636 client * http.Client
37- ctx context.Context
3837 repoURI string
3938 apiURI string
4039 downloadURL string
4140 downloadPackageTimeout time.Duration
4241 latestReleaseTimeout time.Duration
4342}
4443
45- func NewGithubRegistry (ctx context. Context ) * GithubRegistry {
44+ func NewGithubRegistry () * GithubRegistry {
4645 client := & http.Client {
4746 Timeout : 15 * 60 * time .Second , // global timeout
4847 }
4948
5049 reg := & GithubRegistry {
5150 client : client ,
52- ctx : ctx ,
5351 repoURI : "https://github.com/lets-cli/lets" ,
5452 apiURI : "https://api.github.com/repos/lets-cli/lets" ,
5553 downloadURL : "" ,
@@ -76,13 +74,14 @@ func (reg *GithubRegistry) GetPackageName(os string, arch string) (string, error
7674}
7775
7876func (reg * GithubRegistry ) DownloadReleaseBinary (
77+ ctx context.Context ,
7978 packageName string ,
8079 version string ,
8180 dstPath string ,
8281) error {
8382 downloadURL := reg .GetDownloadURL (reg .repoURI , packageName + ".tar.gz" , version )
8483
85- ctx , cancel := context .WithTimeout (reg . ctx , reg .downloadPackageTimeout )
84+ ctx , cancel := context .WithTimeout (ctx , reg .downloadPackageTimeout )
8685 defer cancel ()
8786
8887 req , err := http .NewRequestWithContext (
@@ -128,7 +127,7 @@ func (reg *GithubRegistry) DownloadReleaseBinary(
128127
129128 // TODO add download progress bar
130129 // TODO drop extract dependency, replace with own code
131- err = extract .Gz (reg . ctx , resp .Body , dstDir , nil )
130+ err = extract .Gz (ctx , resp .Body , dstDir , nil )
132131 if err != nil {
133132 return fmt .Errorf ("failed to extract package: %w" , err )
134133 }
@@ -147,8 +146,8 @@ type ReleaseInfo struct {
147146 PublishedAt time.Time `json:"published_at"`
148147}
149148
150- func (reg * GithubRegistry ) GetLatestRelease () (string , error ) {
151- release , err := reg .GetLatestReleaseInfo (reg . ctx )
149+ func (reg * GithubRegistry ) GetLatestRelease (ctx context. Context ) (string , error ) {
150+ release , err := reg .GetLatestReleaseInfo (ctx )
152151 if err != nil {
153152 return "" , err
154153 }
@@ -157,12 +156,7 @@ func (reg *GithubRegistry) GetLatestRelease() (string, error) {
157156}
158157
159158func (reg * GithubRegistry ) GetLatestReleaseInfo (ctx context.Context ) (* ReleaseInfo , error ) {
160- requestCtx := reg .ctx
161- if ctx != nil {
162- requestCtx = ctx
163- }
164-
165- requestCtx , cancel := context .WithTimeout (requestCtx , reg .latestReleaseTimeout )
159+ requestCtx , cancel := context .WithTimeout (ctx , reg .latestReleaseTimeout )
166160 defer cancel ()
167161
168162 url := reg .apiURI + "/releases/latest"
0 commit comments