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

Function createRun

pkg/cmd/event/subscription/create/create.go:84–126  ·  view source on GitHub ↗
(ctx context.Context, opts *CreateOptions)

Source from the content-addressed store, hash-verified

82}
83
84func createRun(ctx context.Context, opts *CreateOptions) error {
85 cfg, err := opts.Config()
86 if err != nil {
87 return err
88 }
89 host, _ := cfg.Authentication().DefaultHost()
90
91 c, err := opts.EventClient(shared.ResourceHost(opts.Resource, host))
92 if err != nil {
93 return err
94 }
95
96 opts.IO.StartProgressIndicator()
97 sub, created, err := c.CreateSubscription(ctx, opts.Resource, shared.NormalizeEventTypes(opts.Events))
98 opts.IO.StopProgressIndicator()
99 if err != nil {
100 if errors.Is(err, client.ErrResourceNotFound) {
101 return fmt.Errorf("could not subscribe to %s; the resource was not found, or you cannot access it: %w",
102 opts.Resource, err)
103 }
104 return shared.SubscriptionLimitError(fmt.Errorf("failed to create subscription: %w", err))
105 }
106
107 if opts.Exporter != nil {
108 return opts.Exporter.Write(opts.IO, sub)
109 }
110
111 if _, err := fmt.Fprintln(opts.IO.Out, sub.ID); err != nil {
112 return err
113 }
114
115 if !opts.IO.IsStderrTTY() {
116 return nil
117 }
118 action := "Created subscription"
119 if !created {
120 action = "Reused existing subscription"
121 }
122 cs := opts.IO.ColorScheme()
123 _, err = fmt.Fprintf(opts.IO.ErrOut, "%s %s %s, which expires %s\n",
124 cs.SuccessIcon(), action, cs.Bold(sub.ID), text.FuzzyIn(opts.Now(), sub.ExpiresAt))
125 return err
126}

Callers 3

TestCreateRunFunction · 0.70
NewCmdCreateFunction · 0.70

Calls 15

ResourceHostFunction · 0.92
NormalizeEventTypesFunction · 0.92
SubscriptionLimitErrorFunction · 0.92
FuzzyInFunction · 0.92
IsStderrTTYMethod · 0.80
ColorSchemeMethod · 0.80
SuccessIconMethod · 0.80
BoldMethod · 0.80
ConfigMethod · 0.65
DefaultHostMethod · 0.65
AuthenticationMethod · 0.65

Tested by 2

TestCreateRunFunction · 0.56