Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save adriens/5a66c2aad305b6da7f3a8f7271e6f42d to your computer and use it in GitHub Desktop.

Select an option

Save adriens/5a66c2aad305b6da7f3a8f7271e6f42d to your computer and use it in GitHub Desktop.

🔖 Resources

🕹️ Demo

clear
figlet "GitHub cli demo around Milestones"
gh version

Create a dumb repo

gh repo create demo-milestone-from-cli \
    --description "Demo repo for milestone management from cli"\
    --public

Then take a glance at it :

gh repo view demo-milestone-from-cli
# Then with the web browser
gh repo view demo-milestone-from-cli --web

Create a milestone

# GitHub CLI api
# https://cli.github.com/manual/gh_api

gh api \
  --method POST \
  -H "Accept: application/vnd.github.v3+json" \
  /repos/adriens/demo-milestone-from-cli/milestones \
  -f title='Demo'
 -f state='open'
 -f description='Dumb milestone for demo purpose'
 -f due_on='2012-10-09T23:39:01Z'

Take a look with web brower

firefox https://github.com/adriens/demo-milestone-from-cli/milestones

List milestones

# https://cli.github.com/manual/gh_api
gh api \
  -H "Accept: application/vnd.github.v3+json" \
  /repos/adriens/demo-milestone-from-cli/milestones

List and format milestones

gh api \
  -H "Accept: application/vnd.github.v3+json" \
  /repos/adriens/demo-milestone-from-cli/milestones \
  | jq -r '.[] | [.id, .number, .title] | @tsv'

Get a milestone

# GitHub CLI api
# https://cli.github.com/manual/gh_api

gh api \
  -H "Accept: application/vnd.github.v3+json" \
  /repos/adriens/demo-milestone-from-cli/milestones/1

Get a formated output of milestones

gh api \
  -H "Accept: application/vnd.github.v3+json" \
  /repos/adriens/demo-milestone-from-cli/milestones/1 \
  | jq -r '. | [.title, .description, .html_url, .creator.login] | @tsv'

Look at the milestone with web browser

firefox https://github.com/adriens/demo-milestone-from-cli/milestone/1

Create issue within the milestone

gh issue create --milestone "Demo" --title "hello from cli" \
    --repo adriens/demo-milestone-from-cli\
    --body "Body bidon from cli"

View issue

gh issue view 1 --repo adriens/demo-milestone-from-cli

# Then with the web browser
gh issue view 1 --repo adriens/demo-milestone-from-cli --web

List issues of the milestone

gh issue list --milestone "Demo" --repo adriens/demo-milestone-from-cli 

# Then from the web browser
firefox https://github.com/adriens/demo-milestone-from-cli/milestone/1

Close the issue

gh issue close 1 --comment "That was fast"  \
    --repo adriens/demo-milestone-from-cli

List (closed) issues of the milestone

gh issue list --milestone Demo --state closed \
    --repo adriens/demo-milestone-from-cli 
# List issues with a web browser
gh issue list --milestone Demo --state closed \
    --repo adriens/demo-milestone-from-cli  --web

Close the milestone

# GitHub CLI api
# https://cli.github.com/manual/gh_api

gh api --method PATCH -H "Accept: application/vnd.github.v3+json" \
    /repos/adriens/demo-milestone-from-cli/milestones/1 \
    -f title='v1.0' -f state='closed' \
    -f description='End of demo' \
    -f due_on='2022-12-25T23:39:01Z'

Check the closed milestone

gh api \
  -H "Accept: application/vnd.github.v3+json" \
  /repos/adriens/demo-milestone-from-cli/milestones/1 \
  | jq -r '. | [.title, .state] | @tsv'

Take a look at the milestone with the web browser

firefox https://github.com/adriens/demo-milestone-from-cli/milestone/1

Delete milestone

# GitHub CLI api
# https://cli.github.com/manual/gh_api

gh api \
  --method DELETE \
  -H "Accept: application/vnd.github.v3+json" \
  /repos/adriens/demo-milestone-from-cli/milestones/1

Check milestone has been deleted

gh api \
  -H "Accept: application/vnd.github.v3+json" \
  /repos/adriens/demo-milestone-from-cli/milestones/1

# Then with web browser
firefox https://github.com/adriens/demo-milestone-from-cli/milestone/1

Delete repo

gh repo delete adriens/demo-milestone-from-cli --confirm
# Then check it
gh repo view demo-milestone-from-cli
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment