MCPcopy
hub / github.com/cli/cli / uploadRun

Function uploadRun

pkg/cmd/release/upload/upload.go:77–129  ·  view source on GitHub ↗
(opts *UploadOptions)

Source from the content-addressed store, hash-verified

75}
76
77func uploadRun(opts *UploadOptions) error {
78 httpClient, err := opts.HttpClient()
79 if err != nil {
80 return err
81 }
82
83 baseRepo, err := opts.BaseRepo()
84 if err != nil {
85 return err
86 }
87
88 release, err := shared.FetchRelease(context.Background(), httpClient, baseRepo, opts.TagName)
89 if err != nil {
90 return err
91 }
92
93 uploadURL := release.UploadURL
94 if idx := strings.IndexRune(uploadURL, '{'); idx > 0 {
95 uploadURL = uploadURL[:idx]
96 }
97
98 var existingNames []string
99 for _, a := range opts.Assets {
100 sanitizedFileName := sanitizeFileName(a.Name)
101 for _, ea := range release.Assets {
102 if ea.Name == sanitizedFileName {
103 a.ExistingURL = ea.APIURL
104 existingNames = append(existingNames, ea.Name)
105 break
106 }
107 }
108 }
109
110 if len(existingNames) > 0 && !opts.OverwriteExisting {
111 return fmt.Errorf("asset under the same name already exists: %v", existingNames)
112 }
113
114 opts.IO.StartProgressIndicator()
115 err = shared.ConcurrentUpload(httpClient, uploadURL, opts.Concurrency, opts.Assets)
116 opts.IO.StopProgressIndicator()
117 if err != nil {
118 return err
119 }
120
121 if opts.IO.IsStdoutTTY() {
122 iofmt := opts.IO.ColorScheme()
123 fmt.Fprintf(opts.IO.Out, "Successfully uploaded %s to %s\n",
124 text.Pluralize(len(opts.Assets), "asset"),
125 iofmt.Bold(release.TagName))
126 }
127
128 return nil
129}
130
131// this method attempts to mimic the same functionality on the client that the platform does on
132// uploaded assets in order to allow the --clobber logic work correctly, since that feature is

Callers 1

NewCmdUploadFunction · 0.85

Calls 11

FetchReleaseFunction · 0.92
ConcurrentUploadFunction · 0.92
PluralizeFunction · 0.92
sanitizeFileNameFunction · 0.85
IsStdoutTTYMethod · 0.80
ColorSchemeMethod · 0.80
BoldMethod · 0.80
BaseRepoMethod · 0.65
ErrorfMethod · 0.65
StopProgressIndicatorMethod · 0.65

Tested by

no test coverage detected