GitLabgitlab-org
cli
main
1package note
3import (
4 "errors"
5 "fmt"
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/commands/issuable"
15 "gitlab.com/gitlab-org/cli/internal/commands/issue/issueutils"
16 "gitlab.com/gitlab-org/cli/internal/mcpannotations"
17 "gitlab.com/gitlab-org/cli/internal/text"
18)
20func NewCmdNote(f cmdutils.Factory, issueType issuable.IssueType) *cobra.Command {
21 var attach []string
22 var internal bool
24 issueNoteCreateCmd := &cobra.Command{
25 Use: fmt.Sprintf("note <%s-id>", issueType),
26 Aliases: []string{"comment"},
27 Short: fmt.Sprintf("Comment on an %s in GitLab.", issueType),
28 Long: heredoc.Docf(`
29 Without %[1]s--message%[1]s, opens an editor at a terminal, and otherwise reads the comment from standard input, such as when input is piped or redirected.
31 %[1]s--attach%[1]s uploads a file and references it at the end of the comment. Repeat the flag for more than one file, or pass %[1]s-%[1]s to read the file from standard input. An attachment is content on its own, so a comment with only %[1]s--attach%[1]s does not prompt for a body. When standard input is not a terminal, it is read as the comment body, unless %[1]s--attach -%[1]s reads the file from standard input. The command waits until standard input closes, so to post only the attachment from a script, redirect standard input from %[1]s/dev/null%[1]s.
32 %[2]s`, "`", fmt.Sprintf(text.ExperimentalFlagString, "`--attach`")),
33 Example: heredoc.Docf(`
34 # Comment on %[1]s 123, opening an editor for the message
35 glab %[1]s note 123
37 # Comment with the message given inline
38 glab %[1]s note 123 --message "Looking into this now."
40 # Create an internal note, visible only to project members
41 glab %[1]s note 123 --message "Rotating the leaked token now." --internal
43 # Attach a screenshot alongside the message
44 glab %[1]s note 123 --message "Here is the repro." --attach ./screenshot.png
46 # Attach an image piped from the clipboard
47 pngpaste - | glab %[1]s note 123 --attach -
49 # Comment with the message read from a file
50 glab %[1]s note 123 < comment.md`, issueType),
51 Args: cobra.ExactArgs(1),
52 Annotations: map[string]string{
53 mcpannotations.Destructive: "true",
54 },
55 RunE: func(cmd *cobra.Command, args []string) error {
56 var err error
58 client, err := f.GitLabClient()
59 if err != nil {
60 return err
61 }
63 issue, repo, err := issueutils.IssueFromArg(f.ApiClient, client, f.BaseRepo, f.DefaultHostname(), f.Config(), args[0])
64 if err != nil {
65 return err
66 }
68 valid, msg := issuable.ValidateIncidentCmd(issueType, "comment", issue)
69 if !valid {
70 f.IO().LogInfo(msg)
71 return nil
72 }
74 body, _ := cmd.Flags().GetString("message")
76 if strings.TrimSpace(body) == "" && !cmdutils.SkipNoteBody(f.IO(), attach) {
77 body, err = cmdutils.NoteBodyFromStdinOrEditor(cmd.Context(), f.IO(), f.Config, "Message:", "Enter the note's message.")
78 if err != nil {
79 return err
80 }
81 }
83 body, err = cmdutils.AppendAttachments(cmd.Context(), f.IO(), client, repo.FullName(), body, attach)
84 if err != nil {
85 return err
86 }
88 if strings.TrimSpace(body) == "" {
89 return errors.New("aborted: note is empty")
90 }
92 opts := &gitlab.CreateIssueNoteOptions{Body: &body}
93 if internal {
94 opts.Internal = &internal
95 }
97 noteInfo, _, err := client.Notes.CreateIssueNote(repo.FullName(), issue.IID, opts)
98 if err != nil {
99 return err
100 }
102 f.IO().LogInfof("%s#note_%d\n", issue.WebURL, noteInfo.ID)
103 return nil
104 },
105 }
106 issueNoteCreateCmd.Flags().StringP("message", "m", "", "Message text.")
107 issueNoteCreateCmd.Flags().BoolVar(&internal, "internal", false, "Create the note as an internal note, visible only to project members.")
108 cmdutils.AddAttachFlag(issueNoteCreateCmd, &attach, "comment")
110 return issueNoteCreateCmd
111}
Diagnostics8 git calls · 473 ms
CallStatusSizeTime0473 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 · hit119 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=93 git.response.bytes=59849 git.response.cache=HIT git.response.duration_ms=119 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 · hit11 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=5 git.response.bytes=4273 git.response.cache=HIT git.response.duration_ms=11 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 · hit35 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=35 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 · hit7 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=7 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:0200347 B · hit17 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=347 git.response.cache=HIT git.response.duration_ms=17 git.fetch.filter=tree:0 git.fetch.wants=73f6a798386c4a4df64da0b5349881ded38885ca 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=347 git.pkt.payload.max=320 git.sideband.band1.bytes=320 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=320 git.pack.trailer=93ed36ed1884d41429801c50b3bb5d32ef1307a5Open pack map
fetchtree:0200184 B · hit25 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=22 git.response.bytes=184 git.response.cache=HIT git.response.duration_ms=25 git.fetch.filter=tree:0 git.fetch.wants=4ba4650ce53b940b2b4e0b7e7adbfd7c000097f8 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=184 git.pkt.payload.max=157 git.sideband.band1.bytes=157 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=157 git.pack.trailer=2f69124ae2ab54b2a01d88119a7a3f8627f17fb9Open pack map
fetch2001.6 KiB294 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=294 git.response.bytes=1648 git.response.cache=MISS git.response.duration_ms=294 git.fetch.wants=8e86791ad1cb57eb4734120209edaaa0d22d5e99 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=1648 git.pkt.payload.max=1621 git.sideband.band1.bytes=1621 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
- a5eaffedfa58d287
- Request
- 4051f9e3…
- 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