-
Notifications
You must be signed in to change notification settings - Fork 14
81 lines (61 loc) · 2.48 KB
/
close-issues.yaml
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
name: Close Issues with Specific Words
on:
workflow_dispatch:
jobs:
close_issues:
runs-on: ubuntu-latest
steps:
- name: Checkout repository content
uses: actions/checkout@v2
- name: Install jq
run: sudo apt-get install jq
- name: Close issues with specified words
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -e
API_URL="https://api.github.com"
PAGE=1
PER_PAGE=30
CLOSED_ISSUES_COUNT=0
echo "Fetching open issues..."
while :; do
ISSUES=$(curl -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3+json" -s "$API_URL/repos/${{ github.repository }}/issues?state=open&page=$PAGE&per_page=$PER_PAGE")
# Debug: Print the raw response
echo "Raw response: $ISSUES"
# Check if the response is valid JSON
if ! echo "$ISSUES" | jq empty; then
echo "Invalid JSON response"
break
fi
# Check if there are no more issues to process
ISSUE_COUNT=$(echo "$ISSUES" | jq '. | length')
if [ "$ISSUE_COUNT" -eq 0 ]; then
echo "No more issues to process."
break
fi
for ISSUE in $(echo "$ISSUES" | jq -r '.[] | @base64'); do
_jq() {
echo "${ISSUE}" | base64 --decode | jq -r "${1}"
}
TITLE=$(_jq '.title')
echo "Processing issue with title: $TITLE"
if [[ "$TITLE" == *"Tutorial"* ]] && [[ "$TITLE" == *"Page"* ]] && [[ "$TITLE" == *"cp-cf-security-xsuaa-create.md"* ]] && [[ "$TITLE" == *"Issue"* ]] && [[ "$TITLE" == *"PROD"* ]]; then
ISSUE_NUMBER=$(_jq '.number')
echo "Closing issue #$ISSUE_NUMBER with title: $TITLE"
curl -X PATCH -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3+json" \
-d '{"state": "closed"}' \
"$API_URL/repos/${{ github.repository }}/issues/$ISSUE_NUMBER"
echo "Issue #$ISSUE_NUMBER closed."
CLOSED_ISSUES_COUNT=$((CLOSED_ISSUES_COUNT + 1))
fi
done
# If the number of issues fetched is less than PER_PAGE, break the loop
if [ "$ISSUE_COUNT" -lt "$PER_PAGE" ]; then
echo "Processed all available issues."
break
fi
PAGE=$((PAGE + 1))
done
echo "Workflow completed."
echo "Total number of issues closed: $CLOSED_ISSUES_COUNT"