Skip to content

Commit d2a1dcf

Browse files
authored
feat: now a PR is used to merge pizza CLI changes (#3)
* feat: now a PR is used to merge pizza CLI changes * docs: updated docs to reflect PRs being used to merge changes now * now the action uses the OpenSauced bot account * docs: typo fix * updated PR script with PR feedback * docs: fixed a typo in a filename
1 parent 84329a9 commit d2a1dcf

File tree

4 files changed

+53
-11
lines changed

4 files changed

+53
-11
lines changed

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
uses: open-sauced/[email protected]
2828
with:
2929
# optional and false by default
30-
commit-and-push: "true"
30+
commit-and-pr: "true"
3131
```
3232
3333
We suggest you add this to a workflow file in the `.github/workflows` directory of your repository and call it something like `pizza-action.yml`.
@@ -42,6 +42,12 @@ The pizza CLI's "generate codeowners ./" command requires a full repository hist
4242

4343
Arguments to pass to the pizza CLI. Default is `generate codeowners ./`.
4444

45-
### `commit-and-push`
45+
### `commit-and-pr`
4646

47-
Whether to commit and push the changes made by the pizza-cli. Default is `false`.
47+
Whether to commit the changes made by the pizza-cli and to create a pull request for the changes. Default is `false`.
48+
49+
## Troubleshooting
50+
51+
One common isssue is the following error, `pull request create failed: GraphQL: GitHub Actions is not permitted to create or approve pull requests (createPullRequest)`. To fix this, check _Allow GitHub Actions to create and approve pull requests_ in the repository settings under the actions section.
52+
53+
![GitHub Actions section of a repository's settings](repository-settings.png)

action.yml

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ inputs:
88
description: "OpenSauced Pizza CLI command to run"
99
default: "generate codeowners ./"
1010
required: true
11-
commit-and-push:
11+
commit-and-pr:
1212
description: "Commit and push changes"
1313
default: "false"
1414
required: false
@@ -43,13 +43,21 @@ runs:
4343
shell: bash
4444
working-directory: ${{ github.workspace }}
4545

46-
- name: Commit and push changes
47-
if: ${{ inputs.commit-and-push == 'true' }}
46+
- name: Make script executable
47+
run: chmod +x ${{ github.action_path }}/scripts/create-pr.sh
48+
shell: bash
49+
50+
- name: Setup git config
4851
run: |
49-
git config user.name github-actions
50-
git config user.email [email protected]
51-
git add .
52-
git commit -m "Auto-commit from GitHub Actions"
53-
git push
52+
git config user.name 'open-sauced[bot]'
53+
git config user.email '63161813+open-sauced[bot]@users.noreply.github.com'
54+
shell: bash
55+
working-directory: ${{ github.workspace }}
56+
57+
- name: Create a PR with pizza CLI changes
58+
env:
59+
GH_TOKEN: ${{ github.token }}
60+
if: ${{ inputs.commit-and-pr == 'true' }}
61+
run: ${{ github.action_path }}/scripts/create-pr.sh
5462
shell: bash
5563
working-directory: ${{ github.workspace }}

repository-settings.png

224 KB
Loading

scripts/create-pr.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
PR_TITLE="chore (automated): OpenSauced updates"
4+
BRANCH_NAME="chore_automated_open-sauced-updates_$(date +%s)"
5+
6+
git checkout -b "$BRANCH_NAME"
7+
8+
# There are potentially multiple files to add from the pizza CLI output
9+
git add .
10+
11+
# Check if there are any changes to commit
12+
if [[ -n "$(git status --porcelain)" ]]; then
13+
echo "Creating PR \"$PR_TITLE\" for branch "$BRANCH_NAME""
14+
git commit -m "$PR_TITLE"
15+
git push origin "$BRANCH_NAME"
16+
17+
# 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
19+
# If dry run is successful, create the actual PR
20+
PR_URL=$(gh pr create --title "$PR_TITLE" --body "This is an automated PR generated by the OpenSauced pizza-action.")
21+
echo "PR created successfully: $PR_URL"
22+
else
23+
echo "Failed to create PR. There might be an issue with branch permissions or other repository settings."
24+
fi
25+
else
26+
# Shouldn't end up here, but log that there was nothing to sync
27+
echo "Looks like there was nothing to update."
28+
fi

0 commit comments

Comments
 (0)