-
Notifications
You must be signed in to change notification settings - Fork 0
89 lines (73 loc) · 2.91 KB
/
update-readme-inprogress-tickets.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
85
86
87
88
89
name: Update README on Label Change
on:
issues:
types:
- labeled
- unlabeled
- closed
permissions:
contents: write
pull-requests: write
jobs:
update-readme:
if: github.event.label.name == 'inprogress' || github.event.action == 'closed'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Generate Temporary Access Token
id: get_workflow_token
uses: peter-murray/workflow-application-token-action@v4
with:
application_id: ${{ secrets.ISEETV_APP_ID }}
application_private_key: ${{ secrets.ISEETV_PRIVATE_KEY }}
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install dependencies
run: pip install requests
- name: Run README update script
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: python .scripts/update_readme_inprogress_tickets.py
- name: Create and Merge Pull Request
env:
GITHUB_TOKEN: ${{ steps.get_workflow_token.outputs.token }}
run: |
# Create a new branch
branch_name="readme-update-issue-${{ github.event.issue.number }}"
git checkout -b $branch_name
# Configure git
git config --global user.name "ReadmeUpdater"
git config --global user.email "[email protected]"
# Commit changes
git add README.md
git commit -m "Update README due to label change on issue #${{ github.event.issue.number }}"
# Push the new branch
git push origin $branch_name
# Create PR using GitHub REST API
pr_response=$(curl -X POST \
-H "Authorization: token ${{ steps.get_workflow_token.outputs.token }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/pulls \
-d '{
"title": "Update README for 'inprogress' tickets",
"body": "Automated README update due to label change on issue",
"head": "'$branch_name'",
"base": "master"
}')
# Get the PR number from the response
pr_number=$(echo $pr_response | jq -r .number)
# Enable auto-merge
curl -X PUT \
-H "Authorization: token ${{ steps.get_workflow_token.outputs.token }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/pulls/$pr_number/merge \
-d '{
"merge_method": "merge"
}'
# Delete the branch after merge
# Wait a moment to ensure merge is complete
sleep 5
git push origin --delete $branch_name