Skip to content

Commit c4725c1

Browse files
Update create-pull-request.md
1 parent 98bae4d commit c4725c1

File tree

1 file changed

+51
-7
lines changed

1 file changed

+51
-7
lines changed

recipes/ci-cd/github-actions/workflows/create-pull-request.md

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
- [Create Pull Request](https://github.com/marketplace/actions/create-pull-request) action
1515
> A GitHub action to create a pull request for changes to your repository in the actions workspace.
1616
17-
If you use this action, you don't need a separate step to commit first as this handles it for you.
17+
If you use this action, you don't need a separate step to commit first, as this handles it for you.
1818

1919
> The changes will be automatically committed to a new branch and a pull request created.
2020
@@ -48,16 +48,51 @@ steps:
4848
```
4949

5050

51-
## No action and across repos
51+
## No action
5252

53-
Here we hit the GitHub API to create a PR. We don't actually make the commit or branch here - just the PR itself.
53+
Here we hit the GitHub API to create a PR.
5454

55-
Note that here we are targeting a different repo to the current repo, so need a token to be specified.
55+
We don't actually make the commit or branch here - just the PR itself. See [Commit][] recipe for making the commit.
56+
57+
[Commit]: {{ site.baseurl }}{% link recipes/ci-cd/github-actions/workflows/commit.md %}
58+
59+
### Same repo
60+
61+
Note that `GITHUB_TOKEN` will be generated for you.
62+
63+
```yaml
64+
env:
65+
BRANCH_NAME: ${{ github.head_ref }}
66+
67+
jobs:
68+
create-pr:
69+
steps:
70+
- name: Create Pull Request
71+
run: |
72+
PAYLOAD=$(cat <<EOF
73+
{
74+
"title": "Title of my PR",
75+
"body": "Automated PR to ...",
76+
"head": "${BRANCH_NAME}",
77+
"base": "main"
78+
}
79+
EOF
80+
)
81+
curl https://api.github.com/repos/my-user/other-repo/pulls \
82+
--header "Authorization: token ${ TOKEN }" \
83+
-H "Content-Type:application/json" \
84+
-d "$PAYLOAD"
85+
env:
86+
TOKEN: ${{ secrets.GITHUB_TOKEN }}
87+
```
88+
89+
### Across repos
90+
91+
Note that here we are targeting a different repo to the current repo, so need a token to be specified as `GH_TOKEN` in secrets (don't use the built-in `GITHUB_TOKEN` name.
5692

5793
```yaml
5894
env:
5995
BRANCH_NAME: ${{ github.head_ref }}
60-
GITHUB_TOKEN: ${{ secrets.TOKEN }}
6196
6297
jobs:
6398
create-pr:
@@ -73,10 +108,19 @@ jobs:
73108
}
74109
EOF
75110
)
76-
curl -v -u my-user:$GITHUB_TOKEN \
111+
curl
112+
https://api.github.com/repos/my-user/my-repo/pulls \
113+
--header "Authorization: token ${TOKEN}" \
77114
-H "Content-Type:application/json" \
78-
https://api.github.com/repos/my-user/other-repo/pulls \
79115
-d "$PAYLOAD"
116+
env:
117+
TOKEN: ${{ secrets.GH_TOKEN }}
118+
```
119+
120+
You can also do this:
121+
122+
```
123+
-u my-user:$GITHUB_TOKEN
80124
```
81125

82126

0 commit comments

Comments
 (0)