mirror of
https://github.com/peter-evans/create-pull-request.git
synced 2026-12-06 05:12:56 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
82eddd8828 | ||
|
|
6df2a462d1 | ||
|
|
3689bd07d7 | ||
|
|
943f19ac64 | ||
|
|
e59d6c7fff | ||
|
|
c65a4f39b3 | ||
|
|
2d18371789 | ||
|
|
cc7020a609 | ||
|
|
d8700620d6 | ||
|
|
b7064071dc | ||
|
|
339e82d37b |
No files matched your search
@@ -1,4 +1,4 @@
|
|||||||
# <img width="24" height="24" src="assets/logo.svg"> Create Pull Request
|
# <img width="24" height="24" src="docs/assets/logo.svg"> Create Pull Request
|
||||||
[](https://github.com/marketplace/actions/create-pull-request)
|
[](https://github.com/marketplace/actions/create-pull-request)
|
||||||
|
|
||||||
A GitHub action to create a pull request for changes to your repository in the actions workspace.
|
A GitHub action to create a pull request for changes to your repository in the actions workspace.
|
||||||
@@ -88,6 +88,21 @@ If there is some reason you need to use `actions/checkout@v1` the following step
|
|||||||
- run: git checkout "${GITHUB_REF:11}"
|
- run: git checkout "${GITHUB_REF:11}"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Checking out a branch from a different repository from where the workflow is executing will make *that repository* the target for the created pull request. In this case, a `repo` scoped [Personal Access Token (PAT)](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line) is required.
|
||||||
|
|
||||||
|
```yml
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.PAT }}
|
||||||
|
repository: owner/repo
|
||||||
|
|
||||||
|
# Create changes to pull request here
|
||||||
|
|
||||||
|
- uses: peter-evans/create-pull-request@v2
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.PAT }}
|
||||||
|
```
|
||||||
|
|
||||||
### Branch naming
|
### Branch naming
|
||||||
|
|
||||||
For branch naming there are two strategies. Create a fixed-name pull request branch that will be updated with new changes until it is merged or closed, OR, always create a new unique branch each time there are changes to be committed.
|
For branch naming there are two strategies. Create a fixed-name pull request branch that will be updated with new changes until it is merged or closed, OR, always create a new unique branch each time there are changes to be committed.
|
||||||
@@ -194,7 +209,7 @@ jobs:
|
|||||||
|
|
||||||
This reference configuration will create pull requests that look like this:
|
This reference configuration will create pull requests that look like this:
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|||||||
Vendored
+18
-2
@@ -1001,18 +1001,34 @@ module.exports = require("os");
|
|||||||
/***/ (function(__unusedmodule, __unusedexports, __webpack_require__) {
|
/***/ (function(__unusedmodule, __unusedexports, __webpack_require__) {
|
||||||
|
|
||||||
const { inspect } = __webpack_require__(669);
|
const { inspect } = __webpack_require__(669);
|
||||||
|
const fs = __webpack_require__(747);
|
||||||
const core = __webpack_require__(470);
|
const core = __webpack_require__(470);
|
||||||
const exec = __webpack_require__(986);
|
const exec = __webpack_require__(986);
|
||||||
const setupPython = __webpack_require__(139);
|
const setupPython = __webpack_require__(139);
|
||||||
|
|
||||||
|
function fileExists(path) {
|
||||||
|
try {
|
||||||
|
return fs.statSync(path).isFile();
|
||||||
|
} catch (e) {
|
||||||
|
core.debug(`e: ${inspect(e)}`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
try {
|
try {
|
||||||
// Allows ncc to find assets to be included in the distribution
|
// Allows ncc to find assets to be included in the distribution
|
||||||
const src = __webpack_require__.ab + "src";
|
const src = __webpack_require__.ab + "src";
|
||||||
core.debug(`src: ${src}`);
|
core.debug(`src: ${src}`);
|
||||||
|
|
||||||
// Setup Python from the tool cache
|
// Check if the platfrom is Alpine Linux
|
||||||
setupPython("3.8.x", "x64");
|
const alpineLinux = fileExists("/etc/alpine-release");
|
||||||
|
core.debug(`alpineLinux: ${alpineLinux}`);
|
||||||
|
|
||||||
|
// Skip Python setup if the platform is Alpine Linux
|
||||||
|
if (!alpineLinux)
|
||||||
|
// Setup Python from the tool cache
|
||||||
|
setupPython("3.8.x", "x64");
|
||||||
|
|
||||||
// Install requirements
|
// Install requirements
|
||||||
await exec.exec("pip", [
|
await exec.exec("pip", [
|
||||||
|
|||||||
Vendored
+13
@@ -8,6 +8,19 @@ def get_random_string(length=7, chars=string.ascii_lowercase + string.digits):
|
|||||||
return "".join(random.choice(chars) for _ in range(length))
|
return "".join(random.choice(chars) for _ in range(length))
|
||||||
|
|
||||||
|
|
||||||
|
def parse_github_repository(url):
|
||||||
|
# Parse the github repository from a URL
|
||||||
|
# e.g. peter-evans/create-pull-request
|
||||||
|
pattern = re.compile(r"^https://github.com/(.+/.+)$")
|
||||||
|
|
||||||
|
# Check we have a match
|
||||||
|
match = pattern.match(url)
|
||||||
|
if match is None:
|
||||||
|
raise ValueError(f"The format of '{url}' is not a valid GitHub repository URL")
|
||||||
|
|
||||||
|
return match.group(1)
|
||||||
|
|
||||||
|
|
||||||
def parse_display_name_email(display_name_email):
|
def parse_display_name_email(display_name_email):
|
||||||
# Parse the name and email address from a string in the following format
|
# Parse the name and email address from a string in the following format
|
||||||
# Display Name <email@address.com>
|
# Display Name <email@address.com>
|
||||||
|
|||||||
Vendored
+12
-1
@@ -31,6 +31,13 @@ def get_git_config_value(repo, name):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def get_github_repository():
|
||||||
|
remote_origin_url = get_git_config_value(repo, "remote.origin.url")
|
||||||
|
if remote_origin_url is None:
|
||||||
|
raise ValueError("Failed to fetch 'remote.origin.url' from git config")
|
||||||
|
return cmn.parse_github_repository(remote_origin_url)
|
||||||
|
|
||||||
|
|
||||||
def git_user_config_is_set(repo):
|
def git_user_config_is_set(repo):
|
||||||
name = get_git_config_value(repo, "user.name")
|
name = get_git_config_value(repo, "user.name")
|
||||||
email = get_git_config_value(repo, "user.email")
|
email = get_git_config_value(repo, "user.email")
|
||||||
@@ -94,7 +101,6 @@ def set_committer_author(repo, committer, author):
|
|||||||
|
|
||||||
# Get required environment variables
|
# Get required environment variables
|
||||||
github_token = os.environ["GITHUB_TOKEN"]
|
github_token = os.environ["GITHUB_TOKEN"]
|
||||||
github_repository = os.environ["GITHUB_REPOSITORY"]
|
|
||||||
# Get environment variables with defaults
|
# Get environment variables with defaults
|
||||||
path = os.getenv("CPR_PATH", os.getcwd())
|
path = os.getenv("CPR_PATH", os.getcwd())
|
||||||
branch = os.getenv("CPR_BRANCH", DEFAULT_BRANCH)
|
branch = os.getenv("CPR_BRANCH", DEFAULT_BRANCH)
|
||||||
@@ -107,6 +113,11 @@ base = os.environ.get("CPR_BASE")
|
|||||||
# Set the repo path
|
# Set the repo path
|
||||||
repo = Repo(path)
|
repo = Repo(path)
|
||||||
|
|
||||||
|
# Determine the GitHub repository from git config
|
||||||
|
# This will be the target repository for the pull request
|
||||||
|
github_repository = get_github_repository()
|
||||||
|
print(f"Target repository set to {github_repository}")
|
||||||
|
|
||||||
# Determine if the checked out ref is a valid base for a pull request
|
# Determine if the checked out ref is a valid base for a pull request
|
||||||
# The action needs the checked out HEAD ref to be a branch
|
# The action needs the checked out HEAD ref to be a branch
|
||||||
# This check will fail in the following cases:
|
# This check will fail in the following cases:
|
||||||
|
|||||||
Vendored
+1
-1
@@ -1,2 +1,2 @@
|
|||||||
GitPython==3.0.5
|
GitPython==3.0.7
|
||||||
PyGithub==1.45
|
PyGithub==1.45
|
||||||
Vendored
+17
@@ -9,6 +9,23 @@ def test_get_random_string():
|
|||||||
assert len(cmn.get_random_string(length=20)) == 20
|
assert len(cmn.get_random_string(length=20)) == 20
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_github_repository_success():
|
||||||
|
repository = cmn.parse_github_repository(
|
||||||
|
"https://github.com/peter-evans/create-pull-request"
|
||||||
|
)
|
||||||
|
assert repository == "peter-evans/create-pull-request"
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_github_repository_failure():
|
||||||
|
url = "https://github.com/peter-evans"
|
||||||
|
with pytest.raises(ValueError) as e_info:
|
||||||
|
cmn.parse_github_repository(url)
|
||||||
|
assert (
|
||||||
|
e_info.value.args[0]
|
||||||
|
== f"The format of '{url}' is not a valid GitHub repository URL"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_parse_display_name_email_success():
|
def test_parse_display_name_email_success():
|
||||||
name, email = cmn.parse_display_name_email("abc def <abc@def.com>")
|
name, email = cmn.parse_display_name_email("abc def <abc@def.com>")
|
||||||
assert name == "abc def"
|
assert name == "abc def"
|
||||||
|
|||||||
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
File renamed without changes.
File renamed without changes.
|
Before Width: | Height: | Size: 207 KiB After Width: | Height: | Size: 207 KiB |
File renamed without changes.
|
Before Width: | Height: | Size: 416 B After Width: | Height: | Size: 416 B |
File renamed without changes.
|
Before Width: | Height: | Size: 414 KiB After Width: | Height: | Size: 414 KiB |
@@ -10,6 +10,7 @@ This document covers terminology, how the action works, and general usage guidel
|
|||||||
- [Pull request events](#pull-request-events)
|
- [Pull request events](#pull-request-events)
|
||||||
- [Restrictions on forked repositories](#restrictions-on-forked-repositories)
|
- [Restrictions on forked repositories](#restrictions-on-forked-repositories)
|
||||||
- [Tag push events](#tag-push-events)
|
- [Tag push events](#tag-push-events)
|
||||||
|
- [Security](#security)
|
||||||
|
|
||||||
## Terminology
|
## Terminology
|
||||||
|
|
||||||
@@ -46,7 +47,7 @@ Workflow steps:
|
|||||||
|
|
||||||
The following git diagram shows how the action creates and updates a pull request branch.
|
The following git diagram shows how the action creates and updates a pull request branch.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## Guidelines
|
## Guidelines
|
||||||
|
|
||||||
@@ -171,3 +172,23 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Security
|
||||||
|
|
||||||
|
From a security perspective it's good practice to fork third-party actions, review the code, and use your fork of the action in workflows.
|
||||||
|
By using third-party actions directly the risk exists that it could be modified to do something malicious, such as capturing secrets.
|
||||||
|
|
||||||
|
This action uses [ncc](https://github.com/zeit/ncc) to compile the Node.js code and dependencies into a single file.
|
||||||
|
Python dependencies are vendored and committed to the repository [here](https://github.com/peter-evans/create-pull-request/tree/master/dist/vendor).
|
||||||
|
No dependencies are downloaded during the action execution.
|
||||||
|
|
||||||
|
Vendored Python dependencies can be reviewed by rebuilding the [dist](https://github.com/peter-evans/create-pull-request/tree/master/dist) directory and redownloading dependencies.
|
||||||
|
The following commands require Node and Python 3.
|
||||||
|
|
||||||
|
```
|
||||||
|
npm install
|
||||||
|
npm run clean
|
||||||
|
npm run package
|
||||||
|
```
|
||||||
|
|
||||||
|
The `dist` directory should be rebuilt leaving no git diff.
|
||||||
@@ -1,16 +1,32 @@
|
|||||||
const { inspect } = require("util");
|
const { inspect } = require("util");
|
||||||
|
const fs = require("fs");
|
||||||
const core = require("@actions/core");
|
const core = require("@actions/core");
|
||||||
const exec = require("@actions/exec");
|
const exec = require("@actions/exec");
|
||||||
const setupPython = require("./src/setup-python");
|
const setupPython = require("./src/setup-python");
|
||||||
|
|
||||||
|
function fileExists(path) {
|
||||||
|
try {
|
||||||
|
return fs.statSync(path).isFile();
|
||||||
|
} catch (e) {
|
||||||
|
core.debug(`e: ${inspect(e)}`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
try {
|
try {
|
||||||
// Allows ncc to find assets to be included in the distribution
|
// Allows ncc to find assets to be included in the distribution
|
||||||
const src = __dirname + "/src";
|
const src = __dirname + "/src";
|
||||||
core.debug(`src: ${src}`);
|
core.debug(`src: ${src}`);
|
||||||
|
|
||||||
// Setup Python from the tool cache
|
// Check if the platfrom is Alpine Linux
|
||||||
setupPython("3.8.x", "x64");
|
const alpineLinux = fileExists("/etc/alpine-release");
|
||||||
|
core.debug(`alpineLinux: ${alpineLinux}`);
|
||||||
|
|
||||||
|
// Skip Python setup if the platform is Alpine Linux
|
||||||
|
if (!alpineLinux)
|
||||||
|
// Setup Python from the tool cache
|
||||||
|
setupPython("3.8.x", "x64");
|
||||||
|
|
||||||
// Install requirements
|
// Install requirements
|
||||||
await exec.exec("pip", [
|
await exec.exec("pip", [
|
||||||
|
|||||||
@@ -8,6 +8,19 @@ def get_random_string(length=7, chars=string.ascii_lowercase + string.digits):
|
|||||||
return "".join(random.choice(chars) for _ in range(length))
|
return "".join(random.choice(chars) for _ in range(length))
|
||||||
|
|
||||||
|
|
||||||
|
def parse_github_repository(url):
|
||||||
|
# Parse the github repository from a URL
|
||||||
|
# e.g. peter-evans/create-pull-request
|
||||||
|
pattern = re.compile(r"^https://github.com/(.+/.+)$")
|
||||||
|
|
||||||
|
# Check we have a match
|
||||||
|
match = pattern.match(url)
|
||||||
|
if match is None:
|
||||||
|
raise ValueError(f"The format of '{url}' is not a valid GitHub repository URL")
|
||||||
|
|
||||||
|
return match.group(1)
|
||||||
|
|
||||||
|
|
||||||
def parse_display_name_email(display_name_email):
|
def parse_display_name_email(display_name_email):
|
||||||
# Parse the name and email address from a string in the following format
|
# Parse the name and email address from a string in the following format
|
||||||
# Display Name <email@address.com>
|
# Display Name <email@address.com>
|
||||||
|
|||||||
@@ -31,6 +31,13 @@ def get_git_config_value(repo, name):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def get_github_repository():
|
||||||
|
remote_origin_url = get_git_config_value(repo, "remote.origin.url")
|
||||||
|
if remote_origin_url is None:
|
||||||
|
raise ValueError("Failed to fetch 'remote.origin.url' from git config")
|
||||||
|
return cmn.parse_github_repository(remote_origin_url)
|
||||||
|
|
||||||
|
|
||||||
def git_user_config_is_set(repo):
|
def git_user_config_is_set(repo):
|
||||||
name = get_git_config_value(repo, "user.name")
|
name = get_git_config_value(repo, "user.name")
|
||||||
email = get_git_config_value(repo, "user.email")
|
email = get_git_config_value(repo, "user.email")
|
||||||
@@ -94,7 +101,6 @@ def set_committer_author(repo, committer, author):
|
|||||||
|
|
||||||
# Get required environment variables
|
# Get required environment variables
|
||||||
github_token = os.environ["GITHUB_TOKEN"]
|
github_token = os.environ["GITHUB_TOKEN"]
|
||||||
github_repository = os.environ["GITHUB_REPOSITORY"]
|
|
||||||
# Get environment variables with defaults
|
# Get environment variables with defaults
|
||||||
path = os.getenv("CPR_PATH", os.getcwd())
|
path = os.getenv("CPR_PATH", os.getcwd())
|
||||||
branch = os.getenv("CPR_BRANCH", DEFAULT_BRANCH)
|
branch = os.getenv("CPR_BRANCH", DEFAULT_BRANCH)
|
||||||
@@ -107,6 +113,11 @@ base = os.environ.get("CPR_BASE")
|
|||||||
# Set the repo path
|
# Set the repo path
|
||||||
repo = Repo(path)
|
repo = Repo(path)
|
||||||
|
|
||||||
|
# Determine the GitHub repository from git config
|
||||||
|
# This will be the target repository for the pull request
|
||||||
|
github_repository = get_github_repository()
|
||||||
|
print(f"Target repository set to {github_repository}")
|
||||||
|
|
||||||
# Determine if the checked out ref is a valid base for a pull request
|
# Determine if the checked out ref is a valid base for a pull request
|
||||||
# The action needs the checked out HEAD ref to be a branch
|
# The action needs the checked out HEAD ref to be a branch
|
||||||
# This check will fail in the following cases:
|
# This check will fail in the following cases:
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
GitPython==3.0.5
|
GitPython==3.0.7
|
||||||
PyGithub==1.45
|
PyGithub==1.45
|
||||||
@@ -9,6 +9,23 @@ def test_get_random_string():
|
|||||||
assert len(cmn.get_random_string(length=20)) == 20
|
assert len(cmn.get_random_string(length=20)) == 20
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_github_repository_success():
|
||||||
|
repository = cmn.parse_github_repository(
|
||||||
|
"https://github.com/peter-evans/create-pull-request"
|
||||||
|
)
|
||||||
|
assert repository == "peter-evans/create-pull-request"
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_github_repository_failure():
|
||||||
|
url = "https://github.com/peter-evans"
|
||||||
|
with pytest.raises(ValueError) as e_info:
|
||||||
|
cmn.parse_github_repository(url)
|
||||||
|
assert (
|
||||||
|
e_info.value.args[0]
|
||||||
|
== f"The format of '{url}' is not a valid GitHub repository URL"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_parse_display_name_email_success():
|
def test_parse_display_name_email_success():
|
||||||
name, email = cmn.parse_display_name_email("abc def <abc@def.com>")
|
name, email = cmn.parse_display_name_email("abc def <abc@def.com>")
|
||||||
assert name == "abc def"
|
assert name == "abc def"
|
||||||
|
|||||||
Reference in new issue
Block a user