Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show notes on lab issue and lab mr #207

Closed
magiraud opened this issue Aug 10, 2018 · 3 comments
Closed

Show notes on lab issue and lab mr #207

magiraud opened this issue Aug 10, 2018 · 3 comments

Comments

@magiraud
Copy link

Thank you @zaquestion for your wonderful program !

lab issue and lab mr could show existing notes/comment.
See also #68.

@zaquestion
Copy link
Owner

Any suggestions on how this should work/look? That's been a bit of a hangup for me. I know for MRs, I want to find a way to show them in lab mr diff and also to show them with relevant code hunks when not looking at a diff.

@claytonrcarter
Copy link
Collaborator

I put together some notes to try to move this forward. Sorry, this is kind of long!

GitLab makes a distinction between notes and discussions, which are notes in a thread. If you query the API for notes, you get them all (notes & discussions) individually, w/o threading. If you query for discussions, you get them all (notes & discussions) with threading. Personally, I've never used discussions, but I'm assuming that they should be taken into account.

gitlab-go docs

GitLab API docs

Example API Output

API Notes:

  1. for notes, the system property is used for GL generated "notes" like "@ user changed the description" and "@ user marked the task blah blah blah as completed"
  2. for discussions, the individual_note property is used to differentiate single notes from discussions

Example results from an issue containing notes and discussions: https://gitlab.com/claytonrcarter/test/issues/2 (I "... truncated ..." duplicate or extra info for brevity)

$ curl --header "Private-Token: $GITLAB_API_PRIVATE_TOKEN" 
https://gitlab.com/api/v4/projects/claytonrcarter%2ftest/issues/2/notes | jq
[
... truncated ...
{
  "id": 116351141,
  "type": "DiscussionNote",
  "body": "This is a comment on the discussion. (Comment 2a.)",
  "attachment": null,
  "author": { ... truncated ... },
  "created_at": "2018-11-12T02:53:13.168Z",
  "updated_at": "2018-11-12T02:53:13.168Z",
  ... truncated ...
},
{
  "id": 116351082,
  "type": "DiscussionNote",
  "body": "This comment is a discussion. (Comment 2.)",
  "attachment": null,
  "author": { ... truncated ... },
  "created_at": "2018-11-12T02:52:39.251Z",
  "updated_at": "2018-11-12T02:52:39.251Z",
  ... truncated ...
},
{
  "id": 116351052,
  "type": null,
  "body": "This comment is a note. (Comment 1.)",
  "attachment": null,
  "author": {
    "id": 666845,
    "name": "Clayton Carter",
    "username": "claytonrcarter",
    "state": "active",
    "avatar_url": "https://assets.gitlab-static.net/uploads/-/system/user/avatar/666845/avatar.png",
    "web_url": "https://gitlab.com/claytonrcarter"
  },
  "created_at": "2018-11-12T02:52:18.178Z",
  "updated_at": "2018-11-12T02:52:18.178Z",
  "system": false,
  "noteable_id": 15742237,
  "noteable_type": "Issue",
  "resolvable": false,
  "noteable_iid": 2
}
]


$ curl --header "Private-Token: $GITLAB_API_PRIVATE_TOKEN" 
https://gitlab.com/api/v4/projects/claytonrcarter%2ftest/issues/2/discussions | jq
[
  {
    "id": "b6f22cf8c18851497733429334fdf196588a974a",
    "individual_note": true,
    "notes": [
      {
        "id": 116351052,
        "type": null,
        "body": "This comment is a note. (Comment 1.)",
        "attachment": null,
        "author": {
          "id": 666845,
          "name": "Clayton Carter",
          "username": "claytonrcarter",
          "state": "active",
          "avatar_url": "https://assets.gitlab-static.net/uploads/-/system/user/avatar/666845/avatar.png",
          "web_url": "https://gitlab.com/claytonrcarter"
        },
        "created_at": "2018-11-12T02:52:18.178Z",
        "updated_at": "2018-11-12T02:52:18.178Z",
        "system": false,
        "noteable_id": 15742237,
        "noteable_type": "Issue",
        "resolvable": false,
        "noteable_iid": 2
      }
    ]
  },
  {
    "id": "57f22ef9870eeadedb032892403cd235de97237d",
    "individual_note": false,
    "notes": [
      {
        "id": 116351082,
        "type": "DiscussionNote",
        "body": "This comment is a discussion. (Comment 2.)",
        "attachment": null,
        "author": { ... truncated ... },
        "created_at": "2018-11-12T02:52:39.251Z",
        "updated_at": "2018-11-12T02:52:39.251Z",
        ... truncated ...
      },
      {
        "id": 116351141,
        "type": "DiscussionNote",
        "body": "This is a comment on the discussion. (Comment 2a.)",
        "attachment": null,
        "author": { ... truncated ... },
        "created_at": "2018-11-12T02:53:13.168Z",
        "updated_at": "2018-11-12T02:53:13.168Z",
        ... truncated ...
      },
      ... truncated ...
    ]
  },
  ... truncated ...
 ]
  

Example of Hub output

Hub shows comments as markdown sections: (e.g., for this issue)

$ hub issue show 207
# Show notes on `lab issue` and `lab mr`

* created by @magiraud on 2018-08-10 14:07:24 +0000 UTC

Thank you @zaquestion for your wonderful program !

`lab issue` and `lab mr` could show existing notes/comment.
See also #68.



## Comments:

### comment by @zaquestion on 2018-08-10 16:15:14 +0000 UTC

Any suggestions on how this should work/look? That's been a bit of a hangup for me. I know for MRs, I want to find a way to show them in `lab mr diff` and also to show them with relevant code hunks when not looking at a diff.

Proposed output

Just to get the conversation started, here is some example output with some proposed formatting. My suggestions:

  1. Refer to "notes" as "comments"
  2. Separate comments from issue metadata with ===================================
  3. Separate individual comments with -----------------------------------
  4. Indent discussions to attempt to group them by thread.
  5. Omit the system notes from CLI output

Possible example (from https://gitlab.com/zaquestion/lab/issues/40):

$ lab issue show zaquestion 40

#40 Add bash completion script
===================================
Cobra has some docs on generating autocompletion scripts for bash: https://github.com/spf13/cobra/blob/master/bash_completions.md
-----------------------------------
Project: zaquestion/lab
Status: Open
Assignees:
Author: zaquestion
Milestone: None
Due Date: None
Time Stats: None
Labels: enhancement, help wanted
WebURL: https://gitlab.com/zaquestion/lab/issues/40

===================================
Comments:
-----------------------------------
comment by @zaquestion at 2017-12-02T10:02:14.000Z

Using the cobra generated bash completion is ended up being rather difficult to use in conjunction with git's bash completion. Moreover, bash completion is clearly well beyond my meager mind. I did put up some work at making a completion script by hand in https://github.com/zaquestion/lab/commit/e1afa8be814976ccc1b96cc01568ceed34dc887a which supports completing the commands but not the arguments.

-----------------------------------
comment by @... at ...

...


Possible example (from https://gitlab.com/claytonrcarter/test/issues/2) :

$ lab issue show claytonrcarter 2

#2 Test issue for notes & discussions.
===================================
This is just an issues for testing notes and discussions in `lab`.
-----------------------------------
Project: claytonrcarter/test
Status: Open
Assignees:
Author: claytonrcarter
Milestone: None
Due Date: None
Time Stats: None
Labels:
WebURL: https://gitlab.com/claytonrcarter/test/issues/2

===================================
Comments:
-----------------------------------
comment by @... at ...

This comment is a note. (Comment 1.)

-----------------------------------
discussion started by @... at ...

    This comment is a discussion. (Comment 2.)
	
    -----------------------------------
    comment by @... at ...
	
    This is a comment on the discussion. (Comment 2a.)
	
    -----------------------------------
    comment by @... at ...
	
    This is another comment on the discussion. (Comment 2b.)
	
-----------------------------------
discussion started by @... at ...

    Another discussion. (Comment 3.)
	
-----------------------------------
comment by @... at ...

Another comment. (Comment 4.)
	
	

@bmeneg
Copy link
Collaborator

bmeneg commented Jun 17, 2021

Feature added in MR #256

@bmeneg bmeneg closed this as completed Jun 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants