-
Notifications
You must be signed in to change notification settings - Fork 0
84 lines (70 loc) · 3.33 KB
/
update-issue-status.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
name: Update Issue Status and Project
on:
pull_request:
types: [closed]
jobs:
check-pr-for-issue:
runs-on: ubuntu-latest
outputs:
issue-number: ${{ steps.check-issue.outputs.issue-number }}
steps:
- name: Get PR Title and Body
id: get-pr-data
run: |
echo "PR Title: ${{ github.event.pull_request.title }}"
echo "PR Body: ${{ github.event.pull_request.body }}"
echo "::set-output name=pr-title::${{ github.event.pull_request.title }}"
echo "::set-output name=pr-body::${{ github.event.pull_request.body }}"
- name: Check for Issue Number in PR Title or Body
id: check-issue
run: |
# Look for issue numbers in PR title or body
issue_number=$(echo "${{ steps.get-pr-data.outputs.pr-title }} ${{ steps.get-pr-data.outputs.pr-body }}" | grep -oP '#([0-9]+)' | head -n 1 | sed 's/#//')
if [[ -z "$issue_number" ]]; then
echo "No issue number found."
echo "::set-output name=issue-number::none"
else
echo "Found issue number: $issue_number"
echo "::set-output name=issue-number::$issue_number"
fi
update-status:
needs: check-pr-for-issue
runs-on: ubuntu-latest
if: needs.check-pr-for-issue.outputs.issue-number != 'none' # Only run if issue number is found
steps:
- name: Update Issue Status to "Done"
uses: peter-evans/create-or-update-comment@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ needs.check-pr-for-issue.outputs.issue-number }}
body: "Status: Done"
- name: Move Issue Card to 'Done' Column in Project
run: |
# Ensure the issue number is properly assigned
issue_number=${{ needs.check-pr-for-issue.outputs.issue-number }}
echo "Moving issue #$issue_number to 'Done' column in the project..."
# Fetch the issue details (we'll use the GitHub API to find the project cards)
project_url="https://api.github.com/repos/${{ github.repository }}/issues/$issue_number"
# Get the project cards associated with the issue
project_cards=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -s $project_url)
# Debug: Print the project cards JSON to check the structure
echo "Project Cards: $project_cards"
# Extract the first project card ID from the JSON response (if it exists)
project_card_id=$(echo "$project_cards" | jq -r '.[0].id')
if [ -z "$project_card_id" ]; then
echo "No project card found for issue #$issue_number"
exit 1
fi
echo "Found project card ID: $project_card_id"
# Specify the 'Done' column ID (replace this with your actual column ID)
done_column_id=<YOUR_DONE_COLUMN_ID>
if [ -z "$done_column_id" ]; then
echo "Done column ID not set. Please provide a valid column ID."
exit 1
fi
# Move the project card to the 'Done' column
curl -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-d '{"column_id": "'$done_column_id'"}' \
"https://api.github.com/projects/columns/cards/$project_card_id/moves"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}