You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
BODY="This is an automated PR generated by the OpenSauced pizza-action."
6
+
7
+
# Even though the bot account is set to the OpenSauced bot account, the author is still the GitHub Actions bot
8
+
AUTHOR="app/github-actions"
9
+
10
+
# Function to close PRs with the same title
11
+
close_duplicate_prs() {
12
+
echo"Checking for PRs with previous updates"
13
+
local new_pr_number=$1
14
+
local prs_to_close=$(gh pr list --state open --json number,title,author --jq ".[] | select(.title == \"$PR_TITLE\" and .number != $new_pr_number and .author.is_bot == "true" and .author.login == \"$AUTHOR\") | .number")
15
+
16
+
# No previous update PRs found
17
+
if [[ -z$prs_to_close ]];then
18
+
echo"No duplicate PRs found to close"
19
+
return
20
+
fi
21
+
22
+
forprin$prs_to_close;do
23
+
echo"Closing duplicate PR #$pr"
24
+
gh pr close $pr --comment "Closing in favor of #$new_pr_number"
25
+
done
26
+
}
5
27
6
28
git checkout -b "$BRANCH_NAME"
7
29
@@ -10,15 +32,21 @@ git add .
10
32
11
33
# Check if there are any changes to commit
12
34
if [[ -n"$(git status --porcelain)" ]];then
13
-
echo"Creating PR \"$PR_TITLE\" for branch "$BRANCH_NAME""
35
+
echo"Creating PR \"$PR_TITLE\" for branch \"$BRANCH_NAME\""
14
36
git commit -m "$PR_TITLE"
15
37
git push origin "$BRANCH_NAME"
16
38
17
39
# Attempt to create the PR (dry run)
18
-
if gh pr create --title "$PR_TITLE" --body "This is an automated PR generated by the OpenSauced pizza-action." --dry-run;then
40
+
if gh pr create --title "$PR_TITLE" --body "$BODY" --dry-run;then
19
41
# If dry run is successful, create the actual PR
20
42
PR_URL=$(gh pr create --title "$PR_TITLE" --body "This is an automated PR generated by the OpenSauced pizza-action.")
21
43
echo"PR created successfully: $PR_URL"
44
+
45
+
# Extract PR number from the URL
46
+
PR_NUMBER=$(echo $PR_URL| grep -oE '[0-9]+$')
47
+
48
+
# Close duplicate PRs
49
+
close_duplicate_prs $PR_NUMBER
22
50
else
23
51
echo"Failed to create PR. There might be an issue with branch permissions or other repository settings."
0 commit comments