MCPcopy
hub / github.com/mislav/hub / downloadRelease

Function downloadRelease

commands/release.go:378–424  ·  view source on GitHub ↗
(cmd *Command, args *Args)

Source from the content-addressed store, hash-verified

376}
377
378func downloadRelease(cmd *Command, args *Args) {
379 tagName := ""
380 if args.ParamsSize() > 0 {
381 tagName = args.GetParam(0)
382 }
383 if tagName == "" {
384 utils.Check(cmd.UsageError(""))
385 }
386
387 localRepo, err := github.LocalRepo()
388 utils.Check(err)
389
390 project, err := localRepo.MainProject()
391 utils.Check(err)
392
393 gh := github.NewClient(project.Host)
394
395 release, err := gh.FetchRelease(project, tagName)
396 utils.Check(err)
397
398 hasPattern := args.Flag.HasReceived("--include")
399 found := false
400 for _, asset := range release.Assets {
401 if hasPattern {
402 isMatch, err := filepath.Match(args.Flag.Value("--include"), asset.Name)
403 utils.Check(err)
404 if !isMatch {
405 continue
406 }
407 }
408
409 found = true
410 ui.Printf("Downloading %s ...\n", asset.Name)
411 err := downloadReleaseAsset(asset, gh)
412 utils.Check(err)
413 }
414
415 if !found && hasPattern {
416 names := []string{}
417 for _, asset := range release.Assets {
418 names = append(names, asset.Name)
419 }
420 utils.Check(fmt.Errorf("the `--include` pattern did not match any available assets:\n%s", strings.Join(names, "\n")))
421 }
422
423 args.NoForward()
424}
425
426func downloadReleaseAsset(asset github.ReleaseAsset, gh *github.Client) (err error) {
427 assetReader, err := gh.DownloadReleaseAsset(asset.ApiUrl)

Callers

nothing calls this directly

Calls 14

FetchReleaseMethod · 0.95
CheckFunction · 0.92
LocalRepoFunction · 0.92
NewClientFunction · 0.92
PrintfFunction · 0.92
downloadReleaseAssetFunction · 0.85
ParamsSizeMethod · 0.80
GetParamMethod · 0.80
UsageErrorMethod · 0.80
MainProjectMethod · 0.80
HasReceivedMethod · 0.80
ValueMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…