GitLabgitlab-org

cli

main
ply8 git calls372 ms99 KiB5 cachedprotocol v2
178 lines5.5 KiBRaw
1package update
3import (
4 "fmt"
5 "strconv"
6 "strings"
8 "github.com/MakeNowJust/heredoc/v2"
9 "github.com/spf13/cobra"
11 gitlab "gitlab.com/gitlab-org/api/client-go/v3"
13 "gitlab.com/gitlab-org/cli/internal/cmdutils"
14 "gitlab.com/gitlab-org/cli/internal/mcpannotations"
17func NewCmdUpdate(f cmdutils.Factory) *cobra.Command {
18 scheduleUpdateCmd := &cobra.Command{
19 Use: "update <id> [flags]",
20 Short: `Update a pipeline schedule.`,
21 Long: heredoc.Docf(`
22 Update a CI/CD pipeline schedule, identified by its numeric ID. Use
23 the flags to change the cron expression, description, ref, time zone,
24 or active state. Only the fields you specify are updated.
26 To change pipeline variables, use %[1]s--create-variable%[1]s, %[1]s--update-variable%[1]s,
27 and %[1]s--delete-variable%[1]s. The %[1]screate%[1]s and %[1]supdate%[1]s flags take
28 %[1]skey:value%[1]s pairs; %[1]sdelete%[1]s takes a key. Pass each flag multiple times
29 to change several variables.
31 By default, the schedule is updated in the current project. Use
32 %[1]s--repo%[1]s to target another project.
33 `, "`"),
34 Example: heredoc.Doc(`
35 # Update the cron expression for a schedule
36 glab schedule update 10 --cron "0 * * * *"
38 # Update a schedule's description and ref
39 glab schedule update 10 --description "Hourly build" --ref main
41 # Add, change, and remove variables in one call
42 glab schedule update 10 --create-variable "foo:bar" --update-variable "baz:qux" --delete-variable "old"
43 `),
44 Args: cobra.ExactArgs(1),
45 Annotations: map[string]string{
46 mcpannotations.Destructive: "true",
47 },
48 RunE: func(cmd *cobra.Command, args []string) error {
49 variablesToCreate, err := cmd.Flags().GetStringSlice("create-variable")
50 if err != nil {
51 return err
52 }
53 variablesToUpdate, err := cmd.Flags().GetStringSlice("update-variable")
54 if err != nil {
55 return err
56 }
57 variablesToDelete, err := cmd.Flags().GetStringSlice("delete-variable")
58 if err != nil {
59 return err
60 }
62 variablePairsToCreate := make([][2]string, 0, len(variablesToCreate))
63 for _, v := range variablesToCreate {
64 split := strings.SplitN(v, ":", 2)
65 if len(split) != 2 {
66 return fmt.Errorf("invalid format for --create-variable: %s", v)
67 }
69 variablePairsToCreate = append(variablePairsToCreate, [2]string{split[0], split[1]})
70 }
72 variablePairsToUpdate := make([][2]string, 0, len(variablesToUpdate))
73 for _, v := range variablesToUpdate {
74 split := strings.SplitN(v, ":", 2)
75 if len(split) != 2 {
76 return fmt.Errorf("invalid format for --update-variable: %s", v)
77 }
79 variablePairsToUpdate = append(variablePairsToUpdate, [2]string{split[0], split[1]})
80 }
82 client, err := f.GitLabClient()
83 if err != nil {
84 return err
85 }
87 repo, err := f.BaseRepo()
88 if err != nil {
89 return err
90 }
92 id, err := strconv.ParseUint(args[0], 10, 64)
93 if err != nil {
94 return err
95 }
97 scheduleId := int64(id)
99 opts := &gitlab.EditPipelineScheduleOptions{}
101 description, _ := cmd.Flags().GetString("description")
102 ref, _ := cmd.Flags().GetString("ref")
103 cron, _ := cmd.Flags().GetString("cron")
104 cronTimeZone, _ := cmd.Flags().GetString("cronTimeZone")
105 active, _ := cmd.Flags().GetBool("active")
107 if cmd.Flags().Lookup("active").Changed {
108 opts.Active = &active
109 }
111 if description != "" {
112 opts.Description = &description
113 }
115 if ref != "" {
116 opts.Ref = &ref
117 }
119 if cron != "" {
120 opts.Cron = &cron
121 }
123 if cronTimeZone != "" {
124 opts.CronTimezone = &cronTimeZone
125 }
127 // skip API call if no changes are made
128 if opts.Active != nil || opts.Description != nil || opts.Ref != nil || opts.Cron != nil || opts.CronTimezone != nil {
129 _, _, err := client.PipelineSchedules.EditPipelineSchedule(repo.FullName(), scheduleId, opts)
130 if err != nil {
131 return err
132 }
133 }
135 for _, v := range variablePairsToCreate {
136 _, _, err := client.PipelineSchedules.CreatePipelineScheduleVariable(repo.FullName(), scheduleId, &gitlab.CreatePipelineScheduleVariableOptions{
137 Key: &v[0],
138 Value: &v[1],
139 })
140 if err != nil {
141 return err
142 }
143 }
145 for _, v := range variablePairsToUpdate {
146 _, _, err := client.PipelineSchedules.EditPipelineScheduleVariable(repo.FullName(), scheduleId, v[0], &gitlab.EditPipelineScheduleVariableOptions{
147 Value: &v[1],
148 })
149 if err != nil {
150 return err
151 }
152 }
154 for _, v := range variablesToDelete {
155 _, _, err := client.PipelineSchedules.DeletePipelineScheduleVariable(repo.FullName(), scheduleId, v)
156 if err != nil {
157 return err
158 }
159 }
161 f.IO().LogInfo("Updated schedule with ID", scheduleId)
163 return nil
164 },
165 }
167 scheduleUpdateCmd.Flags().String("description", "", "Description of the schedule.")
168 scheduleUpdateCmd.Flags().String("ref", "", "Target branch or tag.")
169 scheduleUpdateCmd.Flags().String("cron", "", "Cron interval pattern.")
170 scheduleUpdateCmd.Flags().String("cronTimeZone", "", "Cron timezone.")
171 scheduleUpdateCmd.Flags().Bool("active", true, "Whether or not the schedule is active.")
172 scheduleUpdateCmd.Flags().StringSlice("create-variable", []string{}, "Pass new variables to schedule in format <key>:<value>.")
173 scheduleUpdateCmd.Flags().StringSlice("update-variable", []string{}, "Pass updated variables to schedule in format <key>:<value>.")
174 scheduleUpdateCmd.Flags().StringSlice("delete-variable", []string{}, "Pass variables you want to delete from schedule in format <key>.")
175 scheduleUpdateCmd.Flags().Lookup("active").DefValue = "to not change"
177 return scheduleUpdateCmd
Diagnostics8 git calls · 372 ms
CallStatusSizeTime0372 ms
discover200185 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
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 KiB156 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=154
git.response.bytes=59849
git.response.cache=EXPIRED
git.response.duration_ms=156
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
fetchtree:0 · deepen 1020032 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=32926
git.response.cache=HIT
git.response.duration_ms=2
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=44
Open pack map
fetchcombine:blob:none+tree:2 · deepen 12004.2 KiB · hit4 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=4
git.response.bytes=4273
git.response.cache=HIT
git.response.duration_ms=4
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:02001.8 KiB · 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=1857
git.response.cache=HIT
git.response.duration_ms=3
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=fb03183b7909876778f740d196d7516811003517
Open pack map
fetchtree:0200258 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=258
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=2c270ec0aade647327d1eadbbb162f93f066af69
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=258
git.pkt.payload.max=231
git.sideband.band1.bytes=231
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=231
git.pack.trailer=09803190b531b8c270ef4ea7e6be0d538e0ee9f5
Open 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=2932c519a9d3eddc8f82959dd30999d0ff05bca2
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=cb684225f2eab5a5bab6fb3ced0b6cb98396ac75
Open pack map
fetch2001.7 KiB203 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=203
git.response.bytes=1766
git.response.cache=MISS
git.response.duration_ms=203
git.fetch.wants=9bdc6639edb9dee419a3aeadad52e2ac6709ae65
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=1766
git.pkt.payload.max=1739
git.sideband.band1.bytes=1739
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
a5e23d7ebc874bc2
Request
d412e1ac…
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