GitLabgitlab-org
cli
main
1// Package cancel implements `glab autoflow workflow cancel`.
2package cancel
4import (
5 "context"
6 "fmt"
8 "github.com/MakeNowJust/heredoc/v2"
9 "github.com/spf13/cobra"
10 autoflowrpcv1 "gitlab.com/gitlab-org/protos/gen/go/gitlab/autoflow/rpc/v1"
12 "gitlab.com/gitlab-org/cli/internal/api"
13 "gitlab.com/gitlab-org/cli/internal/cmdutils"
14 "gitlab.com/gitlab-org/cli/internal/commands/autoflow/autoflowutils"
15 "gitlab.com/gitlab-org/cli/internal/iostreams"
16 "gitlab.com/gitlab-org/cli/internal/mcpannotations"
17 "gitlab.com/gitlab-org/cli/internal/text"
18)
20type options struct {
21 io *iostreams.IOStreams
22 apiClient func(repoHost string) (*api.Client, error)
24 conn autoflowutils.Connection
25 workflowToken *cmdutils.SecretFile
26 wait autoflowutils.Wait
28 workflowKey string
29}
31// NewCmd returns the `glab autoflow workflow cancel` command.
32func NewCmd(f cmdutils.Factory) *cobra.Command {
33 opts := &options{
34 io: f.IO(),
35 apiClient: f.ApiClient,
36 }
38 cmd := &cobra.Command{
39 Use: "cancel <workflow-key>",
40 Short: "Cancel an AutoFlow workflow. (EXPERIMENTAL)",
41 Long: heredoc.Docf(`
42 Request the cancellation of a workflow on the AutoFlow service of GitLab Relay. The cancellation is asynchronous: the command returns once AutoFlow accepted the request.
44 The command needs the workflow token that %[1]sglab autoflow workflow start%[1]s printed. Pass it in a file with %[1]s--workflow-token-file%[1]s or in its environment variable.
46 With %[1]s--wait%[1]s, the command polls until the workflow has finished and exits with an error unless it ended canceled. A workflow that finished before the cancellation reached it keeps its state.
47 `, "`") + text.ExperimentalString,
48 Example: heredoc.Doc(`
49 # Cancel a workflow on Runway staging and wait until it is canceled
50 glab autoflow workflow cancel "$WORKFLOW_KEY" --hostname staging.gitlab.com \
51 --address staging.autoflow-gke.svc.gitlab.net:443 \
52 --workflow-token-file workflow-token.txt --wait
53 `),
54 Args: cobra.ExactArgs(1),
55 ValidArgsFunction: cobra.NoFileCompletions,
56 Annotations: map[string]string{
57 mcpannotations.Exclude: "true",
58 },
59 RunE: func(cmd *cobra.Command, args []string) error {
60 if err := opts.complete(args); err != nil {
61 return err
62 }
63 if err := opts.validate(); err != nil {
64 return err
65 }
66 return opts.run(cmd.Context())
67 },
68 }
70 opts.conn.AddFlags(cmd)
71 opts.workflowToken = autoflowutils.NewWorkflowTokenFlag(cmd)
72 opts.wait.AddFlags(cmd)
74 return cmd
75}
77func (o *options) complete(args []string) error {
78 o.workflowKey = args[0]
79 return o.conn.Complete()
80}
82func (o *options) validate() error {
83 return o.wait.Validate()
84}
86func (o *options) run(ctx context.Context) error {
87 token, err := o.workflowToken.Read(o.io.In)
88 if err != nil {
89 return err
90 }
92 client, conn, err := o.conn.Dial(ctx, o.io, o.apiClient)
93 if err != nil {
94 return err
95 }
96 defer conn.Close()
98 callCtx, cancel := context.WithTimeout(ctx, autoflowutils.CallTimeout)
99 defer cancel()
100 _, err = client.CancelWorkflow(callCtx, &autoflowrpcv1.CancelWorkflowRequest{
101 WorkflowKey: o.workflowKey,
102 WorkflowToken: &token,
103 NamespaceId: o.conn.NamespaceID[:],
104 })
105 if err != nil {
106 return fmt.Errorf("failed to cancel workflow: %w", err)
107 }
108 o.io.LogInfof("Requested the cancellation of workflow %s.\n", o.workflowKey)
110 if !o.wait.Enabled {
111 return nil
112 }
113 resp, err := o.wait.Until(ctx, client, &autoflowrpcv1.GetWorkflowRequest{
114 WorkflowKey: o.workflowKey,
115 WorkflowToken: &token,
116 NamespaceId: o.conn.NamespaceID[:],
117 })
118 if err != nil {
119 return err
120 }
121 // Asserts the state, not who caused it: a workflow someone else canceled
122 // counts.
123 if resp.GetState() != autoflowrpcv1.WorkflowState_WORKFLOW_STATE_CANCELED {
124 return fmt.Errorf("workflow finished in state %s", autoflowutils.State(resp.GetState()))
125 }
126 o.io.LogInfof("Workflow %s is canceled.\n", o.workflowKey)
127 return nil
128}
Diagnostics9 git calls · 317 ms
CallStatusSizeTime0317 ms
discover200185 B2 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=185 git.server.agent=git/2.56.g1891de4-Linux git.server.object_format=sha1 git.server.caps=agent ls-refs fetch server-option object-format git.server.fetch=shallow wait-for-done filter git.protocol.version=2 git.pkt.frames=9 git.pkt.data=7 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=185 git.pkt.payload.max=35
ls-refs20058 KiB · hit3 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=59849 git.response.cache=HIT git.response.duration_ms=3 git.protocol.version=2 git.pkt.frames=731 git.pkt.data=730 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=59849 git.pkt.payload.max=143 git.ls_refs.count=730 git.ls_refs.head=refs/heads/main
fetchcombine:blob:none+tree:2 · deepen 12004.2 KiB · hit2 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 git.response.bytes=4273 git.response.cache=HIT git.response.duration_ms=2 git.fetch.filter=combine:blob:none+tree:2 git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9 git.fetch.haves.count=0 git.fetch.deepen=1 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=7 git.pkt.data=5 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=4273 git.pkt.payload.max=4173 git.sideband.band1.bytes=4173 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=11 git.pack.bytes=4173 git.fetch.wide.objects=11 git.fetch.wide.extra_bytes=3930 git.fetch.wide.blobs=0
fetchtree:0 · deepen 1020032 KiB · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=2 git.response.bytes=32926 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=tree:0 git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9 git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=22 git.pkt.data=20 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=32926 git.pkt.payload.max=32046 git.sideband.band1.bytes=32046 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=80 git.pack.bytes=32046 git.pack.ofs_delta=36 git.pack.ref_delta=0 git.pack.chain.max=2 git.pack.trailer=cb0bad5d7ffc514895d8b21c4dd470327f90bc91 git.pack.full=44Open pack map
fetchtree:02001.8 KiB · hit2 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=2 git.response.bytes=1857 git.response.cache=HIT git.response.duration_ms=2 git.fetch.filter=tree:0 git.fetch.wants=dce174ff8c632a19d17eea99c8a9b7c37fb2b592 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=4 git.pkt.data=3 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=1857 git.pkt.payload.max=1830 git.sideband.band1.bytes=1830 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=1830 git.pack.trailer=fb03183b7909876778f740d196d7516811003517Open pack map
fetchtree:0200173 B · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 git.response.bytes=173 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=tree:0 git.fetch.wants=9842465ba0bef0fe35148002069a98d0492349fa git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=4 git.pkt.data=3 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=173 git.pkt.payload.max=146 git.sideband.band1.bytes=146 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=146 git.pack.trailer=257bc2fe070f60e712099d7a0548db758c6c9692Open pack map
fetchtree:0200227 B · hit15 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=15 git.response.bytes=227 git.response.cache=HIT git.response.duration_ms=15 git.fetch.filter=tree:0 git.fetch.wants=d9a7c66bd00e9fc74c41d266132b2171a7a82cdd git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=4 git.pkt.data=3 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=227 git.pkt.payload.max=200 git.sideband.band1.bytes=200 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=200 git.pack.trailer=19b86a461d3d30a55c16a56ca10faa7dc7d8b30dOpen pack map
fetchtree:0200139 B · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 git.response.bytes=139 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=tree:0 git.fetch.wants=0b81cb4a241c607173932d04c561a3f0e6e5700f git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=4 git.pkt.data=3 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=139 git.pkt.payload.max=112 git.sideband.band1.bytes=112 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=112 git.pack.trailer=aaa115e647e42be9251de45d238fd6fe0140bc22Open pack map
fetch2001.6 KiB289 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=289 git.response.bytes=1590 git.response.cache=MISS git.response.duration_ms=289 git.fetch.wants=7699dd124ae89de61f6bfc46b9d641ebb9c0c252 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=4 git.pkt.data=3 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=1590 git.pkt.payload.max=1563 git.sideband.band1.bytes=1563 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://gitlab.com/gitlab-org/cli
- Ref
- refs/heads/main
- Commit
- 0dd7574dce9e385c5c30540e6c15657adc6bdce9
- cf-ray
- a5e30a35ce6cee28
- Request
- 2585ed72…
- Protocol
- v2 · sha1
- Agent
- git/2.56.g1891de4-Linux
- Filter
- advertised
- Fetch
- shallow wait-for-done filter
- Capabilities
- agent ls-refs fetch server-option object-format