Skip to content

feat: assign issue or PR to project on setting milestone #172

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

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
55 changes: 55 additions & 0 deletions .github/workflows/99-assign-to-project-on-milestone-set.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Assign to Project on Milestone Set

on:
issues:
types: [milestoned]
pull_request:
types: [milestoned]

jobs:
assign_to_project:
runs-on: ubuntu-latest

permissions:
issues: write # Permission to modify issues
pull-requests: write # Permission to modify pull requests
repository-projects: write

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Assign issue or PR to project if milestone set
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Pass the GITHUB_TOKEN for authentication
DEV_PROJECT_ID: ${{ secrets.DEV_PROJECT_ID }} # Pass the project ID as an environment variable
run: |
# Extract the issue or PR number
if [ "${{ github.event.issue }}" ]; then
ISSUE_NUMBER=${{ github.event.issue.number }}
elif [ "${{ github.event.pull_request }}" ]; then
ISSUE_NUMBER=${{ github.event.pull_request.number }}
fi

# Output values for debugging
echo "Issue/PR Number: $ISSUE_NUMBER"
echo "Milestone: ${{ github.event.milestone.title }}"
echo "Using Project ID: $DEV_PROJECT_ID"

# Get the repository details
REPO_NAME=${{ github.repository }}
echo "Repository Name: $REPO_NAME"

# If a milestone is set, assign it to the project
if [ -n "${{ github.event.milestone }}" ]; then
echo "Assigning issue/PR #$ISSUE_NUMBER to project..."

# Use curl to create a card in the project (no column ID specified)
curl -X POST \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
-d "{\"content_id\": \"$ISSUE_NUMBER\", \"content_type\": \"Issue\"}" \
"https://api.github.com/repos/$REPO_NAME/projects/$DEV_PROJECT_ID/columns/cards"
else
echo "No milestone set, skipping assignment."
fi
4 changes: 4 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
permissions:
pull-requests: write
contents: write
repository-projects: write
actions: read
security-events: write

Expand All @@ -30,3 +31,6 @@ jobs:
labeler:
if: github.event.pull_request.head.repo.owner.login == 'db-ux-design-system'
uses: ./.github/workflows/99-labeler.yml

project-on-milestone-assignment:
uses: ./.github/workflows/99-assign-to-project-on-milestone-set.yml
Loading