GitLabgitlab-org
cli
main
1package edit
3import (
4 "strconv"
6 "github.com/MakeNowJust/heredoc/v2"
7 "github.com/spf13/cobra"
9 gitlab "gitlab.com/gitlab-org/api/client-go/v3"
11 "gitlab.com/gitlab-org/cli/internal/api"
12 "gitlab.com/gitlab-org/cli/internal/cmdutils"
13 "gitlab.com/gitlab-org/cli/internal/glrepo"
14 "gitlab.com/gitlab-org/cli/internal/iostreams"
15 "gitlab.com/gitlab-org/cli/internal/mcpannotations"
16)
18type options struct {
19 apiClient func(repoHost string) (*api.Client, error)
20 io *iostreams.IOStreams
21 baseRepo func() (glrepo.Interface, error)
23 projectID string
24 groupID string
25 milestoneID int64
27 title string
28 description string
29 dueDate string
30 startDate string
31 state string
32}
34func NewCmdEdit(f cmdutils.Factory) *cobra.Command {
35 opts := &options{
36 io: f.IO(),
37 apiClient: f.ApiClient,
38 baseRepo: f.BaseRepo,
39 }
41 cmd := &cobra.Command{
42 Use: "edit <id> [flags]",
43 Short: "Edit a milestone in a project or group.",
44 Long: heredoc.Docf(`
45 Edit a milestone, identified by its numeric ID, in a project or group.
46 Use the flags to update the title, description, due date, start date,
47 or state. Only the fields you specify are updated.
49 By default, the milestone is edited in the current project. Use
50 %[1]s--project%[1]s to target a different project, or %[1]s--group%[1]s to edit a
51 group-level milestone. %[1]s--project%[1]s and %[1]s--group%[1]s are mutually exclusive.
52 `, "`"),
53 Example: heredoc.Doc(`
54 # Update a milestone's title and due date in the current project
55 glab milestone edit 123 --title='Example title' --due-date='2025-12-16'
57 # Update a milestone in a different project
58 glab milestone edit 123 --title='Q4 release' --due-date='2025-12-16' --project owner/project
60 # Update a group milestone
61 glab milestone edit 123 --title='FY26 planning' --due-date='2026-01-31' --group 789
62 `),
63 Args: cobra.ExactArgs(1),
64 Annotations: map[string]string{
65 mcpannotations.Destructive: "true",
66 },
67 RunE: func(cmd *cobra.Command, args []string) error {
68 var err error
69 milestoneIDInt, err := strconv.Atoi(args[0])
70 if err != nil {
71 return err
72 }
73 opts.milestoneID = int64(milestoneIDInt)
74 return opts.run()
75 },
76 }
78 cmd.Flags().StringVar(&opts.projectID, "project", "", "The ID or URL-encoded path of the project.")
79 cmd.Flags().StringVar(&opts.groupID, "group", "", "The ID or URL-encoded path of the group.")
81 cmd.Flags().StringVar(&opts.title, "title", "", "Title of the milestone.")
82 cmd.Flags().StringVar(&opts.description, "description", "", "Description of the milestone.")
83 cmd.Flags().StringVar(&opts.dueDate, "due-date", "", "Due date for the milestone. Expected in ISO 8601 format (2025-04-15T08:00:00Z).")
84 cmd.Flags().StringVar(&opts.startDate, "start-date", "", "Start date for the milestone. Expected in ISO 8601 format (2025-04-15T08:00:00Z).")
85 cmd.Flags().StringVar(&opts.state, "state", "", "State of the milestone. Can be 'activate' or 'close'.")
87 return cmd
88}
90func (o *options) run() error {
91 c, err := o.apiClient("")
92 if err != nil {
93 return err
94 }
95 client := c.Lab()
97 updateMilestoneOptions, updateGroupMilestoneOptions, err := createOptions(o)
98 if err != nil {
99 return err
100 }
102 switch {
103 case o.projectID != "":
104 milestone, _, err := client.Milestones.UpdateMilestone(o.projectID, o.milestoneID, updateMilestoneOptions)
105 if err != nil {
106 return err
107 }
108 o.io.LogInfof("Updated project milestone %s (ID: %d)", milestone.Title, milestone.ID)
109 case o.groupID != "":
110 milestone, _, err := client.GroupMilestones.UpdateGroupMilestone(o.groupID, o.milestoneID, updateGroupMilestoneOptions)
111 if err != nil {
112 return err
113 }
114 o.io.LogInfof("Updated group milestone %s (ID: %d)", milestone.Title, milestone.ID)
115 default:
116 repo, err := o.baseRepo()
117 if err != nil {
118 return err
119 }
120 milestone, _, err := client.Milestones.UpdateMilestone(repo.FullName(), o.milestoneID, updateMilestoneOptions)
121 if err != nil {
122 return err
123 }
124 o.io.LogInfof("Updated project milestone %s (ID: %d)", milestone.Title, milestone.ID)
126 }
127 return nil
128}
130// createOptions - helper function used to create the UpdateMilestoneOptions and UpdateGroupMilestoneOptions
131func createOptions(o *options) (*gitlab.UpdateMilestoneOptions, *gitlab.UpdateGroupMilestoneOptions, error) {
132 var parsedDueDate, parsedStartDate gitlab.ISOTime
133 var err error
135 if o.startDate != "" {
136 if parsedStartDate, err = gitlab.ParseISOTime(o.startDate); err != nil {
137 return nil, nil, err
138 }
139 }
141 if o.dueDate != "" {
142 if parsedDueDate, err = gitlab.ParseISOTime(o.dueDate); err != nil {
143 return nil, nil, err
144 }
145 }
147 updateMilestoneOptions := &gitlab.UpdateMilestoneOptions{}
148 updateGroupMilestoneOptions := &gitlab.UpdateGroupMilestoneOptions{}
150 if o.title != "" {
151 updateMilestoneOptions.Title = &o.title
152 updateGroupMilestoneOptions.Title = &o.title
153 }
154 if o.description != "" {
155 updateMilestoneOptions.Description = &o.description
156 updateGroupMilestoneOptions.Description = &o.description
157 }
159 if o.startDate != "" {
160 updateMilestoneOptions.StartDate = &parsedStartDate
161 updateGroupMilestoneOptions.StartDate = &parsedStartDate
162 }
164 if o.dueDate != "" {
165 updateMilestoneOptions.DueDate = &parsedDueDate
166 updateGroupMilestoneOptions.DueDate = &parsedDueDate
167 }
169 if o.state != "" {
170 updateMilestoneOptions.StateEvent = &o.state
171 updateGroupMilestoneOptions.StateEvent = &o.state
172 }
174 return updateMilestoneOptions, updateGroupMilestoneOptions, nil
175}
Diagnostics8 git calls · 246 ms
CallStatusSizeTime0246 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 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
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=3 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
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=fb03183b7909876778f740d196d7516811003517Open pack map
fetchtree:0200287 B · 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=287 git.response.cache=HIT git.response.duration_ms=4 git.fetch.filter=tree:0 git.fetch.wants=4b2a62b649e97f7e66e5dd178207a12ec137d596 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=287 git.pkt.payload.max=260 git.sideband.band1.bytes=260 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=260 git.pack.trailer=6593eafdcd01a12bbd3c8da0f75aaca8bc99568fOpen pack map
fetchtree:0200135 B · hit6 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=6 git.response.bytes=135 git.response.cache=HIT git.response.duration_ms=6 git.fetch.filter=tree:0 git.fetch.wants=36a47b09bc13b1752f059e580024ac77b4d01f01 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=135 git.pkt.payload.max=108 git.sideband.band1.bytes=108 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=108 git.pack.trailer=177bd9243ff28f36f129a466d481406949338a74Open pack map
fetch2001.7 KiB226 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=226 git.response.bytes=1736 git.response.cache=MISS git.response.duration_ms=226 git.fetch.wants=24c60618fc4621f135bfe1be0f5e378ada7714f8 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=1736 git.pkt.payload.max=1709 git.sideband.band1.bytes=1709 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
- a5eafa20987bb1bb
- Request
- 771e0d9a…
- 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