MCPcopy Create free account
hub / github.com/bufbuild/buf / run

Function run

cmd/buf/internal/command/push/push.go:216–300  ·  view source on GitHub ↗
(
	ctx context.Context,
	container appext.Container,
	flags *flags,
)

Source from the content-addressed store, hash-verified

214}
215
216func run(
217 ctx context.Context,
218 container appext.Container,
219 flags *flags,
220) (retErr error) {
221 if err := validateFlags(flags); err != nil {
222 return err
223 }
224
225 workspace, err := getBuildableWorkspace(ctx, container, flags)
226 if err != nil {
227 return err
228 }
229
230 uploader, err := bufcli.NewModuleUploader(container)
231 if err != nil {
232 return err
233 }
234
235 var uploadOptions []bufmodule.UploadOption
236 if flags.GitMetadata {
237 gitMetadataUploadOptions, err := getGitMetadataUploadOptions(ctx, container, flags)
238 if err != nil {
239 return err
240 }
241 uploadOptions = append(uploadOptions, gitMetadataUploadOptions...)
242 // Accept any additional labels the user has set using `--label`
243 if len(flags.Labels) > 0 {
244 uploadOptions = append(uploadOptions, bufmodule.UploadWithLabels(xslices.ToUniqueSorted(flags.Labels)...))
245 }
246 } else {
247 // Otherwise, we parse the flags set individually by the user.
248 if labelUploadOption := getLabelUploadOption(flags); labelUploadOption != nil {
249 uploadOptions = append(uploadOptions, labelUploadOption)
250 }
251 }
252 if flags.Create {
253 createModuleVisibility, err := bufmodule.ParseModuleVisibility(flags.CreateVisibility)
254 if err != nil {
255 return err
256 }
257 uploadOptions = append(
258 uploadOptions,
259 bufmodule.UploadWithCreateIfNotExist(createModuleVisibility, flags.CreateDefaultLabel),
260 )
261 }
262 if flags.SourceControlURL != "" {
263 uploadOptions = append(uploadOptions, bufmodule.UploadWithSourceControlURL(flags.SourceControlURL))
264 }
265 if flags.ExcludeUnnamed {
266 uploadOptions = append(uploadOptions, bufmodule.UploadWithExcludeUnnamed())
267 }
268
269 commits, err := uploader.Upload(ctx, workspace, uploadOptions...)
270 if err != nil {
271 return err
272 }
273 if len(commits) == 0 {

Callers 1

NewCommandFunction · 0.70

Calls 15

NewModuleUploaderFunction · 0.92
UploadWithLabelsFunction · 0.92
ParseModuleVisibilityFunction · 0.92
UploadWithExcludeUnnamedFunction · 0.92
NewfFunction · 0.92
ToDashlessFunction · 0.92
getBuildableWorkspaceFunction · 0.85
getLabelUploadOptionFunction · 0.85
validateFlagsFunction · 0.70

Tested by

no test coverage detected