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

Automatically create new milestone; optionally move issues to it #1

Open
anthonyfok opened this issue Aug 3, 2021 · 2 comments
Open
Assignees
Labels
Milestone

Comments

@anthonyfok
Copy link
Member

Last Thursday, July 29, Joost and I had a brief discussion on the possibility of automatically creating a new milestone and moving issues to it, and how I surmised that Hugo developers might be already doing it. The day after though, I was surprised by the following tweet:

https://twitter.com/GoHugoIO/status/1421181681717944323

Dear @github moving 200+ issues from a milestone to another is a surprisingly time consuming process. /cc @natfriedman
(and yes, we have been wining about this before)

So, the Hugo folks were migrating issues to new milestone manually too? 🤔

[Edited 2021-08-10: Probably through GitHub's web interface, e.g. search for is:open is:issue milestone:v0.87, click the "select all" checkbox, then click the Milestone to set a new milestone, e.g. v0.88. Problem is that the "select all" checkbox only selects up to 25 issues while Hugo has 299 open issues. 300 ÷ 25 = 12, i.e. the operation has to be repeated 12 times!?! That is a whole lot of clicking! Maybe that is what the complaint was about.]

Anyhow, GitHub does have an Issues API that can create a milestone and update an issue, for example, so perhaps we can use the Issues API to accomplish what we need.

Some on-line posts even suggests the use of GitHub CLI (gh) to manage milestones · Issue #1200 · cli/cli.

(Aside: So that was what I started doing last Saturday (I had a memory lapse), but veered off to looking into having github-cli (gh) packaged for Debian.)

Update: Shared the idea with Hugo at https://discourse.gohugo.io/t/script-to-move-issues-to-new-milestone-proof-of-concept/34181

@anthonyfok anthonyfok self-assigned this Aug 3, 2021
@anthonyfok anthonyfok changed the title Automatically move milestone from Automatically create a new milestone and move issues to it Aug 3, 2021
@anthonyfok
Copy link
Member Author

This is a test script that successfully move OpenDRR/opendrr-api "Sprint 39" issues to "Sprint 40" milestone. (Tested on Thu 2021-08-05).

Note:

  1. It lives on my computer as ~/bin/milestone-test.sh
  2. GitHub CLI gh automatically replaces {owner} and {repo} based on the Git repo directory that you are in.
  3. This is very preliminary and a proof of concept. The milestones names are hardcoded. No error checking is done whatsoever, at least not yet. Proceed with caution!
#!/bin/bash

set -x

OLD_MILESTONE_TITLE="Sprint 39"
NEW_MILESTONE_TITLE="Sprint 40"

OLD_MILESTONE_NUMBER=$(gh api -X GET "repos/{owner}/{repo}/milestones" --jq ".[] | select(.title == \"$OLD_MILESTONE_TITLE\").number")
NEW_MILESTONE_NUMBER=$(gh api -X GET "repos/{owner}/{repo}/milestones" --jq ".[] | select(.title == \"$NEW_MILESTONE_TITLE\").number")

# Print open issues in the previous milestone 
gh api -X GET "repos/{owner}/{repo}/issues" -f milestone="$OLD_MILESTONE_NUMBER" --jq '.[] | [.number, .title, .assignee.login]'

# Move issues to the new milestone
for i in $(gh api -X GET "repos/{owner}/{repo}/issues" -f milestone="$OLD_MILESTONE_NUMBER" -f direction=asc --jq '.[].number'); do
  echo "Moving Issue $i from \"$OLD_MILESTONE_TITLE\" to \"$NEW_MILESTONE_TITLE\"..."
  gh api -X GET "repos/{owner}/{repo}/issues/$i" > "Issue-${i}-${OLD_MILESTONE_TITLE// /-}.json"
  gh api -X PATCH "repos/{owner}/{repo}/issues/$i" -f milestone="$NEW_MILESTONE_NUMBER" > "Issue-${i}-${NEW_MILESTONE_TITLE// /-}.json"
done

To create a milestone:

gh api -X POST repos/{owner}/{repo}/milestones -f title="Sprint 40" -f due_on=2021-08-26T15:30:00-07:00
  • GitHub stores only the date of due_on, but when creating a milestone with -X POST, it needs the whole date+time+timezone string like the above.
  • No such restriction for changing the due_on with -X PATCH though. For example:
gh api -X PATCH repos/{owner}/{repo}/milestones/35 -f due_on=2021-08-05

TODO:

  • Expand this script and turn it into something useful that our team can use. Add features such as:
    • List all open assigned issues
    • Create new milestone with due date
  • Make it cross-platform, i.e. can use on Linux, macOS and Windows. (Implies rewriting in Python? Or keep the bash script but provides also .bat / .ps1?)

@anthonyfok anthonyfok transferred this issue from OpenDRR/opendrr Oct 12, 2021
@anthonyfok anthonyfok added this to the Sprint 44 milestone Oct 12, 2021
@anthonyfok
Copy link
Member Author

My quick-and-dirty one-liner that I used today for creating Sprint 44. Perhaps make it a built-in (hardcoded) or user-configurable list?

for i in boundaries data model-factory opendrr-api opendrr-data-store opendrr-platform pygeoapi; do
    ( cd $i && pwd && gh milestone "Sprint 43" "Sprint 44" )
    echo; echo
done

Another TODO: Remove jq dependency and rely on gh's built-in jq functionality alone.

@anthonyfok anthonyfok changed the title Automatically create a new milestone and move issues to it Automatically create new milestone; optionally move issues to it Oct 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant