MCPcopy Create free account
hub / github.com/cli/cli / uploadRun

Function uploadRun

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

Source from the content-addressed store, hash-verified

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

Callers 1

NewCmdUploadFunction · 0.85

Calls 13

FetchReleaseFunction · 0.92
NewImmutableSafeURLFunction · 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
RepoHostMethod · 0.65

Tested by

no test coverage detected