Compare commits

...

42 Commits

Author SHA1 Message Date
Peter Evans
340e629d2f Merge pull request #152 from peter-evans/dev
Add input for draft pull requests
2020-04-04 09:50:05 +09:00
Peter Evans
abc19caa82 Add input for draft pull requests 2020-04-04 09:47:58 +09:00
Peter Evans
3474dda921 Update documentation 2020-04-03 17:26:11 +09:00
Peter Evans
ad11b10aa4 Merge pull request #151 from peter-evans/renovate/jest-monorepo
Update dependency jest to v25.2.7
2020-04-03 17:14:23 +09:00
Renovate Bot
86aa5be8bf Update dependency jest to v25.2.7 2020-04-03 07:58:49 +00:00
Peter Evans
6867319cf3 Merge pull request #149 from peter-evans/renovate/jest-monorepo
Update dependency jest to v25.2.6
2020-04-02 21:58:25 +09:00
Renovate Bot
cc84a2389e Update dependency jest to v25.2.6 2020-04-02 10:36:04 +00:00
Peter Evans
7e7150d0e8 Merge pull request #147 from peter-evans/dev
Default token to github.token
2020-04-01 19:09:39 +09:00
Peter Evans
eb99d45ce6 Default token to github.token 2020-04-01 18:50:53 +09:00
Peter Evans
115b7391e1 Revert "Update documentation"
This reverts commit 628c2d7d35.
2020-03-30 17:36:34 +09:00
Peter Evans
8305970523 Merge pull request #146 from peter-evans/renovate/jest-monorepo
Update dependency jest to v25.2.4
2020-03-30 09:02:53 +09:00
Renovate Bot
32f5c5dd5f Update dependency jest to v25.2.4 2020-03-29 20:05:26 +00:00
Peter Evans
628c2d7d35 Update documentation 2020-03-29 21:34:47 +09:00
Peter Evans
37582e8764 Update documentation 2020-03-29 21:27:56 +09:00
Peter Evans
1e6b4d1790 Merge pull request #145 from peter-evans/dev
Create pull requests in the parent repository of a checked out fork
2020-03-29 21:02:48 +09:00
Peter Evans
a70c6ebe2a Merge pull request #144 from jderusse/fork
Allow custom repository when pushin in fork
2020-03-29 20:47:00 +09:00
Jérémy Derussé
5bd05538d0 Update src/cpr/create_or_update_pull_request.py
Co-Authored-By: Peter Evans <peter-evans@users.noreply.github.com>
2020-03-29 13:36:48 +02:00
Jérémy Derussé
26bc40eea1 Add link in TOC 2020-03-29 12:44:57 +02:00
Jérémy Derussé
6bb0e7771c Apply suggestions from code review
Co-Authored-By: Peter Evans <peter-evans@users.noreply.github.com>
2020-03-29 12:43:21 +02:00
Jérémy Derussé
4c347a4514 Update docs/concepts-guidelines.md
Co-Authored-By: Tobias Nyholm <tobias.nyholm@gmail.com>
2020-03-28 16:42:57 +01:00
Jérémy Derussé
cff2c3381d Add doc 2020-03-28 13:27:58 +01:00
Jérémy Derussé
e48dab0c1c Add PR creation from Fork 2020-03-28 13:10:12 +01:00
Peter Evans
ac9f92d6e7 Merge pull request #141 from peter-evans/renovate/jest-monorepo
Update dependency jest to v25.2.3
2020-03-27 08:15:40 +09:00
Renovate Bot
3ff256ce08 Update dependency jest to v25.2.3 2020-03-26 20:38:32 +00:00
Peter Evans
0bcb10560b Merge pull request #140 from peter-evans/renovate/jest-monorepo
Update dependency jest to v25.2.1
2020-03-26 19:03:52 +09:00
Renovate Bot
3c4b2793c1 Update dependency jest to v25.2.1 2020-03-26 09:43:37 +00:00
Peter Evans
22870d7816 Merge pull request #139 from peter-evans/renovate/jest-monorepo
Update dependency jest to v25.2.0
2020-03-26 10:23:31 +09:00
Renovate Bot
e324a22ee1 Update dependency jest to v25.2.0 2020-03-25 18:18:56 +00:00
Peter Evans
8b60386018 Merge pull request #135 from peter-evans/renovate/zeit-ncc-0.x
Update dependency @zeit/ncc to v0.22.0
2020-03-24 09:20:19 +09:00
Renovate Bot
6852d55922 Update dependency @zeit/ncc to v0.22.0 2020-03-23 22:31:46 +00:00
Peter Evans
32e5bb80a5 Merge pull request #134 from peter-evans/dev
Update dependencies
2020-03-21 11:38:19 +09:00
Peter Evans
619cf2115d Update dependencies due to security vulnerabilities 2020-03-21 11:31:34 +09:00
Peter Evans
69008aa567 Update vendored dependencies 2020-03-21 11:29:37 +09:00
Renovate Bot
ae4278bf24 Update dependency PyGithub to v1.47 2020-03-21 11:23:42 +09:00
Peter Evans
88da40fea7 Merge pull request #132 from peter-evans/dev
Update dependency GitPython to v3.1.0
2020-03-07 09:08:24 +09:00
Peter Evans
694e068136 Update vendored dependencies 2020-03-07 08:57:59 +09:00
Peter Evans
64c34f6885 Update README 2020-03-03 09:49:52 +09:00
Renovate Bot
52ada17960 Update dependency GitPython to v3.1.0 2020-02-25 13:12:00 +09:00
Peter Evans
ce00b952cf Merge pull request #128 from peter-evans/dev
Unset and restore authorization extraheader only
2020-02-22 17:02:15 +09:00
Peter Evans
0d42c285a3 Unset and restore authorization extraheader only 2020-02-22 16:56:42 +09:00
Peter Evans
ea1eaf1734 Merge pull request #127 from peter-evans/dev
Unset and restore extraheader config option
2020-02-22 14:53:46 +09:00
Peter Evans
d5c5ea3e20 Unset and restore extraheader config option 2020-02-22 14:08:54 +09:00
43 changed files with 6614 additions and 234 deletions

17
.eslintrc.json Normal file
View File

@@ -0,0 +1,17 @@
{
"env": {
"commonjs": true,
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018
},
"rules": {
}
}

View File

@@ -13,7 +13,6 @@ jobs:
id: cpr id: cpr
uses: ./ uses: ./
with: with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: Add report file commit-message: Add report file
committer: Peter Evans <peter-evans@users.noreply.github.com> committer: Peter Evans <peter-evans@users.noreply.github.com>
title: '[Example] Add report file' title: '[Example] Add report file'
@@ -29,7 +28,9 @@ jobs:
milestone: 1 milestone: 1
project: Example Project project: Example Project
project-column: To do project-column: To do
draft: false
branch: example-patches branch: example-patches
request-to-parent: false
- name: Check outputs - name: Check outputs
run: | run: |
echo "Pull Request Number - ${{ env.PULL_REQUEST_NUMBER }}" echo "Pull Request Number - ${{ env.PULL_REQUEST_NUMBER }}"

View File

@@ -27,22 +27,20 @@ Create Pull Request action will:
```yml ```yml
- name: Create Pull Request - name: Create Pull Request
uses: peter-evans/create-pull-request@v2 uses: peter-evans/create-pull-request@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
``` ```
You can also pin to a [specific release](https://github.com/peter-evans/create-pull-request/releases) version in the format `@v2.x.x` You can also pin to a [specific release](https://github.com/peter-evans/create-pull-request/releases) version in the format `@v2.x.x`
### Action inputs ### Action inputs
With the exception of `token`, all inputs are **optional**. If not set, sensible default values will be used. All inputs are **optional**. If not set, sensible default values will be used.
**Note**: If you want pull requests created by this action to trigger an `on: push` or `on: pull_request` workflow then you must use a [Personal Access Token](https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line) instead of the default `GITHUB_TOKEN`. Alternatively, allow the action to [push using SSH](https://github.com/peter-evans/create-pull-request/blob/master/docs/concepts-guidelines.md#push-using-ssh-deploy-keys) by configuring a deploy key. **Note**: If you want pull requests created by this action to trigger an `on: push` or `on: pull_request` workflow then you must use a [Personal Access Token](https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line) instead of the default `GITHUB_TOKEN`. Alternatively, allow the action to [push using SSH](https://github.com/peter-evans/create-pull-request/blob/master/docs/concepts-guidelines.md#push-using-ssh-deploy-keys) by configuring a deploy key.
| Name | Description | Default | | Name | Description | Default |
| --- | --- | --- | | --- | --- | --- |
| `token` | `GITHUB_TOKEN` or a `repo` scoped [PAT](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line). | | | `token` | `GITHUB_TOKEN` or a `repo` scoped [PAT](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line). | `GITHUB_TOKEN` |
| `path` | Relative path under `$GITHUB_WORKSPACE` to the repository. | `$GITHUB_WORKSPACE` | | `path` | Relative path under `GITHUB_WORKSPACE` to the repository. | `GITHUB_WORKSPACE` |
| `commit-message` | The message to use when committing changes. | `[create-pull-request] automated change` | | `commit-message` | The message to use when committing changes. | `[create-pull-request] automated change` |
| `committer` | The committer name and email address in the format `Display Name <email@address.com>`. | Defaults to the GitHub Actions bot user. See [Committer and author](#committer-and-author) for details. | | `committer` | The committer name and email address in the format `Display Name <email@address.com>`. | Defaults to the GitHub Actions bot user. See [Committer and author](#committer-and-author) for details. |
| `author` | The author name and email address in the format `Display Name <email@address.com>`. | Defaults to the GitHub Actions bot user. See [Committer and author](#committer-and-author) for details. | | `author` | The author name and email address in the format `Display Name <email@address.com>`. | Defaults to the GitHub Actions bot user. See [Committer and author](#committer-and-author) for details. |
@@ -55,7 +53,9 @@ With the exception of `token`, all inputs are **optional**. If not set, sensible
| `milestone` | The number of the milestone to associate this pull request with. | | | `milestone` | The number of the milestone to associate this pull request with. | |
| `project` | The name of the project for which a card should be created. Requires `project-column`. | | | `project` | The name of the project for which a card should be created. Requires `project-column`. | |
| `project-column` | The name of the project column under which a card should be created. Requires `project`. | | | `project-column` | The name of the project column under which a card should be created. Requires `project`. | |
| `draft` | Create a [draft pull request](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests#draft-pull-requests). | `false` |
| `branch` | The branch name. See [Branch naming](#branch-naming) for details. | `create-pull-request/patch` | | `branch` | The branch name. See [Branch naming](#branch-naming) for details. | `create-pull-request/patch` |
| `request-to-parent` | Create the pull request in the parent repository of the checked out fork. See [push pull request branches to a fork](https://github.com/peter-evans/create-pull-request/blob/master/docs/concepts-guidelines.md#push-pull-request-branches-to-a-fork) for details. | `false` |
| `base` | Sets the pull request base branch. | Defaults to the branch checked out in the workflow. | | `base` | Sets the pull request base branch. | Defaults to the branch checked out in the workflow. |
| `branch-suffix` | The branch suffix type. Valid values are `random`, `timestamp` and `short-commit-hash`. See [Branch naming](#branch-naming) for details. | | | `branch-suffix` | The branch suffix type. Valid values are `random`, `timestamp` and `short-commit-hash`. See [Branch naming](#branch-naming) for details. | |
@@ -68,8 +68,6 @@ Note that in order to read the step output the action step must have an id.
- name: Create Pull Request - name: Create Pull Request
id: cpr id: cpr
uses: peter-evans/create-pull-request@v2 uses: peter-evans/create-pull-request@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Check outputs - name: Check outputs
run: | run: |
echo "Pull Request Number - ${{ env.PULL_REQUEST_NUMBER }}" echo "Pull Request Number - ${{ env.PULL_REQUEST_NUMBER }}"
@@ -119,7 +117,6 @@ In most cases, where the committer and author are the same, just the committer c
- name: Create Pull Request - name: Create Pull Request
uses: peter-evans/create-pull-request@v2 uses: peter-evans/create-pull-request@v2
with: with:
token: ${{ secrets.GITHUB_TOKEN }}
committer: Peter Evans <peter-evans@users.noreply.github.com> committer: Peter Evans <peter-evans@users.noreply.github.com>
``` ```
@@ -143,8 +140,6 @@ As well as relying on the action to handle uncommitted changes, you can addition
run: date +%s > report.txt run: date +%s > report.txt
- name: Create Pull Request - name: Create Pull Request
uses: peter-evans/create-pull-request@v2 uses: peter-evans/create-pull-request@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
``` ```
## Reference Example ## Reference Example
@@ -181,10 +176,13 @@ jobs:
labels: report, automated pr labels: report, automated pr
assignees: peter-evans assignees: peter-evans
reviewers: peter-evans reviewers: peter-evans
team-reviewers: owners, maintainers
milestone: 1 milestone: 1
project: Example Project project: Example Project
project-column: To do project-column: To do
draft: false
branch: example-patches branch: example-patches
request-to-parent: false
- name: Check outputs - name: Check outputs
run: | run: |
echo "Pull Request Number - ${{ env.PULL_REQUEST_NUMBER }}" echo "Pull Request Number - ${{ env.PULL_REQUEST_NUMBER }}"

View File

@@ -3,7 +3,7 @@ description: 'Creates a pull request for changes to your repository in the actio
inputs: inputs:
token: token:
description: 'GITHUB_TOKEN or a repo scoped PAT' description: 'GITHUB_TOKEN or a repo scoped PAT'
required: true default: ${{ github.token }}
path: path:
description: 'Relative path under $GITHUB_WORKSPACE to the repository.' description: 'Relative path under $GITHUB_WORKSPACE to the repository.'
commit-message: commit-message:
@@ -32,6 +32,9 @@ inputs:
description: 'The name of the project column under which a card should be created.' description: 'The name of the project column under which a card should be created.'
branch: branch:
description: 'The pull request branch name.' description: 'The pull request branch name.'
request-to-parent:
description: 'Create the pull request in the parent repository of the checked out fork.'
default: false
base: base:
description: 'The pull request base branch.' description: 'The pull request base branch.'
branch-suffix: branch-suffix:

View File

@@ -4,6 +4,20 @@ from github import Github, GithubException
import os import os
def string_to_bool(str):
if str is None:
return False
else:
return str.lower() in [
"true",
"1",
"t",
"y",
"yes",
"on",
]
def cs_string_to_list(str): def cs_string_to_list(str):
# Split the comma separated string into a list # Split the comma separated string into a list
l = [i.strip() for i in str.split(",")] l = [i.strip() for i in str.split(",")]
@@ -56,25 +70,43 @@ def create_or_update_pull_request(
team_reviewers, team_reviewers,
project_name, project_name,
project_column_name, project_column_name,
draft,
request_to_parent,
): ):
github_repo = head_repo = Github(github_token).get_repo(github_repository)
if string_to_bool(request_to_parent):
github_repo = github_repo.parent
if github_repo is None:
raise ValueError(
"The checked out repository is not a fork. Input 'request-to-parent' should be set to false."
)
head_branch = f"{head_repo.owner.login}:{branch}"
# Create the pull request # Create the pull request
github_repo = Github(github_token).get_repo(github_repository)
try: try:
pull_request = github_repo.create_pull( pull_request = github_repo.create_pull(
title=title, body=body, base=base, head=branch title=title,
body=body,
base=base,
head=head_branch,
draft=string_to_bool(draft),
)
print(
f"Created pull request #{pull_request.number} ({head_branch} => {github_repo.owner.login}:{base})"
) )
print(f"Created pull request #{pull_request.number} ({branch} => {base})")
except GithubException as e: except GithubException as e:
if e.status == 422: if e.status == 422:
# A pull request exists for this branch and base # A pull request exists for this branch and base
head_branch = "{}:{}".format(github_repository.split("/")[0], branch)
# Get the pull request # Get the pull request
pull_request = github_repo.get_pulls( pull_request = github_repo.get_pulls(
state="open", base=base, head=head_branch state="open", base=base, head=head_branch
)[0] )[0]
# Update title and body # Update title and body
pull_request.as_issue().edit(title=title, body=body) pull_request.as_issue().edit(title=title, body=body)
print(f"Updated pull request #{pull_request.number} ({branch} => {base})") print(
f"Updated pull request #{pull_request.number} ({head_branch} => {github_repo.owner.login}:{base})"
)
else: else:
print(str(e)) print(str(e))
raise raise

View File

@@ -224,4 +224,6 @@ if result["action"] in ["created", "updated"]:
os.environ.get("CPR_TEAM_REVIEWERS"), os.environ.get("CPR_TEAM_REVIEWERS"),
os.environ.get("CPR_PROJECT_NAME"), os.environ.get("CPR_PROJECT_NAME"),
os.environ.get("CPR_PROJECT_COLUMN_NAME"), os.environ.get("CPR_PROJECT_COLUMN_NAME"),
os.environ.get("CPR_DRAFT"),
os.environ.get("CPR_REQUEST_TO_PARENT"),
) )

2
dist/cpr/requirements.txt vendored Normal file
View File

@@ -0,0 +1,2 @@
GitPython==3.1.0
PyGithub==1.47

377
dist/index.js vendored
View File

@@ -34,7 +34,7 @@ module.exports =
/******/ // the startup function /******/ // the startup function
/******/ function startup() { /******/ function startup() {
/******/ // Load entry module and return exports /******/ // Load entry module and return exports
/******/ return __webpack_require__(104); /******/ return __webpack_require__(676);
/******/ }; /******/ };
/******/ /******/
/******/ // run startup /******/ // run startup
@@ -973,21 +973,6 @@ module.exports = util.assign(
module.exports = require("tls"); module.exports = require("tls");
/***/ }),
/***/ 58:
/***/ (function(module, __unusedexports, __webpack_require__) {
// Unique ID creation requires a high quality random # generator. In node.js
// this is pretty straight-forward - we use the crypto API.
var crypto = __webpack_require__(417);
module.exports = function nodeRNG() {
return crypto.randomBytes(16);
};
/***/ }), /***/ }),
/***/ 87: /***/ 87:
@@ -998,109 +983,6 @@ module.exports = require("os");
/***/ }), /***/ }),
/***/ 104: /***/ 104:
/***/ (function(__unusedmodule, __unusedexports, __webpack_require__) {
const { inspect } = __webpack_require__(669);
const isDocker = __webpack_require__(160);
const core = __webpack_require__(470);
const exec = __webpack_require__(986);
const setupPython = __webpack_require__(139);
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}`);
// Determine how to access python and pip
const { pip, python } = (function() {
if (isDocker()) {
core.info("Running inside a Docker container");
// Python 3 assumed to be installed and on the PATH
return {
pip: "pip3",
python: "python3"
};
} else {
// Setup Python from the tool cache
setupPython("3.x", "x64");
return {
pip: "pip",
python: "python"
};
}
})();
// Install requirements
await exec.exec(pip, [
"install",
"--requirement",
`${src}/requirements.txt`,
"--no-index",
`--find-links=${__dirname}/vendor`
]);
// Fetch action inputs
const inputs = {
token: core.getInput("token"),
path: core.getInput("path"),
commitMessage: core.getInput("commit-message"),
committer: core.getInput("committer"),
author: core.getInput("author"),
title: core.getInput("title"),
body: core.getInput("body"),
labels: core.getInput("labels"),
assignees: core.getInput("assignees"),
reviewers: core.getInput("reviewers"),
teamReviewers: core.getInput("team-reviewers"),
milestone: core.getInput("milestone"),
project: core.getInput("project"),
projectColumn: core.getInput("project-column"),
branch: core.getInput("branch"),
base: core.getInput("base"),
branchSuffix: core.getInput("branch-suffix")
};
core.debug(`Inputs: ${inspect(inputs)}`);
// Set environment variables from inputs.
if (inputs.token) process.env.GITHUB_TOKEN = inputs.token;
if (inputs.path) process.env.CPR_PATH = inputs.path;
if (inputs.commitMessage) process.env.CPR_COMMIT_MESSAGE = inputs.commitMessage;
if (inputs.committer) process.env.CPR_COMMITTER = inputs.committer;
if (inputs.author) process.env.CPR_AUTHOR = inputs.author;
if (inputs.title) process.env.CPR_TITLE = inputs.title;
if (inputs.body) process.env.CPR_BODY = inputs.body;
if (inputs.labels) process.env.CPR_LABELS = inputs.labels;
if (inputs.assignees) process.env.CPR_ASSIGNEES = inputs.assignees;
if (inputs.reviewers) process.env.CPR_REVIEWERS = inputs.reviewers;
if (inputs.teamReviewers) process.env.CPR_TEAM_REVIEWERS = inputs.teamReviewers;
if (inputs.milestone) process.env.CPR_MILESTONE = inputs.milestone;
if (inputs.project) process.env.CPR_PROJECT_NAME = inputs.project;
if (inputs.projectColumn) process.env.CPR_PROJECT_COLUMN_NAME = inputs.projectColumn;
if (inputs.branch) process.env.CPR_BRANCH = inputs.branch;
if (inputs.base) process.env.CPR_BASE = inputs.base;
if (inputs.branchSuffix) process.env.CPR_BRANCH_SUFFIX = inputs.branchSuffix;
// Execute python script
await exec.exec(python, [`${src}/create_pull_request.py`]);
} catch (error) {
core.setFailed(error.message);
}
}
run();
/***/ }),
/***/ 129:
/***/ (function(module) {
module.exports = require("child_process");
/***/ }),
/***/ 139:
/***/ (function(module, __unusedexports, __webpack_require__) { /***/ (function(module, __unusedexports, __webpack_require__) {
const core = __webpack_require__(470); const core = __webpack_require__(470);
@@ -1157,6 +1039,28 @@ let setupPython = function(versionSpec, arch) {
module.exports = setupPython; module.exports = setupPython;
/***/ }),
/***/ 129:
/***/ (function(module) {
module.exports = require("child_process");
/***/ }),
/***/ 139:
/***/ (function(module, __unusedexports, __webpack_require__) {
// Unique ID creation requires a high quality random # generator. In node.js
// this is pretty straight-forward - we use the crypto API.
var crypto = __webpack_require__(417);
module.exports = function nodeRNG() {
return crypto.randomBytes(16);
};
/***/ }), /***/ }),
/***/ 141: /***/ 141:
@@ -4301,6 +4205,239 @@ function isUnixExecutable(stats) {
} }
//# sourceMappingURL=io-util.js.map //# sourceMappingURL=io-util.js.map
/***/ }),
/***/ 676:
/***/ (function(__unusedmodule, __unusedexports, __webpack_require__) {
const { inspect } = __webpack_require__(669);
const isDocker = __webpack_require__(160);
const core = __webpack_require__(470);
const exec = __webpack_require__(986);
const setupPython = __webpack_require__(104);
const {
getRepoPath,
getAndUnsetConfigOption,
addConfigOption
} = __webpack_require__(718);
const EXTRAHEADER_OPTION = "http.https://github.com/.extraheader";
const EXTRAHEADER_VALUE_REGEX = "^AUTHORIZATION:";
async function run() {
try {
// Allows ncc to find assets to be included in the distribution
const cpr = __webpack_require__.ab + "cpr";
core.debug(`cpr: ${cpr}`);
// Determine how to access python and pip
const { pip, python } = (function() {
if (isDocker()) {
core.info("Running inside a Docker container");
// Python 3 assumed to be installed and on the PATH
return {
pip: "pip3",
python: "python3"
};
} else {
// Setup Python from the tool cache
setupPython("3.x", "x64");
return {
pip: "pip",
python: "python"
};
}
})();
// Install requirements
await exec.exec(pip, [
"install",
"--requirement",
`${cpr}/requirements.txt`,
"--no-index",
`--find-links=${__dirname}/vendor`
]);
// Fetch action inputs
const inputs = {
token: core.getInput("token"),
path: core.getInput("path"),
commitMessage: core.getInput("commit-message"),
committer: core.getInput("committer"),
author: core.getInput("author"),
title: core.getInput("title"),
body: core.getInput("body"),
labels: core.getInput("labels"),
assignees: core.getInput("assignees"),
reviewers: core.getInput("reviewers"),
teamReviewers: core.getInput("team-reviewers"),
milestone: core.getInput("milestone"),
project: core.getInput("project"),
projectColumn: core.getInput("project-column"),
draft: core.getInput("draft"),
branch: core.getInput("branch"),
request_to_parent: core.getInput("request-to-parent"),
base: core.getInput("base"),
branchSuffix: core.getInput("branch-suffix")
};
core.debug(`Inputs: ${inspect(inputs)}`);
// Set environment variables from inputs.
if (inputs.token) process.env.GITHUB_TOKEN = inputs.token;
if (inputs.path) process.env.CPR_PATH = inputs.path;
if (inputs.commitMessage) process.env.CPR_COMMIT_MESSAGE = inputs.commitMessage;
if (inputs.committer) process.env.CPR_COMMITTER = inputs.committer;
if (inputs.author) process.env.CPR_AUTHOR = inputs.author;
if (inputs.title) process.env.CPR_TITLE = inputs.title;
if (inputs.body) process.env.CPR_BODY = inputs.body;
if (inputs.labels) process.env.CPR_LABELS = inputs.labels;
if (inputs.assignees) process.env.CPR_ASSIGNEES = inputs.assignees;
if (inputs.reviewers) process.env.CPR_REVIEWERS = inputs.reviewers;
if (inputs.teamReviewers) process.env.CPR_TEAM_REVIEWERS = inputs.teamReviewers;
if (inputs.milestone) process.env.CPR_MILESTONE = inputs.milestone;
if (inputs.project) process.env.CPR_PROJECT_NAME = inputs.project;
if (inputs.projectColumn) process.env.CPR_PROJECT_COLUMN_NAME = inputs.projectColumn;
if (inputs.draft) process.env.CPR_DRAFT = inputs.draft;
if (inputs.branch) process.env.CPR_BRANCH = inputs.branch;
if (inputs.request_to_parent) process.env.CPR_REQUEST_TO_PARENT = inputs.request_to_parent;
if (inputs.base) process.env.CPR_BASE = inputs.base;
if (inputs.branchSuffix) process.env.CPR_BRANCH_SUFFIX = inputs.branchSuffix;
// Get the repository path
var repoPath = getRepoPath(inputs.path);
// Get the extraheader config option if it exists
var extraHeaderOption = await getAndUnsetConfigOption(
repoPath,
EXTRAHEADER_OPTION,
EXTRAHEADER_VALUE_REGEX
);
// Execute create pull request
await exec.exec(python, [`${cpr}/create_pull_request.py`]);
} catch (error) {
core.setFailed(error.message);
} finally {
// Restore the extraheader config option
if (extraHeaderOption) {
if (
await addConfigOption(
repoPath,
EXTRAHEADER_OPTION,
extraHeaderOption.value
)
)
core.debug(`Restored config option '${EXTRAHEADER_OPTION}'`);
}
}
}
run();
/***/ }),
/***/ 718:
/***/ (function(module, __unusedexports, __webpack_require__) {
const core = __webpack_require__(470);
const exec = __webpack_require__(986);
const path = __webpack_require__(622);
function getRepoPath(relativePath) {
let githubWorkspacePath = process.env["GITHUB_WORKSPACE"];
if (!githubWorkspacePath) {
throw new Error("GITHUB_WORKSPACE not defined");
}
githubWorkspacePath = path.resolve(githubWorkspacePath);
core.debug(`githubWorkspacePath: ${githubWorkspacePath}`);
repoPath = githubWorkspacePath;
if (relativePath) repoPath = path.resolve(repoPath, relativePath);
core.debug(`repoPath: ${repoPath}`);
return repoPath;
}
async function execGit(repoPath, args, ignoreReturnCode = false) {
const stdout = [];
const options = {
cwd: repoPath,
ignoreReturnCode: ignoreReturnCode,
listeners: {
stdout: data => {
stdout.push(data.toString());
}
}
};
var result = {};
result.exitCode = await exec.exec("git", args, options);
result.stdout = stdout.join("");
return result;
}
async function addConfigOption(repoPath, name, value) {
const result = await execGit(
repoPath,
["config", "--local", "--add", name, value],
true
);
return result.exitCode === 0;
}
async function unsetConfigOption(repoPath, name, valueRegex=".") {
const result = await execGit(
repoPath,
["config", "--local", "--unset", name, valueRegex],
true
);
return result.exitCode === 0;
}
async function configOptionExists(repoPath, name, valueRegex=".") {
const result = await execGit(
repoPath,
["config", "--local", "--name-only", "--get-regexp", name, valueRegex],
true
);
return result.exitCode === 0;
}
async function getConfigOption(repoPath, name, valueRegex=".") {
const result = await execGit(
repoPath,
["config", "--local", "--get-regexp", name, valueRegex],
true
);
const option = result.stdout.trim().split(`${name} `);
return {
name: name,
value: option[1]
}
}
async function getAndUnsetConfigOption(repoPath, name, valueRegex=".") {
if (await configOptionExists(repoPath, name, valueRegex)) {
const option = await getConfigOption(repoPath, name, valueRegex);
if (await unsetConfigOption(repoPath, name, valueRegex)) {
core.debug(`Unset config option '${name}'`);
return option;
}
}
return null;
}
module.exports = {
getRepoPath,
execGit,
addConfigOption,
unsetConfigOption,
configOptionExists,
getConfigOption,
getAndUnsetConfigOption
};
/***/ }), /***/ }),
/***/ 722: /***/ 722:
@@ -4733,7 +4870,7 @@ module.exports = require("zlib");
/***/ 826: /***/ 826:
/***/ (function(module, __unusedexports, __webpack_require__) { /***/ (function(module, __unusedexports, __webpack_require__) {
var rng = __webpack_require__(58); var rng = __webpack_require__(139);
var bytesToUuid = __webpack_require__(722); var bytesToUuid = __webpack_require__(722);
function v4(options, buf, offset) { function v4(options, buf, offset) {

View File

@@ -1,2 +0,0 @@
GitPython==3.0.8
PyGithub==1.46

View File

@@ -1,52 +0,0 @@
const core = require("@actions/core");
const tc = require("@actions/tool-cache");
const path = require("path");
const semver = require("semver");
/**
* Setup for Python from the GitHub Actions tool cache
* Converted from https://github.com/actions/setup-python
*
* @param {string} versionSpec version of Python
* @param {string} arch architecture (x64|x32)
*/
let setupPython = function(versionSpec, arch) {
return new Promise((resolve, reject) => {
const IS_WINDOWS = process.platform === "win32";
// Find the version of Python we want in the tool cache
const installDir = tc.find("Python", versionSpec, arch);
core.debug(`installDir: ${installDir}`);
// Set paths
core.exportVariable("pythonLocation", installDir);
core.addPath(installDir);
if (IS_WINDOWS) {
core.addPath(path.join(installDir, "Scripts"));
} else {
core.addPath(path.join(installDir, "bin"));
}
if (IS_WINDOWS) {
// Add --user directory
// `installDir` from tool cache should look like $AGENT_TOOLSDIRECTORY/Python/<semantic version>/x64/
// So if `findLocalTool` succeeded above, we must have a conformant `installDir`
const version = path.basename(path.dirname(installDir));
const major = semver.major(version);
const minor = semver.minor(version);
const userScriptsDir = path.join(
process.env["APPDATA"] || "",
"Python",
`Python${major}${minor}`,
"Scripts"
);
core.addPath(userScriptsDir);
}
// On Linux and macOS, pip will create the --user directory and add it to PATH as needed.
resolve();
});
};
module.exports = setupPython;

Binary file not shown.

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

Binary file not shown.

Binary file not shown.

BIN
dist/vendor/PyGithub-1.47.tar.gz vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
dist/vendor/idna-2.9.tar.gz vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
dist/vendor/requests-2.23.0.tar.gz vendored Normal file

Binary file not shown.

BIN
dist/vendor/smmap-3.0.1.tar.gz vendored Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
dist/vendor/wrapt-1.12.1.tar.gz vendored Normal file

Binary file not shown.

View File

@@ -13,6 +13,7 @@ This document covers terminology, how the action works, general usage guidelines
- [Advanced usage](#advanced-usage) - [Advanced usage](#advanced-usage)
- [Creating pull requests in a remote repository](#creating-pull-requests-in-a-remote-repository) - [Creating pull requests in a remote repository](#creating-pull-requests-in-a-remote-repository)
- [Push using SSH (deploy keys)](#push-using-ssh-deploy-keys) - [Push using SSH (deploy keys)](#push-using-ssh-deploy-keys)
- [Push pull request branches to a fork](#push-pull-request-branches-to-a-fork)
- [Running in a container](#running-in-a-container) - [Running in a container](#running-in-a-container)
- [Creating pull requests on tag push](#creating-pull-requests-on-tag-push) - [Creating pull requests on tag push](#creating-pull-requests-on-tag-push)
@@ -161,23 +162,48 @@ How to use SSH (deploy keys) with create-pull-request action:
1. [Create a new SSH key pair](https://help.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#generating-a-new-ssh-key) for your repository. Do not set a passphrase. 1. [Create a new SSH key pair](https://help.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#generating-a-new-ssh-key) for your repository. Do not set a passphrase.
2. Copy the contents of the public key (.pub file) to a new repository [deploy key](https://developer.github.com/v3/guides/managing-deploy-keys/#deploy-keys) and check the box to "Allow write access." 2. Copy the contents of the public key (.pub file) to a new repository [deploy key](https://developer.github.com/v3/guides/managing-deploy-keys/#deploy-keys) and check the box to "Allow write access."
3. Add a secret to the repository containing the entire contents of the private key. 3. Add a secret to the repository containing the entire contents of the private key.
4. As shown in the example steps below, use the [`webfactory/ssh-agent`](https://github.com/webfactory/ssh-agent) action to install the private key and clone your repository. Remember to checkout the `base` of your pull request if it's not the default branch, e.g. `git checkout my-branch`. 4. As shown in the example below, configure `actions/checkout` to use the deploy key you have created.
```yml ```yml
steps: steps:
- uses: webfactory/ssh-agent@v0.2.0 - uses: actions/checkout@v2
with: with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Checkout via SSH
run: git clone git@github.com:peter-evans/create-pull-request.git .
# Make changes to pull request here # Make changes to pull request here
- name: Create Pull Request - name: Create Pull Request
uses: peter-evans/create-pull-request@v2 uses: peter-evans/create-pull-request@v2
```
### Push pull request branches to a fork
Instead of pushing pull request branches to the repository you want to update, you can push them to a fork of that repository.
This allows you to employ the [principle of least privilege](https://en.wikipedia.org/wiki/Principle_of_least_privilege) by using a dedicated user acting as a [machine account](https://help.github.com/en/github/site-policy/github-terms-of-service#3-account-requirements).
This user has no access to the main repository.
It will use their own fork to push code and create the pull request.
1. Create a new GitHub user and login.
2. Fork the repository that you will be creating pull requests in.
3. Create a [Personal Access Token (PAT)](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line).
4. Logout and log back in to your main user account.
5. Add a secret to your repository containing the above PAT.
6. As shown in the following example workflow, switch the git remote to the fork's URL after checkout and set the action input `request-on-parent` to `true`.
```yaml
- uses: actions/checkout@v2
- run: |
git config user.password ${{ secrets.PAT }}
git remote set-url origin https://github.com/bot-user/fork-project
git fetch --unshallow -p origin
# Make changes to pull request here
- uses: peter-evans/create-pull-request@v2
with: with:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.PAT }}
request-on-parent: true
``` ```
### Running in a container ### Running in a container
@@ -205,8 +231,6 @@ jobs:
- name: Create Pull Request - name: Create Pull Request
uses: peter-evans/create-pull-request@v2 uses: peter-evans/create-pull-request@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
``` ```
**Ubuntu container example:** **Ubuntu container example:**
@@ -230,8 +254,6 @@ jobs:
- name: Create Pull Request - name: Create Pull Request
uses: peter-evans/create-pull-request@v2 uses: peter-evans/create-pull-request@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
``` ```
### Creating pull requests on tag push ### Creating pull requests on tag push
@@ -265,7 +287,6 @@ jobs:
- name: Create Pull Request - name: Create Pull Request
uses: peter-evans/create-pull-request@v2 uses: peter-evans/create-pull-request@v2
with: with:
token: ${{ secrets.GITHUB_TOKEN }}
base: master base: master
- name: Delete tag branch - name: Delete tag branch
@@ -293,6 +314,4 @@ jobs:
- name: Create Pull Request - name: Create Pull Request
uses: peter-evans/create-pull-request@v2 uses: peter-evans/create-pull-request@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
``` ```

View File

@@ -45,7 +45,6 @@ jobs:
- name: Create Pull Request - name: Create Pull Request
uses: peter-evans/create-pull-request@v2 uses: peter-evans/create-pull-request@v2
with: with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: update authors commit-message: update authors
title: Update AUTHORS title: Update AUTHORS
body: Credit new contributors by updating AUTHORS body: Credit new contributors by updating AUTHORS
@@ -78,7 +77,6 @@ jobs:
- name: Create Pull Request - name: Create Pull Request
uses: peter-evans/create-pull-request@v2 uses: peter-evans/create-pull-request@v2
with: with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: production-promotion branch: production-promotion
``` ```
@@ -110,7 +108,6 @@ jobs:
- name: Create Pull Request - name: Create Pull Request
uses: peter-evans/create-pull-request@v2 uses: peter-evans/create-pull-request@v2
with: with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: update dependencies commit-message: update dependencies
title: Automated Dependency Updates title: Automated Dependency Updates
body: This is an auto-generated PR with dependency updates. body: This is an auto-generated PR with dependency updates.
@@ -161,7 +158,6 @@ jobs:
- name: Create Pull Request - name: Create Pull Request
uses: peter-evans/create-pull-request@v2 uses: peter-evans/create-pull-request@v2
with: with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: Update swagger-ui to ${{ steps.swagger-ui.outputs.release_tag }} commit-message: Update swagger-ui to ${{ steps.swagger-ui.outputs.release_tag }}
title: Update SwaggerUI to ${{ steps.swagger-ui.outputs.release_tag }} title: Update SwaggerUI to ${{ steps.swagger-ui.outputs.release_tag }}
body: | body: |
@@ -204,7 +200,6 @@ jobs:
- name: Create Pull Request - name: Create Pull Request
uses: peter-evans/create-pull-request@v2 uses: peter-evans/create-pull-request@v2
with: with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: update local website copy commit-message: update local website copy
title: Automated Updates to Local Website Copy title: Automated Updates to Local Website Copy
body: This is an auto-generated PR with website updates. body: This is an auto-generated PR with website updates.
@@ -299,7 +294,6 @@ jobs:
if: steps.autopep8.outputs.exit-code == 2 if: steps.autopep8.outputs.exit-code == 2
uses: peter-evans/create-pull-request@v2 uses: peter-evans/create-pull-request@v2
with: with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: autopep8 action fixes commit-message: autopep8 action fixes
title: Fixes by autopep8 action title: Fixes by autopep8 action
body: This is an auto-generated PR with fixes by autopep8. body: This is an auto-generated PR with fixes by autopep8.
@@ -358,7 +352,6 @@ The recommended method is to use [`set-output`](https://help.github.com/en/githu
- name: Create Pull Request - name: Create Pull Request
uses: peter-evans/create-pull-request@v2 uses: peter-evans/create-pull-request@v2
with: with:
token: ${{ secrets.GITHUB_TOKEN }}
title: ${{ steps.vars.outputs.pr_title }} title: ${{ steps.vars.outputs.pr_title }}
body: ${{ steps.vars.outputs.pr_body }} body: ${{ steps.vars.outputs.pr_body }}
``` ```
@@ -374,7 +367,6 @@ Alternatively, [`set-env`](https://help.github.com/en/github/automating-your-wor
- name: Create Pull Request - name: Create Pull Request
uses: peter-evans/create-pull-request@v2 uses: peter-evans/create-pull-request@v2
with: with:
token: ${{ secrets.GITHUB_TOKEN }}
title: ${{ env.PULL_REQUEST_TITLE }} title: ${{ env.PULL_REQUEST_TITLE }}
body: ${{ env.PULL_REQUEST_BODY }} body: ${{ env.PULL_REQUEST_BODY }}
``` ```

3
jest.config.js Normal file
View File

@@ -0,0 +1,3 @@
process.env = Object.assign(process.env, {
GITHUB_WORKSPACE: __dirname
});

5970
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -5,8 +5,10 @@
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"clean": "rm -rf dist", "clean": "rm -rf dist",
"build": "ncc build index.js -o dist", "lint": "eslint src/index.js",
"vendor-deps": "pip download -r src/requirements.txt --no-binary=:all: -d dist/vendor", "test": "eslint src/index.js && jest",
"build": "ncc build src/index.js -o dist",
"vendor-deps": "pip download -r src/cpr/requirements.txt --no-binary=:all: -d dist/vendor",
"package": "npm run build && npm run vendor-deps" "package": "npm run build && npm run vendor-deps"
}, },
"repository": { "repository": {
@@ -27,6 +29,8 @@
"is-docker": "^2.0.0" "is-docker": "^2.0.0"
}, },
"devDependencies": { "devDependencies": {
"@zeit/ncc": "0.21.1" "@zeit/ncc": "0.22.0",
"eslint": "6.8.0",
"jest": "25.2.7"
} }
} }

View File

@@ -4,6 +4,20 @@ from github import Github, GithubException
import os import os
def string_to_bool(str):
if str is None:
return False
else:
return str.lower() in [
"true",
"1",
"t",
"y",
"yes",
"on",
]
def cs_string_to_list(str): def cs_string_to_list(str):
# Split the comma separated string into a list # Split the comma separated string into a list
l = [i.strip() for i in str.split(",")] l = [i.strip() for i in str.split(",")]
@@ -56,25 +70,43 @@ def create_or_update_pull_request(
team_reviewers, team_reviewers,
project_name, project_name,
project_column_name, project_column_name,
draft,
request_to_parent,
): ):
github_repo = head_repo = Github(github_token).get_repo(github_repository)
if string_to_bool(request_to_parent):
github_repo = github_repo.parent
if github_repo is None:
raise ValueError(
"The checked out repository is not a fork. Input 'request-to-parent' should be set to false."
)
head_branch = f"{head_repo.owner.login}:{branch}"
# Create the pull request # Create the pull request
github_repo = Github(github_token).get_repo(github_repository)
try: try:
pull_request = github_repo.create_pull( pull_request = github_repo.create_pull(
title=title, body=body, base=base, head=branch title=title,
body=body,
base=base,
head=head_branch,
draft=string_to_bool(draft),
)
print(
f"Created pull request #{pull_request.number} ({head_branch} => {github_repo.owner.login}:{base})"
) )
print(f"Created pull request #{pull_request.number} ({branch} => {base})")
except GithubException as e: except GithubException as e:
if e.status == 422: if e.status == 422:
# A pull request exists for this branch and base # A pull request exists for this branch and base
head_branch = "{}:{}".format(github_repository.split("/")[0], branch)
# Get the pull request # Get the pull request
pull_request = github_repo.get_pulls( pull_request = github_repo.get_pulls(
state="open", base=base, head=head_branch state="open", base=base, head=head_branch
)[0] )[0]
# Update title and body # Update title and body
pull_request.as_issue().edit(title=title, body=body) pull_request.as_issue().edit(title=title, body=body)
print(f"Updated pull request #{pull_request.number} ({branch} => {base})") print(
f"Updated pull request #{pull_request.number} ({head_branch} => {github_repo.owner.login}:{base})"
)
else: else:
print(str(e)) print(str(e))
raise raise

View File

@@ -224,4 +224,6 @@ if result["action"] in ["created", "updated"]:
os.environ.get("CPR_TEAM_REVIEWERS"), os.environ.get("CPR_TEAM_REVIEWERS"),
os.environ.get("CPR_PROJECT_NAME"), os.environ.get("CPR_PROJECT_NAME"),
os.environ.get("CPR_PROJECT_COLUMN_NAME"), os.environ.get("CPR_PROJECT_COLUMN_NAME"),
os.environ.get("CPR_DRAFT"),
os.environ.get("CPR_REQUEST_TO_PARENT"),
) )

2
src/cpr/requirements.txt Normal file
View File

@@ -0,0 +1,2 @@
GitPython==3.1.0
PyGithub==1.47

97
src/git.js Normal file
View File

@@ -0,0 +1,97 @@
const core = require("@actions/core");
const exec = require("@actions/exec");
const path = require("path");
function getRepoPath(relativePath) {
let githubWorkspacePath = process.env["GITHUB_WORKSPACE"];
if (!githubWorkspacePath) {
throw new Error("GITHUB_WORKSPACE not defined");
}
githubWorkspacePath = path.resolve(githubWorkspacePath);
core.debug(`githubWorkspacePath: ${githubWorkspacePath}`);
repoPath = githubWorkspacePath;
if (relativePath) repoPath = path.resolve(repoPath, relativePath);
core.debug(`repoPath: ${repoPath}`);
return repoPath;
}
async function execGit(repoPath, args, ignoreReturnCode = false) {
const stdout = [];
const options = {
cwd: repoPath,
ignoreReturnCode: ignoreReturnCode,
listeners: {
stdout: data => {
stdout.push(data.toString());
}
}
};
var result = {};
result.exitCode = await exec.exec("git", args, options);
result.stdout = stdout.join("");
return result;
}
async function addConfigOption(repoPath, name, value) {
const result = await execGit(
repoPath,
["config", "--local", "--add", name, value],
true
);
return result.exitCode === 0;
}
async function unsetConfigOption(repoPath, name, valueRegex=".") {
const result = await execGit(
repoPath,
["config", "--local", "--unset", name, valueRegex],
true
);
return result.exitCode === 0;
}
async function configOptionExists(repoPath, name, valueRegex=".") {
const result = await execGit(
repoPath,
["config", "--local", "--name-only", "--get-regexp", name, valueRegex],
true
);
return result.exitCode === 0;
}
async function getConfigOption(repoPath, name, valueRegex=".") {
const result = await execGit(
repoPath,
["config", "--local", "--get-regexp", name, valueRegex],
true
);
const option = result.stdout.trim().split(`${name} `);
return {
name: name,
value: option[1]
}
}
async function getAndUnsetConfigOption(repoPath, name, valueRegex=".") {
if (await configOptionExists(repoPath, name, valueRegex)) {
const option = await getConfigOption(repoPath, name, valueRegex);
if (await unsetConfigOption(repoPath, name, valueRegex)) {
core.debug(`Unset config option '${name}'`);
return option;
}
}
return null;
}
module.exports = {
getRepoPath,
execGit,
addConfigOption,
unsetConfigOption,
configOptionExists,
getConfigOption,
getAndUnsetConfigOption
};

98
src/git.test.js Normal file
View File

@@ -0,0 +1,98 @@
const path = require("path");
const {
getRepoPath,
execGit,
addConfigOption,
unsetConfigOption,
configOptionExists,
getConfigOption,
getAndUnsetConfigOption
} = require("./git");
test("getRepoPath", async () => {
expect(getRepoPath()).toEqual(process.env["GITHUB_WORKSPACE"]);
expect(getRepoPath("foo")).toEqual(
path.resolve(process.env["GITHUB_WORKSPACE"], "foo")
);
});
test("execGit", async () => {
const repoPath = getRepoPath();
const result = await execGit(
repoPath,
["config", "--local", "--name-only", "--get-regexp", "remote.origin.url"],
true
);
expect(result.exitCode).toEqual(0);
expect(result.stdout.trim()).toEqual("remote.origin.url");
});
test("add and unset config option", async () => {
const repoPath = getRepoPath();
const add = await addConfigOption(repoPath, "test.add.and.unset.config.option", "foo");
expect(add).toBeTruthy();
const unset = await unsetConfigOption(repoPath, "test.add.and.unset.config.option");
expect(unset).toBeTruthy();
});
test("add and unset config option with value regex", async () => {
const repoPath = getRepoPath();
const add = await addConfigOption(repoPath, "test.add.and.unset.config.option", "foo bar");
expect(add).toBeTruthy();
const unset = await unsetConfigOption(repoPath, "test.add.and.unset.config.option", "^foo");
expect(unset).toBeTruthy();
});
test("configOptionExists returns true", async () => {
const repoPath = getRepoPath();
const result = await configOptionExists(repoPath, "remote.origin.url");
expect(result).toBeTruthy();
});
test("configOptionExists returns false", async () => {
const repoPath = getRepoPath();
const result = await configOptionExists(repoPath, "this.key.does.not.exist");
expect(result).toBeFalsy();
});
test("get config option", async () => {
const repoPath = getRepoPath();
const add = await addConfigOption(repoPath, "test.get.config.option", "foo");
expect(add).toBeTruthy();
const option = await getConfigOption(repoPath, "test.get.config.option");
expect(option.value).toEqual("foo");
const unset = await unsetConfigOption(repoPath, "test.get.config.option");
expect(unset).toBeTruthy();
});
test("get config option with value regex", async () => {
const repoPath = getRepoPath();
const add = await addConfigOption(repoPath, "test.get.config.option", "foo bar");
expect(add).toBeTruthy();
const option = await getConfigOption(repoPath, "test.get.config.option", "^foo");
expect(option.value).toEqual("foo bar");
const unset = await unsetConfigOption(repoPath, "test.get.config.option", "^foo");
expect(unset).toBeTruthy();
});
test("get and unset config option is successful", async () => {
const repoPath = getRepoPath();
const add = await addConfigOption(repoPath, "test.get.and.unset.config.option", "foo");
expect(add).toBeTruthy();
const getAndUnset = await getAndUnsetConfigOption(repoPath, "test.get.and.unset.config.option");
expect(getAndUnset.value).toEqual("foo");
});
test("get and unset config option is successful with value regex", async () => {
const repoPath = getRepoPath();
const add = await addConfigOption(repoPath, "test.get.and.unset.config.option", "foo bar");
expect(add).toBeTruthy();
const getAndUnset = await getAndUnsetConfigOption(repoPath, "test.get.and.unset.config.option", "^foo");
expect(getAndUnset.value).toEqual("foo bar");
});
test("get and unset config option is unsuccessful", async () => {
const repoPath = getRepoPath();
const getAndUnset = await getAndUnsetConfigOption(repoPath, "this.key.does.not.exist");
expect(getAndUnset).toBeNull();
});

View File

@@ -2,13 +2,21 @@ const { inspect } = require("util");
const isDocker = require("is-docker"); const isDocker = require("is-docker");
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("./setup-python");
const {
getRepoPath,
getAndUnsetConfigOption,
addConfigOption
} = require("./git");
const EXTRAHEADER_OPTION = "http.https://github.com/.extraheader";
const EXTRAHEADER_VALUE_REGEX = "^AUTHORIZATION:";
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 cpr = __dirname + "/cpr";
core.debug(`src: ${src}`); core.debug(`cpr: ${cpr}`);
// Determine how to access python and pip // Determine how to access python and pip
const { pip, python } = (function() { const { pip, python } = (function() {
@@ -33,7 +41,7 @@ async function run() {
await exec.exec(pip, [ await exec.exec(pip, [
"install", "install",
"--requirement", "--requirement",
`${src}/requirements.txt`, `${cpr}/requirements.txt`,
"--no-index", "--no-index",
`--find-links=${__dirname}/vendor` `--find-links=${__dirname}/vendor`
]); ]);
@@ -54,7 +62,9 @@ async function run() {
milestone: core.getInput("milestone"), milestone: core.getInput("milestone"),
project: core.getInput("project"), project: core.getInput("project"),
projectColumn: core.getInput("project-column"), projectColumn: core.getInput("project-column"),
draft: core.getInput("draft"),
branch: core.getInput("branch"), branch: core.getInput("branch"),
request_to_parent: core.getInput("request-to-parent"),
base: core.getInput("base"), base: core.getInput("base"),
branchSuffix: core.getInput("branch-suffix") branchSuffix: core.getInput("branch-suffix")
}; };
@@ -75,14 +85,37 @@ async function run() {
if (inputs.milestone) process.env.CPR_MILESTONE = inputs.milestone; if (inputs.milestone) process.env.CPR_MILESTONE = inputs.milestone;
if (inputs.project) process.env.CPR_PROJECT_NAME = inputs.project; if (inputs.project) process.env.CPR_PROJECT_NAME = inputs.project;
if (inputs.projectColumn) process.env.CPR_PROJECT_COLUMN_NAME = inputs.projectColumn; if (inputs.projectColumn) process.env.CPR_PROJECT_COLUMN_NAME = inputs.projectColumn;
if (inputs.draft) process.env.CPR_DRAFT = inputs.draft;
if (inputs.branch) process.env.CPR_BRANCH = inputs.branch; if (inputs.branch) process.env.CPR_BRANCH = inputs.branch;
if (inputs.request_to_parent) process.env.CPR_REQUEST_TO_PARENT = inputs.request_to_parent;
if (inputs.base) process.env.CPR_BASE = inputs.base; if (inputs.base) process.env.CPR_BASE = inputs.base;
if (inputs.branchSuffix) process.env.CPR_BRANCH_SUFFIX = inputs.branchSuffix; if (inputs.branchSuffix) process.env.CPR_BRANCH_SUFFIX = inputs.branchSuffix;
// Execute python script // Get the repository path
await exec.exec(python, [`${src}/create_pull_request.py`]); var repoPath = getRepoPath(inputs.path);
// Get the extraheader config option if it exists
var extraHeaderOption = await getAndUnsetConfigOption(
repoPath,
EXTRAHEADER_OPTION,
EXTRAHEADER_VALUE_REGEX
);
// Execute create pull request
await exec.exec(python, [`${cpr}/create_pull_request.py`]);
} catch (error) { } catch (error) {
core.setFailed(error.message); core.setFailed(error.message);
} finally {
// Restore the extraheader config option
if (extraHeaderOption) {
if (
await addConfigOption(
repoPath,
EXTRAHEADER_OPTION,
extraHeaderOption.value
)
)
core.debug(`Restored config option '${EXTRAHEADER_OPTION}'`);
}
} }
} }

View File

@@ -1,2 +0,0 @@
GitPython==3.0.8
PyGithub==1.46