Compare commits

...

9 Commits

Author SHA1 Message Date
Peter Evans
b6a458d96a Merge pull request #114 from peter-evans/dev
Add support for ssh protocol
2020-02-10 23:06:03 +09:00
Peter Evans
7b5ff6b642 Add support for ssh protocol 2020-02-10 22:52:00 +09:00
Peter Evans
82eddd8828 Merge pull request #112 from peter-evans/dev
Skip python setup for alpine linux
2020-02-10 18:47:40 +09:00
Peter Evans
6df2a462d1 Skip python setup for alpine linux 2020-02-10 09:53:43 +09:00
Peter Evans
3689bd07d7 Merge pull request #110 from peter-evans/dev
Update dependency GitPython to v3.0.7
2020-02-08 16:45:18 +09:00
Peter Evans
943f19ac64 Update vendored dependencies 2020-02-08 16:12:36 +09:00
Renovate Bot
e59d6c7fff Update dependency GitPython to v3.0.7 2020-02-08 16:09:50 +09:00
Peter Evans
c65a4f39b3 Update documentation 2020-02-08 16:04:23 +09:00
Peter Evans
2d18371789 Update documentation 2020-02-08 12:52:06 +09:00
13 changed files with 109 additions and 34 deletions

View File

@@ -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}"
```
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
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.

20
dist/index.js vendored
View File

@@ -1001,18 +1001,34 @@ module.exports = require("os");
/***/ (function(__unusedmodule, __unusedexports, __webpack_require__) {
const { inspect } = __webpack_require__(669);
const fs = __webpack_require__(747);
const core = __webpack_require__(470);
const exec = __webpack_require__(986);
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() {
try {
// Allows ncc to find assets to be included in the distribution
const src = __webpack_require__.ab + "src";
core.debug(`src: ${src}`);
// Setup Python from the tool cache
setupPython("3.8.x", "x64");
// Check if the platfrom is Alpine Linux
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
await exec.exec("pip", [

20
dist/src/common.py vendored
View File

@@ -9,16 +9,20 @@ def get_random_string(length=7, chars=string.ascii_lowercase + string.digits):
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/(.+/.+)$")
# Parse the protocol and github repository from a URL
# e.g. HTTPS, peter-evans/create-pull-request
https_pattern = re.compile(r"^https://github.com/(.+/.+)$")
ssh_pattern = re.compile(r"^git@github.com:(.+/.+).git$")
# 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")
match = https_pattern.match(url)
if match is not None:
return "HTTPS", match.group(1)
return match.group(1)
match = ssh_pattern.match(url)
if match is not None:
return "SSH", match.group(1)
raise ValueError(f"The format of '{url}' is not a valid GitHub repository URL")
def parse_display_name_email(display_name_email):

View File

@@ -31,11 +31,12 @@ def get_git_config_value(repo, name):
return None
def get_github_repository():
def get_repository_detail():
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)
protocol, github_repository = cmn.parse_github_repository(remote_origin_url)
return remote_origin_url, protocol, github_repository
def git_user_config_is_set(repo):
@@ -115,7 +116,7 @@ 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()
repo_url, protocol, github_repository = get_repository_detail()
print(f"Target repository set to {github_repository}")
# Determine if the checked out ref is a valid base for a pull request
@@ -173,8 +174,10 @@ except ValueError as e:
print(f"::error::{e} " + "Unable to continue. Exiting.")
sys.exit(1)
# Set the repository URL
repo_url = f"https://x-access-token:{github_token}@github.com/{github_repository}"
# Set the auth token in the repo URL
# This supports checkout@v1. From v2 the auth token is saved for further use.
if protocol == "HTTPS":
repo_url = f"https://x-access-token:{github_token}@github.com/{github_repository}"
# Create or update the pull request branch
result = coub.create_or_update_branch(repo, repo_url, commit_message, base, branch)

View File

@@ -1,2 +1,2 @@
GitPython==3.0.5
GitPython==3.0.7
PyGithub==1.45

View File

@@ -10,9 +10,16 @@ def test_get_random_string():
def test_parse_github_repository_success():
repository = cmn.parse_github_repository(
protocol, repository = cmn.parse_github_repository(
"https://github.com/peter-evans/create-pull-request"
)
assert protocol == "HTTPS"
assert repository == "peter-evans/create-pull-request"
protocol, repository = cmn.parse_github_repository(
"git@github.com:peter-evans/create-pull-request.git"
)
assert protocol == "SSH"
assert repository == "peter-evans/create-pull-request"

Binary file not shown.

BIN
dist/vendor/GitPython-3.0.7.tar.gz vendored Normal file

Binary file not shown.

View File

@@ -1,16 +1,32 @@
const { inspect } = require("util");
const fs = require("fs");
const core = require("@actions/core");
const exec = require("@actions/exec");
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() {
try {
// Allows ncc to find assets to be included in the distribution
const src = __dirname + "/src";
core.debug(`src: ${src}`);
// Setup Python from the tool cache
setupPython("3.8.x", "x64");
// Check if the platfrom is Alpine Linux
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
await exec.exec("pip", [

View File

@@ -9,16 +9,20 @@ def get_random_string(length=7, chars=string.ascii_lowercase + string.digits):
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/(.+/.+)$")
# Parse the protocol and github repository from a URL
# e.g. HTTPS, peter-evans/create-pull-request
https_pattern = re.compile(r"^https://github.com/(.+/.+)$")
ssh_pattern = re.compile(r"^git@github.com:(.+/.+).git$")
# 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")
match = https_pattern.match(url)
if match is not None:
return "HTTPS", match.group(1)
return match.group(1)
match = ssh_pattern.match(url)
if match is not None:
return "SSH", match.group(1)
raise ValueError(f"The format of '{url}' is not a valid GitHub repository URL")
def parse_display_name_email(display_name_email):

View File

@@ -31,11 +31,12 @@ def get_git_config_value(repo, name):
return None
def get_github_repository():
def get_repository_detail():
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)
protocol, github_repository = cmn.parse_github_repository(remote_origin_url)
return remote_origin_url, protocol, github_repository
def git_user_config_is_set(repo):
@@ -115,7 +116,7 @@ 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()
repo_url, protocol, github_repository = get_repository_detail()
print(f"Target repository set to {github_repository}")
# Determine if the checked out ref is a valid base for a pull request
@@ -173,8 +174,10 @@ except ValueError as e:
print(f"::error::{e} " + "Unable to continue. Exiting.")
sys.exit(1)
# Set the repository URL
repo_url = f"https://x-access-token:{github_token}@github.com/{github_repository}"
# Set the auth token in the repo URL
# This supports checkout@v1. From v2 the auth token is saved for further use.
if protocol == "HTTPS":
repo_url = f"https://x-access-token:{github_token}@github.com/{github_repository}"
# Create or update the pull request branch
result = coub.create_or_update_branch(repo, repo_url, commit_message, base, branch)

View File

@@ -1,2 +1,2 @@
GitPython==3.0.5
GitPython==3.0.7
PyGithub==1.45

View File

@@ -10,9 +10,16 @@ def test_get_random_string():
def test_parse_github_repository_success():
repository = cmn.parse_github_repository(
protocol, repository = cmn.parse_github_repository(
"https://github.com/peter-evans/create-pull-request"
)
assert protocol == "HTTPS"
assert repository == "peter-evans/create-pull-request"
protocol, repository = cmn.parse_github_repository(
"git@github.com:peter-evans/create-pull-request.git"
)
assert protocol == "SSH"
assert repository == "peter-evans/create-pull-request"