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

Tag Boost milestones #41470

Closed
wants to merge 6 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/tag-boost-milestone.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Tag Boost PRs with milestone

on:
pull_request:
types: [closed]

jobs:
tag-pr:
runs-on: ubuntu-latest
if: |
github.event.pull_request.merged == true &&
contains(github.event.pull_request.labels.*.name, '[Plugin] Boost')
env:
MILESTONE_NAME: "boost/next"

steps:
- name: Checkout repository
uses: actions/checkout@v2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actions/checkout is up to v4 by now.


- name: Create the milestone if it doesn't exist
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
run: |
if ! gh api repos/${REPO}/milestones --jq '.[] | select(.title=="'"$MILESTONE_NAME"'")' | grep -q "$MILESTONE_NAME"; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be done a bit more cleanly as something like

Suggested change
if ! gh api repos/${REPO}/milestones --jq '.[] | select(.title=="'"$MILESTONE_NAME"'")' | grep -q "$MILESTONE_NAME"; then
if ! gh api "repos/${REPO}/milestones" | jq -e --arg NAME "$MILESTONE_NAME" '.[] | select( .title == $NAME )' &>/dev/null; then

Using jq's -e saves having to grep, and --arg saves having to worry about quotes in the variable when trying to embed it in the jq filter string.

echo "Creating milestone $MILESTONE_NAME"
gh api repos/${REPO}/milestones -F title="$MILESTONE_NAME" -F state="open"
else
echo "Milestone $MILESTONE_NAME already exists"
fi

- name: Set milestone on PR if none is set
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
milestone=$(gh pr view ${PR_NUMBER} --json milestone --jq '.milestone.title')
if [ "$milestone" = "null" ] || [ -z "$milestone" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bash syntax

Suggested change
if [ "$milestone" = "null" ] || [ -z "$milestone" ]; then
if [[ "$milestone" = "null" || -z "$milestone" ]]; then

echo "Setting milestone $MILESTONE_NAME on PR #${PR_NUMBER}"
gh pr edit ${PR_NUMBER} --milestone "$MILESTONE_NAME"
else
echo "PR already has milestone: $milestone"
fi