valeriobelli / gh-milestone

GitHub CLI extension for managing Milestones
MIT License
54 stars 2 forks source link

Sorting milestones list #13

Open birbilis opened 2 years ago

birbilis commented 2 years ago

I'm trying to list issues per milestone, I've had progress with https://github.com/cli/cli/discussions/6178

gh-milestone extension isn't used there, but it could as well have been used to get the list of milestone names that is done in the first step of the iterative solution

I have the issue that the milestones are returned in an order for which I can't specify sorting. In specific I'd like to do semantic version SORTING that the bash "sort -V" command can do but on DOS batch that I use there is no ready-made alternative for doing semantic sorting

Seems GitHub CLI supports sorting for other lists, can follow this path of discussions/docs on search's sort: https://github.com/cli/cli/releases/tag/v1.8.0 https://cli.github.com/manual/gh_search_issues https://docs.github.com/en/search-github/searching-on-github/searching-issues-and-pull-requests https://docs.github.com/en/search-github/getting-started-with-searching-on-github/sorting-search-results

eg they have syntax:

`gh issue list -l "bug" --search "sort:interactions-desc"

they don't have a separate sort flag but do it via the search one

So similarly it would be nice to have something like

gh milestone list --search "sort:Version(title)" or gh milestone list --search "sort:title:version" to treat the milestone title as a version string

(code would have to use some semantic version sorting routine though, since GitHub API doesn't seem to have sorting by a "semantic" string)

birbilis commented 2 years ago

doing

gh milestone list -?

noticed there's a sorting option

gh milestone list --state all --orderBy.direction desc

the implied --orderBy.field number there does the job in my case since the temporal order of creation of my milestones is the same as their semantic ordering (based on their title that uses a semantic version string)

However, I need to output only a list of milestone titles. There's a --jq option there and experimented a bit with that with no success. Now I'm getting

 Showing 48 milestones

 #48                    0.8.0   https://github.com/Zoomicon/READCOM_App/milestone/48
 #47                    0.7.2   https://github.com/Zoomicon/READCOM_App/milestone/47
 #46                    0.7.1   https://github.com/Zoomicon/READCOM_App/milestone/46
 #45                    0.5.13  https://github.com/Zoomicon/READCOM_App/milestone/45
 #44                    0.5.12  https://github.com/Zoomicon/READCOM_App/milestone/44
 #43                    0.5.11  https://github.com/Zoomicon/READCOM_App/milestone/43
 #42                    0.5.10  https://github.com/Zoomicon/READCOM_App/milestone/42
 #41                    0.5.9   https://github.com/Zoomicon/READCOM_App/milestone/41
 #40                    0.5.8   https://github.com/Zoomicon/READCOM_App/milestone/40
 #39                    0.5.7   https://github.com/Zoomicon/READCOM_App/milestone/39
 #38                    0.5.6   https://github.com/Zoomicon/READCOM_App/milestone/38
 #37                    0.5.5   https://github.com/Zoomicon/READCOM_App/milestone/37
 #36                    0.5.4   https://github.com/Zoomicon/READCOM_App/milestone/36
 #35                    0.5.3   https://github.com/Zoomicon/READCOM_App/milestone/35
 #34                    0.5.2   https://github.com/Zoomicon/READCOM_App/milestone/34
 #33                    0.5.1   https://github.com/Zoomicon/READCOM_App/milestone/33
 #32                    0.5.0   https://github.com/Zoomicon/READCOM_App/milestone/32
 #31                    0.4.4   https://github.com/Zoomicon/READCOM_App/milestone/31
 #30                    0.4.3   https://github.com/Zoomicon/READCOM_App/milestone/30
 #29                    0.4.2   https://github.com/Zoomicon/READCOM_App/milestone/29
 #28                    0.4.1   https://github.com/Zoomicon/READCOM_App/milestone/28
 #27                    0.4.0   https://github.com/Zoomicon/READCOM_App/milestone/27
 #26                    0.3.6   https://github.com/Zoomicon/READCOM_App/milestone/26
 #25                    0.3.5   https://github.com/Zoomicon/READCOM_App/milestone/25
 #24                    0.3.4   https://github.com/Zoomicon/READCOM_App/milestone/24
 #23                    0.3.3   https://github.com/Zoomicon/READCOM_App/milestone/23
 #22                    0.3.2   https://github.com/Zoomicon/READCOM_App/milestone/22
 #21                    0.3.1   https://github.com/Zoomicon/READCOM_App/milestone/21
 #20                    0.6.0   https://github.com/Zoomicon/READCOM_App/milestone/20
 #19                    0.3.0   https://github.com/Zoomicon/READCOM_App/milestone/19
 #18                    0.2.0   https://github.com/Zoomicon/READCOM_App/milestone/18
 #17                    0.1.0   https://github.com/Zoomicon/READCOM_App/milestone/17
 #16                    0.0.19  https://github.com/Zoomicon/READCOM_App/milestone/16
 #15                    0.0.18  https://github.com/Zoomicon/READCOM_App/milestone/15
 #14                    0.0.17  https://github.com/Zoomicon/READCOM_App/milestone/14
 #13                    0.0.16  https://github.com/Zoomicon/READCOM_App/milestone/13
 #12                    0.0.15  https://github.com/Zoomicon/READCOM_App/milestone/12
 #11                    0.0.14  https://github.com/Zoomicon/READCOM_App/milestone/11
 #10                    0.0.13  https://github.com/Zoomicon/READCOM_App/milestone/10
 #9                     0.0.12  https://github.com/Zoomicon/READCOM_App/milestone/9
 #8                     0.0.11  https://github.com/Zoomicon/READCOM_App/milestone/8
 #7                     0.0.10  https://github.com/Zoomicon/READCOM_App/milestone/7
 #6                     0.0.9   https://github.com/Zoomicon/READCOM_App/milestone/6
 #5                     0.0.8   https://github.com/Zoomicon/READCOM_App/milestone/5
 #4                     0.0.7   https://github.com/Zoomicon/READCOM_App/milestone/4
 #3                     0.0.6   https://github.com/Zoomicon/READCOM_App/milestone/3
 #2                     0.0.4   https://github.com/Zoomicon/READCOM_App/milestone/2
 #1                     0.0.3   https://github.com/Zoomicon/READCOM_App/milestone/1

and I need to get back instead: 0.8.0 0.7.2 0.7.1 ...

birbilis commented 2 years ago

to get just the 2nd column of the output (the title) and to skip the first three lines - the " Showing 48 milestones" is preceeded and followed by an empty line) I used in DOS batch file a FOR command with /F "skip=3 tokens=2" like below:

for /F "skip=3 tokens=2" %%i in (listMilestones.txt) do (
  echo Milestone %%i
  gh issue list --milestone "%%i"  --search "sort:updated-desc" --state "all" --repo "%1/%2"
  ::APPEND THIS TO SHOW JUST ISSUE NUMBER AND TITLE:  --jq ".[] | (.number|tostring)+\" \"+.title" --json number,title
  echo.
)
birbilis commented 2 years ago

However, GitHub seems to have reused probably a deleted index number from a milestone that had been removed (though I don't remember removing one) for my 0.6.0 milestone, ending up in it using number 20 and its previous and next ones using numbers 45 an 46 instead. Nevertheless they happen to sort fine in https://github.com/Zoomicon/READCOM_App/milestones?state=closed using the "Recently updated" Sort order (the default). Obviously if I edit an older one it will damage the sorting in that page. I don't see any way to sort semantically in that page either (nor to sort by creation date or index number of milestone), and that doesn't even have a way to show both open and closed ones (tried puttin ?state=all at the url with no success)

So semantic sorting is still useful to have, can't trust the number of the milestone as it seems that GitHub doesn't leave gap numbers if you delete a milestone (next one will use the gap number instead of the highest number + 1)