Skip to content

Commit c2dd13e

Browse files
committed
feat: make PR ready templetized
1 parent 2736556 commit c2dd13e

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

pr-ready/pr-ready.sh

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,33 @@
11
#!/bin/bash
22

3-
# Set your GitHub repository
4-
REPO="ldetmer/java-cloud"
5-
63
# Function to fetch release PRs
74
get_release_prs() {
85
local token=$1
9-
local response=$(curl -s -H "Authorization: token $token" -H "Accept: application/vnd.github+json" "https://api.github.com/repos/$REPO/pulls")
6+
local repo=$2
7+
local desc=$3
8+
local response=$(curl -s -H "Authorization: token $token" -H "Accept: application/vnd.github+json" "https://api.github.com/repos/$repo/pulls")
109
# Extract PR numbers from the response JSON
11-
echo "$response" | jq -r '.[] | select(.title | startswith("chore(main): release")) | .number'
10+
echo "$response" | jq -r '.[] | select(.title | startswith("$desc")) | .number'
11+
12+
PR_NUMBER=$(echo "$response" | jq -r '.[] | select(.title | startswith("$desc")) | .number')
13+
14+
if [ -n "$PR_NUMBER" ]; then
15+
echo "$PR_NUMBER"
16+
return 0 # PR found
17+
else
18+
echo "No PR found starting with '$desc'. Trying again in 60 seconds..."
19+
sleep 60
20+
return 1 # PR not found
21+
fi
1222
}
1323

1424
# Function to merge a PR
15-
merge_pr() {
25+
check_if_pr_mergable() {
1626
local pr_number=$1
1727
local token=$2
28+
local repo=$3
1829
while true; do
19-
local response=$(curl -s -H "Authorization: token $token" -H "Accept: application/vnd.github+json" "https://api.github.com/repos/$REPO/pulls/$pr_number")
30+
local response=$(curl -s -H "Authorization: token $token" -H "Accept: application/vnd.github+json" "https://api.github.com/repos/$repo/pulls/$pr_number")
2031
# Check if the PR is mergeable
2132
if jq -e '.mergeable' <<< "$response" > /dev/null; then
2233
echo "https://api.github.com/repos/$REPO/pulls/$pr_number"
@@ -29,15 +40,18 @@ merge_pr() {
2940
}
3041

3142
# Main script execution
32-
if [[ $# -ne 1 ]]; then
33-
echo "Usage: $0 <your-github-access-token>"
43+
if [[ $# -ne 3 ]]; then
44+
echo "Usage: $0 <your-github-access-token> <repo> <pr text>"
3445
exit 1
3546
fi
3647

3748
TOKEN=$1
38-
release_prs=$(get_release_prs "$TOKEN")
49+
REPO=$2
50+
DESC=$3
51+
52+
release_prs=$(get_release_prs "$TOKEN" "$REPO" "$DESC")
3953

4054
# Iterate over PR numbers and attempt to merge them
4155
for pr_number in $release_prs; do
42-
merge_pr "$pr_number" "$TOKEN"
56+
check_if_pr_mergable "$pr_number" "$TOKEN" "$REPO"
4357
done

0 commit comments

Comments
 (0)