GitLabgitlab-org

cli

main
ply8 git calls237 ms99 KiB6 cachedprotocol v2
170 lines4.7 KiBRaw
1package create
3import (
4 "github.com/MakeNowJust/heredoc/v2"
5 "github.com/spf13/cobra"
7 gitlab "gitlab.com/gitlab-org/api/client-go/v3"
9 "gitlab.com/gitlab-org/cli/internal/api"
10 "gitlab.com/gitlab-org/cli/internal/cmdutils"
11 "gitlab.com/gitlab-org/cli/internal/glrepo"
12 "gitlab.com/gitlab-org/cli/internal/iostreams"
13 "gitlab.com/gitlab-org/cli/internal/mcpannotations"
16type options struct {
17 apiClient func(repoHost string) (*api.Client, error)
18 io *iostreams.IOStreams
19 baseRepo func() (glrepo.Interface, error)
21 projectID string
22 groupID string
24 title string
25 description string
26 dueDate string
27 startDate string
30func NewCmdCreate(f cmdutils.Factory) *cobra.Command {
31 opts := &options{
32 io: f.IO(),
33 apiClient: f.ApiClient,
34 baseRepo: f.BaseRepo,
35 }
37 cmd := &cobra.Command{
38 Use: "create [flags]",
39 Short: "Create a milestone in a project or group.",
40 Long: heredoc.Docf(`
41 The %[1]s--title%[1]s flag is required.
42 Optionally provide a description, due date, and start date.
44 By default, the milestone is created in the current project. Use
45 %[1]s--project%[1]s to target a different project, or %[1]s--group%[1]s to create a
46 group-level milestone. %[1]s--project%[1]s and %[1]s--group%[1]s are mutually exclusive.
47 `, "`"),
48 Example: heredoc.Doc(`
49 # Create a milestone in the current project
50 glab milestone create --title='Example title' --due-date='2025-12-16'
52 # Create a milestone in a different project
53 glab milestone create --title='Q4 release' --due-date='2025-12-16' --project 123
55 # Create a milestone in a group
56 glab milestone create --title='FY26 planning' --due-date='2026-01-31' --group 456
57 `),
58 Args: cobra.NoArgs,
59 ValidArgsFunction: cobra.NoFileCompletions,
60 Annotations: map[string]string{
61 mcpannotations.Destructive: "true",
62 },
63 RunE: func(cmd *cobra.Command, args []string) error {
64 return opts.run()
65 },
66 }
68 cmd.Flags().StringVar(&opts.projectID, "project", "", "The ID or URL-encoded path of the project.")
69 cmd.Flags().StringVar(&opts.groupID, "group", "", "The ID or URL-encoded path of the group.")
71 cmd.Flags().StringVar(&opts.title, "title", "", "Title of the milestone.")
72 cmd.Flags().StringVar(&opts.description, "description", "", "Description of the milestone.")
73 cmd.Flags().StringVar(&opts.dueDate, "due-date", "", "Due date for the milestone. Expected in ISO 8601 format (2025-04-15T08:00:00Z).")
74 cmd.Flags().StringVar(&opts.startDate, "start-date", "", "Start date for the milestone. Expected in ISO 8601 format (2025-04-15T08:00:00Z).")
76 cobra.CheckErr(cmd.MarkFlagRequired("title"))
78 return cmd
81func (o *options) run() error {
82 c, err := o.apiClient("")
83 if err != nil {
84 return err
85 }
86 client := c.Lab()
88 var parsedDueDate, parsedStartDate gitlab.ISOTime
90 if o.startDate != "" {
91 if parsedStartDate, err = gitlab.ParseISOTime(o.startDate); err != nil {
92 return err
93 }
94 }
96 if o.dueDate != "" {
97 if parsedDueDate, err = gitlab.ParseISOTime(o.dueDate); err != nil {
98 return err
99 }
100 }
102 if o.projectID != "" {
103 createMilestoneOptions := &gitlab.CreateMilestoneOptions{
104 Title: &o.title,
105 Description: &o.description,
106 }
108 if o.startDate != "" {
109 createMilestoneOptions.StartDate = &parsedStartDate
110 }
112 if o.dueDate != "" {
113 createMilestoneOptions.DueDate = &parsedDueDate
114 }
116 milestone, _, err := client.Milestones.CreateMilestone(o.projectID, createMilestoneOptions)
117 if err != nil {
118 return err
119 }
121 o.io.LogInfof("Created project milestone %s (ID: %d)", milestone.Title, milestone.ID)
122 return nil
123 } else if o.groupID != "" { // get group milestone
124 createGroupMilestoneOptions := &gitlab.CreateGroupMilestoneOptions{
125 Title: &o.title,
126 Description: &o.description,
127 }
129 if o.startDate != "" {
130 createGroupMilestoneOptions.StartDate = &parsedStartDate
131 }
133 if o.dueDate != "" {
134 createGroupMilestoneOptions.DueDate = &parsedDueDate
135 }
137 milestone, _, err := client.GroupMilestones.CreateGroupMilestone(o.groupID, createGroupMilestoneOptions)
138 if err != nil {
139 return err
140 }
142 o.io.LogInfof("Created group milestone %s (ID: %d)", milestone.Title, milestone.ID)
143 return nil
144 }
146 // run for the current project
147 repo, err := o.baseRepo()
148 if err != nil {
149 return err
150 }
151 createMilestoneOptions := &gitlab.CreateMilestoneOptions{
152 Title: &o.title,
153 Description: &o.description,
154 }
156 if o.startDate != "" {
157 createMilestoneOptions.StartDate = &parsedStartDate
158 }
159 if o.dueDate != "" {
160 createMilestoneOptions.DueDate = &parsedDueDate
161 }
163 milestone, _, err := client.Milestones.CreateMilestone(repo.FullName(), createMilestoneOptions)
164 if err != nil {
165 return err
166 }
168 o.io.LogInfof("Created project milestone %s (ID: %d)", milestone.Title, milestone.ID)
169 return nil
Diagnostics8 git calls · 237 ms
CallStatusSizeTime0237 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 · hit2 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=59849
git.response.cache=HIT
git.response.duration_ms=2
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 · 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=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:02001.8 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=1857
git.response.cache=HIT
git.response.duration_ms=4
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:0200287 B · 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=287
git.response.cache=HIT
git.response.duration_ms=2
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=6593eafdcd01a12bbd3c8da0f75aaca8bc99568f
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=0ce745a78aa912da4dde1375fc7435eca1c70ebf
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=1d57eb13f88bf11e31241cc65128337b1c5cf5f0
Open pack map
fetch2001.5 KiB224 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=224
git.response.bytes=1532
git.response.cache=MISS
git.response.duration_ms=224
git.fetch.wants=5b979702a7e0512ad83ccde82f68682eeb4b1c65
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=1532
git.pkt.payload.max=1505
git.sideband.band1.bytes=1505
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
a5eafa27b90eb1bb
Request
5b6f43a2…
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