Compare commits

...

587 Commits

Author SHA1 Message Date
20dac2ed48 build: update distribution (#1208)
Co-authored-by: peter-evans <peter-evans@users.noreply.github.com>
2022-08-17 12:37:21 +09:00
8557470a68 feat: support no_proxy environment variable (#1205)
Co-authored-by: TGANSTE <till.ganster@mercedes-benz.com>
2022-08-17 12:25:36 +09:00
10db75894f docs: add info about workflow permissions 2022-06-08 17:57:28 +09:00
5a6b15373e docs: clearer description of update behaviour 2022-06-08 17:30:26 +09:00
923ad837f1 force tryFetch (#1189) 2022-06-03 17:30:50 +09:00
f094b77505 fix: avoid issue with case sensitivity of repo names (#1179)
* fix: avoid issue with case sensitivity in condition

* chore: upgrade jest to v28
2022-05-08 17:37:36 +09:00
af7c021bb9 docs: shorten quote 2022-04-22 14:27:14 +09:00
97872c4843 docs: update GA quote/ref in concepts-guidelines.md (#1169)
* Update GA quote/ref in concepts-guidelines.md

The current quote and reference link appear to be out of date

* Change "Triggering further workflow runs" excerpt
2022-04-14 08:39:38 +09:00
bd72e1b792 fix: use full name for head branch to allow for repo renaming (#1164) 2022-04-08 21:38:55 +09:00
f1a7646cea build: update distribution (#1157)
Co-authored-by: peter-evans <peter-evans@users.noreply.github.com>
2022-03-31 17:14:30 +09:00
15b68d176d fix: strip optional '.git' suffix from https server remote name. (#1153)
* Strip optional '.git' suffix from https server remote name.

* Revert "Strip optional '.git' suffix from https server remote name."

This reverts commit c2e9041213.

* Strip optional '.git' suffix from https server remote name.
2022-03-31 17:10:39 +09:00
0dfc93c104 build(deps): bump peter-evans/create-pull-request from 3 to 4 (#1150) 2022-03-28 21:33:19 +09:00
252fb19db2 build(deps): bump peter-evans/slash-command-dispatch from 2 to 3 (#1122)
Bumps [peter-evans/slash-command-dispatch](https://github.com/peter-evans/slash-command-dispatch) from 2 to 3.
- [Release notes](https://github.com/peter-evans/slash-command-dispatch/releases)
- [Commits](https://github.com/peter-evans/slash-command-dispatch/compare/v2...v3)

---
updated-dependencies:
- dependency-name: peter-evans/slash-command-dispatch
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-03-23 14:31:35 +09:00
4b867c4939 build(deps): bump actions/setup-node from 2 to 3 (#1123)
Bumps [actions/setup-node](https://github.com/actions/setup-node) from 2 to 3.
- [Release notes](https://github.com/actions/setup-node/releases)
- [Commits](https://github.com/actions/setup-node/compare/v2...v3)

---
updated-dependencies:
- dependency-name: actions/setup-node
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-03-23 14:31:11 +09:00
4fb3835236 build(deps): bump peter-evans/close-pull from 1 to 2 (#1121)
Bumps [peter-evans/close-pull](https://github.com/peter-evans/close-pull) from 1 to 2.
- [Release notes](https://github.com/peter-evans/close-pull/releases)
- [Commits](https://github.com/peter-evans/close-pull/compare/v1...v2)

---
updated-dependencies:
- dependency-name: peter-evans/close-pull
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-03-23 14:29:36 +09:00
19ace475b4 build(deps): bump peter-evans/create-or-update-comment from 1 to 2 (#1120)
Bumps [peter-evans/create-or-update-comment](https://github.com/peter-evans/create-or-update-comment) from 1 to 2.
- [Release notes](https://github.com/peter-evans/create-or-update-comment/releases)
- [Commits](https://github.com/peter-evans/create-or-update-comment/compare/v1...v2)

---
updated-dependencies:
- dependency-name: peter-evans/create-or-update-comment
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-03-23 14:29:17 +09:00
84d431ad62 build(deps): bump peter-evans/find-comment from 1 to 2 (#1119)
Bumps [peter-evans/find-comment](https://github.com/peter-evans/find-comment) from 1 to 2.
- [Release notes](https://github.com/peter-evans/find-comment/releases)
- [Commits](https://github.com/peter-evans/find-comment/compare/v1...v2)

---
updated-dependencies:
- dependency-name: peter-evans/find-comment
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-03-23 14:28:50 +09:00
d6d5519d05 v4 (#1099)
* feat: update action runtime to node 16

* feat: allow add-paths to resolve to no changes

* docs: update readme

* chore: update package lock

* chore: bump dependency

* ci: add dependabot workflow

* docs: update action versions
2022-03-23 14:22:01 +09:00
0e8dfbd57d docs: update guidelines 2022-03-11 13:46:10 +09:00
ffa8cc2261 docs: Skip follow-up steps if there is no pull request (#1083) 2022-03-09 12:40:44 +09:00
00fb6900cb docs: Document how to improve close-and-reopen user experience (#1084) 2022-03-09 12:38:41 +09:00
2fe7e77753 docs: Add word "permissions" (#1082) 2022-03-09 10:46:31 +09:00
18f7dc018c feat: revert update action runtime to node 16 2022-02-28 21:17:05 +09:00
89265e8d24 feat: update action runtime to node 16 (#1074)
* fix: prefer getMultilineInput and getBooleanInput from actions/core

* build: update distribution

* feat: update action runtime to node 16

* ci: update setup-node and cache npm dependencies

* revert: getMultilineInput to getInputAsArray

* build: update distribution
2022-02-28 13:55:51 +09:00
a7bb76508d fix: remove unused draft param from pull update (#1065) 2022-02-23 15:34:53 +09:00
357cebe268 Document that draft status changes are not reflected (#1064)
The github pull request update API does not accept changing
draft status - the only way to do it appears to be through
the web UI.
2022-02-23 15:18:03 +09:00
f22a7da129 fix: add '--' to checkout command to avoid ambiguity (#1051)
* fix: add '--' to checkout command to avoid ambiguity

Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp>

* Update src/git-command-manager.ts

Co-authored-by: Peter Evans <18365890+peter-evans@users.noreply.github.com>

Co-authored-by: Peter Evans <18365890+peter-evans@users.noreply.github.com>
2022-01-31 09:49:59 +09:00
3f60247108 ci: remove workflow (#1046) 2022-01-28 11:42:48 +09:00
dcd5fd746d feat: add-paths input (#1010)
* add add-pattern-array argument

* ignore return code

* doc to add-pattern-array

* update README.md

* cleanup after success commit

* fix integration tests

* add test

* update naming and docs

* update readme

* fix missing await

* update docs

Co-authored-by: avdim <avdim@mail.ru>
Co-authored-by: Авдеев Дима <avdeev@tutu.tech>
2021-12-14 11:23:29 +09:00
4b53b6fd1a Merge pull request #967 from peter-evans/update-dependencies
Update dependencies
2021-12-02 12:02:05 +09:00
10a1849302 chore: update dist 2021-12-02 11:19:12 +09:00
c209d72428 chore: update package lock 2021-12-02 11:18:20 +09:00
ef9e028216 fix: resolving path to module 2021-12-02 11:17:26 +09:00
f8f85df783 chore: update dependencies 2021-12-02 01:25:39 +00:00
b9117f2e0c Merge pull request #992 from MichaelCurrin/patch-1
docs: update marketplace logo
2021-12-02 08:56:24 +09:00
598ffcd35c docs: update marketplace logo 2021-12-01 12:59:42 +02:00
d8e8e547cc Merge pull request #986 from irphilli/docs/github-app-permissions
docs: Update to include app permissions needed to add teams as reviewers
2021-11-15 09:14:49 +09:00
507420e035 docs: Update to include app permissions needed to add teams as reviewers 2021-11-12 12:26:36 -06:00
67df31e08a fix: add head sha output to action.yml 2021-11-04 11:13:50 +09:00
f530141cd3 Merge pull request #981 from peter-evans/update-distribution
Update distribution
2021-11-04 11:07:54 +09:00
a5a72ba246 build: update distribution 2021-11-04 02:07:25 +00:00
a6c8b3814a Merge pull request #976 from peter-evans/output-sha
feat: add output for head sha
2021-11-04 11:04:47 +09:00
c0a9598b0e feat: add output for head sha 2021-11-04 10:42:17 +09:00
3c3d696d5b Merge pull request #955 from peter-evans/dependabot/npm_and_yarn/ansi-regex-5.0.1
build(deps): bump ansi-regex from 5.0.0 to 5.0.1
2021-10-07 11:09:44 +09:00
bd0f84d69c Merge pull request #958 from peter-evans/update-distribution
Update distribution
2021-10-07 10:50:19 +09:00
ad71e1f128 build: update distribution 2021-10-07 01:48:29 +00:00
368c9da6f6 build(deps): bump ansi-regex from 5.0.0 to 5.0.1
Bumps [ansi-regex](https://github.com/chalk/ansi-regex) from 5.0.0 to 5.0.1.
- [Release notes](https://github.com/chalk/ansi-regex/releases)
- [Commits](https://github.com/chalk/ansi-regex/compare/v5.0.0...v5.0.1)

---
updated-dependencies:
- dependency-name: ansi-regex
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-10-07 01:46:56 +00:00
d8a389d1fa Merge pull request #932 from peter-evans/update-dependencies
Update dependencies
2021-10-07 10:46:28 +09:00
225cf628aa chore: update dependencies 2021-10-07 01:25:48 +00:00
d7a8d0affc ci: revert test of new scd version
This reverts commit 2dc79e58de.
2021-09-17 09:59:51 +09:00
2dc79e58de ci: test new scd version 2021-09-16 14:56:26 +09:00
95767e7d51 Merge pull request #894 from peter-evans/update-dependencies
Update dependencies
2021-09-02 14:10:28 +09:00
3263596ac4 fix: set error types to any 2021-09-02 13:59:32 +09:00
3e21ec0c82 chore: update package-lock 2021-09-02 13:54:47 +09:00
5050a372c9 chore: update dependencies 2021-09-02 01:24:01 +00:00
7380612b49 Merge pull request #915 from peter-evans/missing-outputs
fix: add missing outputs
2021-08-23 12:59:53 +09:00
771ad1b5f4 fix: add missing outputs 2021-08-23 12:51:26 +09:00
093c191148 Merge pull request #903 from peter-evans/failure-mode-test
test: add test for detached head failure mode
2021-08-13 11:47:40 +09:00
00cb0abb4d build: update package lock version 2021-08-13 11:35:07 +09:00
fa0950476f test: add test for detached head failure mode 2021-08-13 11:34:19 +09:00
b90b9c1e20 Merge pull request #890 from peter-evans/update-distribution
Update distribution
2021-07-22 11:05:37 +09:00
028a63020c build: update distribution 2021-07-22 02:05:00 +00:00
9d59234a82 Merge pull request #864 from peter-evans/update-dependencies
Update dependencies
2021-07-22 11:02:56 +09:00
210f7aab2c chore: update dependencies 2021-07-22 01:26:10 +00:00
6bb7394339 Merge pull request #850 from peter-evans/update-distribution
Update distribution
2021-05-27 13:22:56 +09:00
a518698c07 build: update distribution 2021-05-27 04:20:57 +00:00
8be395fdd3 Merge pull request #834 from peter-evans/update-dependencies
Update dependencies
2021-05-27 13:18:59 +09:00
36d063872e chore: update dependencies 2021-05-27 01:32:21 +00:00
9825ae65b1 Merge pull request #837 from peter-evans/proxy-support
feat: add support for https_proxy env var
2021-05-24 15:11:36 +09:00
243251cf92 docs: update readme 2021-05-24 15:06:55 +09:00
28beef91aa feat: add support for https_proxy env var 2021-05-22 09:32:10 +09:00
01f7dd1d28 Merge pull request #829 from peter-evans/logging
fix: improve logging
2021-05-14 13:58:45 +09:00
32c71c837c fix: improve logging 2021-05-14 13:47:55 +09:00
a6d621d73e Merge pull request #820 from peter-evans/dependabot/npm_and_yarn/hosted-git-info-2.8.9
build(deps): bump hosted-git-info from 2.8.8 to 2.8.9
2021-05-13 13:18:59 +09:00
09f51e6391 Merge pull request #819 from peter-evans/dependabot/npm_and_yarn/lodash-4.17.21
build(deps): bump lodash from 4.17.19 to 4.17.21
2021-05-13 13:09:37 +09:00
ed04db61de build(deps): bump hosted-git-info from 2.8.8 to 2.8.9
Bumps [hosted-git-info](https://github.com/npm/hosted-git-info) from 2.8.8 to 2.8.9.
- [Release notes](https://github.com/npm/hosted-git-info/releases)
- [Changelog](https://github.com/npm/hosted-git-info/blob/v2.8.9/CHANGELOG.md)
- [Commits](https://github.com/npm/hosted-git-info/compare/v2.8.8...v2.8.9)

Signed-off-by: dependabot[bot] <support@github.com>
2021-05-13 03:57:30 +00:00
ea6b55fc9d build(deps): bump lodash from 4.17.19 to 4.17.21
Bumps [lodash](https://github.com/lodash/lodash) from 4.17.19 to 4.17.21.
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](https://github.com/lodash/lodash/compare/4.17.19...4.17.21)

Signed-off-by: dependabot[bot] <support@github.com>
2021-05-13 03:57:16 +00:00
88896f707d Merge pull request #816 from peter-evans/update-distribution
Update distribution
2021-05-13 12:51:15 +09:00
423630f7c0 build: update distribution 2021-05-13 03:50:34 +00:00
66cc0cc1e2 Merge pull request #776 from peter-evans/update-dependencies
Update dependencies
2021-05-13 12:48:13 +09:00
2a63057d1e chore: update dependencies 2021-05-13 02:16:24 +00:00
f83efdc34a docs: update default branch 2021-05-13 09:53:24 +09:00
fff683e9ca docs: update default branch 2021-05-13 09:43:00 +09:00
9f83247b25 ci: update default branch 2021-05-13 09:42:47 +09:00
670e508eb6 docs: update readme 2021-05-11 10:12:39 +09:00
d9d6fd980e Merge pull request #804 from peter-evans/gpg-sign-fix
fix: remove unnecessary gpg-sign input
2021-05-10 09:19:01 +09:00
8bb8511e4d fix: remove unnecessary gpg-sign input 2021-05-10 09:01:53 +09:00
c1d92ef456 docs: update readme 2021-05-09 14:44:37 +09:00
1ff93da091 Merge pull request #795 from peter-evans/gpg-sign
feat: add input to enable gpg commit signing
2021-05-09 14:15:03 +09:00
0524c01297 feat: add input to enable gpg commit signing 2021-05-09 10:14:59 +09:00
548adff9dc docs: update examples 2021-04-09 15:03:53 +09:00
28674474a4 docs: add link to github blog post 2021-04-06 10:46:44 +09:00
4fb90330a4 Merge pull request #773 from peter-evans/update-distribution
Update distribution
2021-04-01 12:08:39 +09:00
e4c811acf5 build: update distribution 2021-04-01 03:07:25 +00:00
99ccb3479b Merge pull request #759 from peter-evans/update-dependencies
Update dependencies
2021-04-01 12:05:05 +09:00
13616a4432 fix: update octokit rest methods 2021-04-01 11:56:16 +09:00
b5b91bc2b0 chore: update dependencies 2021-04-01 01:28:21 +00:00
5666cd8fe9 Merge pull request #755 from peter-evans/update-distribution
Update distribution
2021-03-16 11:35:49 +09:00
ad897490d5 build: update distribution 2021-03-16 02:35:04 +00:00
0735106af9 Merge pull request #744 from peter-evans/update-dependencies
Update dependencies
2021-03-16 11:31:26 +09:00
9aeedaa8c2 fix: remove unnecessary prettier config 2021-03-16 11:16:45 +09:00
52d31873b6 chore: update dependencies 2021-03-11 01:43:57 +00:00
09b9ac155b Merge pull request #740 from peter-evans/update-distribution
Update distribution
2021-02-25 11:22:27 +09:00
6ec5e3e26b build: update distribution 2021-02-25 02:20:17 +00:00
8b46437b6d Merge pull request #709 from peter-evans/update-dependencies
Update dependencies
2021-02-25 11:17:55 +09:00
e361fd1788 chore: update dependencies 2021-02-25 01:38:41 +00:00
052fc72b41 Merge pull request #724 from peter-evans/fix-assignees
fix: use the correct assignees property
2021-02-10 09:28:28 +09:00
ed00d4629c fix: use the correct assignees property 2021-02-10 09:00:23 +09:00
34371f09e5 Merge pull request #719 from peter-evans/add-to-lists
fix: add to labels and assignees instead of resetting
2021-02-08 10:19:41 +09:00
c27ea51ae0 fix: add to labels and assignees instead of resetting 2021-02-08 09:32:46 +09:00
5e9d0ee9ea Merge pull request #712 from peter-evans/operation-output
feat: add pull-request-operation output
2021-02-01 10:28:29 +09:00
b5f41d9b08 feat: add pull-request-operation output 2021-02-01 09:57:11 +09:00
2455e15969 Merge pull request #704 from jonico/support-ghes
Support GitHub Enterprise Server
2021-01-26 11:17:38 +09:00
05bc46786e Support GitHub Server API URL
* pass GitHub Server API in Octokkit constructor
2021-01-25 19:16:19 +01:00
adc6552966 Support GitHub Enterprise Server
* parse GITHUB_SERVER_URL if present
* accept proper server remotes as well
2021-01-25 18:25:20 +01:00
171fc6cce4 Merge pull request #701 from peter-evans/update-distribution
Update distribution
2021-01-25 14:22:27 +09:00
3fb765f674 build: update distribution 2021-01-25 05:19:37 +00:00
d95c81ee98 Merge pull request #686 from peter-evans/update-dependencies
Update dependencies
2021-01-25 14:16:59 +09:00
8d5ed6557f chore: update dependencies 2021-01-21 02:46:33 +00:00
7b1819c092 Merge pull request #683 from peter-evans/update-distribution
Update distribution
2020-12-28 10:22:06 +09:00
be0a8c9666 build: update distribution 2020-12-28 01:20:44 +00:00
a0a6157bf1 Merge pull request #594 from peter-evans/update-dependencies
Update dependencies
2020-12-28 10:18:18 +09:00
9c5ec2e07d chore: update dependencies 2020-12-24 02:04:52 +00:00
45c510e1f6 Merge pull request #672 from peter-evans/reset-perf
perf: git reset instead of fetch
2020-12-23 14:28:23 +09:00
249b80db6b perf: git reset instead of fetch 2020-12-23 14:10:40 +09:00
6c2b44c6ac Merge pull request #666 from peter-evans/dependabot/npm_and_yarn/node-notifier-8.0.1
build(deps): bump node-notifier from 8.0.0 to 8.0.1
2020-12-23 09:48:12 +09:00
76c58cf6a9 build(deps): bump node-notifier from 8.0.0 to 8.0.1
Bumps [node-notifier](https://github.com/mikaelbr/node-notifier) from 8.0.0 to 8.0.1.
- [Release notes](https://github.com/mikaelbr/node-notifier/releases)
- [Changelog](https://github.com/mikaelbr/node-notifier/blob/v8.0.1/CHANGELOG.md)
- [Commits](https://github.com/mikaelbr/node-notifier/compare/v8.0.0...v8.0.1)

Signed-off-by: dependabot[bot] <support@github.com>
2020-12-22 13:17:50 +00:00
8c603dbb04 Merge pull request #653 from peter-evans/fix-error-handling
fix: change or->and to catch all errors
2020-12-09 09:56:23 +09:00
d01e0807ef fix: change or->and to catch all errors 2020-12-09 09:38:10 +09:00
ce699aa2d1 Merge pull request #637 from peter-evans/prune-remote
fix: prune stale remote ref for self-hosted runners
2020-11-25 12:40:23 +09:00
9984f611a7 fix: prune stale remote ref for self-hosted runners 2020-11-24 12:34:57 +09:00
ff0beed1b2 Merge pull request #627 from peter-evans/git-diff-perf
perf: set diff quiet and switch isdirty command order
2020-11-17 13:22:44 +09:00
ddeca94037 perf: set diff quiet and switch isdirty command order 2020-11-17 11:42:31 +09:00
0fd77ba8cc docs: add missing contents link 2020-10-26 09:23:01 +09:00
c7f493a800 docs: remove deprecated set-env example 2020-10-02 15:53:49 +09:00
91664dfb28 Merge pull request #604 from peter-evans/update-distribution
Update distribution
2020-10-02 15:18:04 +09:00
13ec5274b1 build: update distribution 2020-10-02 06:17:23 +00:00
bcf9790963 Merge pull request #599 from peter-evans/dependabot/npm_and_yarn/actions/core-1.2.6
Bump @actions/core from 1.2.5 to 1.2.6
2020-10-02 15:14:43 +09:00
88ea447de7 Bump @actions/core from 1.2.5 to 1.2.6
Bumps [@actions/core](https://github.com/actions/toolkit/tree/HEAD/packages/core) from 1.2.5 to 1.2.6.
- [Release notes](https://github.com/actions/toolkit/releases)
- [Changelog](https://github.com/actions/toolkit/blob/main/packages/core/RELEASES.md)
- [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/core)

Signed-off-by: dependabot[bot] <support@github.com>
2020-10-01 17:24:16 +00:00
da928d5fcc Merge pull request #587 from peter-evans/url-output
feat: output the pull request url
2020-09-17 11:18:34 +09:00
2465e435b9 feat: output the pull request url 2020-09-17 10:41:26 +09:00
37b2bd1eca Merge pull request #584 from peter-evans/update-distribution
Update distribution
2020-09-17 10:39:30 +09:00
eb13e17e17 build: update distribution 2020-09-17 01:38:44 +00:00
a1ecc20658 Merge pull request #565 from peter-evans/update-dependencies
Update dependencies
2020-09-17 10:36:25 +09:00
ffcad23634 chore: update dependencies 2020-09-17 01:15:53 +00:00
f4b52b768a Merge pull request #574 from peter-evans/update-distribution
Update distribution
2020-09-13 15:13:25 +09:00
af682c8fcb build: update distribution 2020-09-13 06:11:21 +00:00
7378b23cb0 Merge pull request #569 from peter-evans/dependabot/npm_and_yarn/node-fetch-2.6.1
Bump node-fetch from 2.6.0 to 2.6.1
2020-09-13 15:08:27 +09:00
370ae6d537 Bump node-fetch from 2.6.0 to 2.6.1
Bumps [node-fetch](https://github.com/bitinn/node-fetch) from 2.6.0 to 2.6.1.
- [Release notes](https://github.com/bitinn/node-fetch/releases)
- [Changelog](https://github.com/node-fetch/node-fetch/blob/master/docs/CHANGELOG.md)
- [Commits](https://github.com/bitinn/node-fetch/compare/v2.6.0...v2.6.1)

Signed-off-by: dependabot[bot] <support@github.com>
2020-09-12 21:49:56 +00:00
ae0797ee12 ci: update commit message type 2020-09-07 17:25:24 +09:00
e05457394a ci: update commit messages 2020-09-07 15:26:59 +09:00
44f76dd5b3 Merge pull request #558 from peter-evans/update-distribution
Update distribution
2020-09-07 09:30:37 +09:00
279e66ed27 Update distribution 2020-09-07 00:29:59 +00:00
ce9dd3641e Merge pull request #511 from peter-evans/update-dependencies
Update dependencies
2020-09-07 09:27:33 +09:00
1a00b34382 Update dependencies 2020-09-07 09:18:17 +09:00
e17bb55cb7 Merge pull request #547 from peter-evans/delete-branch
feat: add input for branch delete
2020-09-07 09:14:08 +09:00
1890e1ec35 Merge pull request #537 from peter-evans/squash-merge-fix
fix: reset branches to handle squash merge
2020-09-07 09:10:33 +09:00
a49ee3308e feat: add input for branch delete 2020-09-06 10:21:35 +09:00
16fa12ee5f fix: reset branches to handle squash merge 2020-09-06 08:55:33 +09:00
5ea31358e9 docs: updates related to checkout 2020-09-01 09:15:45 +09:00
105f0d3816 docs: update examples 2020-08-30 15:17:23 +09:00
8fb2374109 docs: update readme 2020-08-30 11:20:42 +09:00
a68328a1ee docs: update concepts-guidelines 2020-08-30 11:06:03 +09:00
9bf4b302a5 Merge pull request #526 from peter-evans/detached-head
feat: support checkout on a commit in addition to a ref
2020-08-30 10:02:44 +09:00
da6a868b86 docs: update readme 2020-08-30 09:55:17 +09:00
cbd5e97fef docs: update concepts-guidelines 2020-08-30 09:55:07 +09:00
095c53659b feat: support checkout on a commit in addition to a ref 2020-08-29 17:28:46 +09:00
fc687f898b docs: update examples 2020-08-25 12:18:25 +09:00
3b32bfa4f7 Merge pull request #517 from peter-evans/update-ncc
Change zeit to vercel
2020-08-22 11:51:38 +09:00
9c3bf74d10 Change zeit to vercel 2020-08-22 11:42:42 +09:00
b9ed02107c Update documentation 2020-08-22 11:11:38 +09:00
2f31350598 Remove unused slash command 2020-08-20 14:31:41 +09:00
d14206169d Update documentation 2020-08-19 18:29:04 +09:00
82c423c73b Merge pull request #508 from peter-evans/update-distribution
Update distribution
2020-08-19 17:40:53 +09:00
7cf22579c6 Update distribution 2020-08-19 08:39:31 +00:00
5893420513 Merge pull request #503 from peter-evans/not-updated-fix
Fix pr create/update for already up to date branches
2020-08-19 17:37:01 +09:00
8bdec9b230 Fix pr create/update for already up to date branches 2020-08-19 17:08:59 +09:00
2570a753e0 Merge pull request #497 from peter-evans/branch-check-fix
Fix branch naming check for push-to-fork
2020-08-19 14:27:34 +09:00
1c466bedd5 Fix branch naming check for push-to-fork 2020-08-19 12:22:50 +09:00
a755ad5ffb Merge pull request #492 from peter-evans/update-distribution
Update distribution
2020-08-19 12:21:35 +09:00
52cabd40b9 Update distribution 2020-08-19 03:20:28 +00:00
12b7e7a141 Merge pull request #467 from peter-evans/update-dependencies
Update dependencies
2020-08-19 12:18:09 +09:00
8f96fd0252 Merge pull request #488 from jsoref/spelling
Spelling
2020-08-19 12:09:20 +09:00
5f45e30ff9 spelling: uncommitted
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2020-08-18 12:51:12 -04:00
348abed1de spelling: javascript
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2020-08-17 23:27:12 -04:00
06ab0ad94e Update documentation 2020-08-16 13:34:15 +09:00
de6e791e81 Update documentation 2020-08-15 14:21:58 +09:00
184bc2eccd Update documentation 2020-08-14 11:08:04 +09:00
4dab765cf5 Update dependencies 2020-08-13 01:09:37 +00:00
329417f094 Update documentation 2020-08-04 22:02:58 +09:00
7311df63a5 Update documentation 2020-08-04 15:44:58 +09:00
47a0e6b298 Update documentation 2020-08-04 14:27:36 +09:00
9b02473bb0 Update documentation 2020-08-04 14:20:01 +09:00
40b1b245eb Merge pull request #477 from peter-evans/dev
signoff
2020-07-31 18:08:02 +09:00
64c8d492d5 Update documentation 2020-07-31 16:59:26 +09:00
28fddffcf8 Add test for signoff 2020-07-31 16:57:41 +09:00
ba8309ff9c Refactor setting commit params 2020-07-31 16:57:16 +09:00
ee482f51bd Move input next to commit related inputs for context 2020-07-31 16:56:10 +09:00
bf7dd38b26 Merge pull request #476 from pvogt09/master
Adds option to signoff commits
2020-07-31 15:12:43 +09:00
71a37c5c33 Update documentation 2020-07-31 10:24:31 +09:00
f9af0fbfc0 Merge pull request #3 from pvogt09/update-distribution
Update distribution
2020-07-30 17:18:52 +02:00
0c57887fe8 Update distribution 2020-07-30 15:18:17 +00:00
7ad9f6e012 try -s instead of --signoff
Signed-off-by: pvogt09 <50047961+pvogt09@users.noreply.github.com>
2020-07-30 16:23:22 +02:00
dd364f2835 adds argument to test cases
Signed-off-by: pvogt09 <50047961+pvogt09@users.noreply.github.com>
2020-07-30 16:06:07 +02:00
ddd52205b6 adds signoff option to sign off commits
Signed-off-by: pvogt09 <50047961+pvogt09@users.noreply.github.com>
2020-07-30 15:57:37 +02:00
a81d0faef6 Merge pull request #470 from peter-evans/rem-dep
Remove unnecessary dependency
2020-07-30 12:26:57 +09:00
fc03a820b2 Remove unnecessary dependency 2020-07-30 12:16:48 +09:00
b2cdf099d0 Update ci workflow 2020-07-25 14:02:46 +09:00
f3d08d3f0b Update slash-command-dispatch to v2 2020-07-25 13:23:29 +09:00
3a21b8d668 Update slash-command-dispatch to v2-beta 2020-07-25 12:53:35 +09:00
132b02c8e1 Merge pull request #455 from peter-evans/lodash-vuln
Update lodash to fix vuln
2020-07-23 17:18:11 +09:00
9507cdc7ac Update lodash to fix vuln 2020-07-23 17:06:02 +09:00
f4bf0d40c3 Update workflows to v3 2020-07-23 16:20:49 +09:00
cf325ed84b Update example screenshot 2020-07-23 15:37:47 +09:00
ebc5e02585 Merge pull request #429 from peter-evans/dev
v3
2020-07-23 15:19:55 +09:00
c01f8fadc7 Remove unnecessary scripts 2020-07-23 15:04:58 +09:00
c0c9424b03 Update changes documentation 2020-07-23 14:52:44 +09:00
7649c29e89 Update documentation 2020-07-23 14:35:35 +09:00
125f154b50 Update documentation 2020-07-20 22:12:30 +09:00
8c01dce3ac Restore the branch-suffix input 2020-07-20 19:15:11 +09:00
3c6aade49b Fix link to action.yml 2020-07-19 20:47:45 +09:00
76c09b178c Default author and committer to actions.yml defaults 2020-07-19 20:23:36 +09:00
2f62e00e1b Rename test command param from branch to ref 2020-07-19 17:20:46 +09:00
16354377ad Update documentation 2020-07-19 17:04:47 +09:00
809468fcd7 Update documentation 2020-07-19 17:01:54 +09:00
216b3681c3 Update workflow 2020-07-19 16:20:13 +09:00
6fa44e144d Set defaults in action.yml 2020-07-19 15:09:44 +09:00
b5b1bc17a4 Remove branch-suffix input 2020-07-19 13:58:50 +09:00
794518a553 Move fileExistsSync to utils 2020-07-18 17:55:42 +09:00
f4ee4a8333 Unshallow on fetch 2020-07-18 16:04:36 +09:00
053b501145 Redesign from request-to-parent to push-to-fork 2020-07-18 15:35:30 +09:00
1a182d0679 Fix function name 2020-07-17 21:06:16 +09:00
24012f5c84 Refactor extraheader auth handling 2020-07-17 20:54:39 +09:00
a6a1a418bf Use force-with-lease to push the pr branch 2020-07-17 10:37:09 +09:00
5429e57002 Keep env var output for backwards compat 2020-07-16 19:42:19 +09:00
3c32fac1fe Tidy log output into groups 2020-07-16 19:13:28 +09:00
803cc5ea8a Remove python related code and artifacts 2020-07-16 18:18:58 +09:00
4ba9ca3d10 Convert action to typescript 2020-07-16 17:57:42 +09:00
40e70b8f7b Update documentation 2020-07-01 09:42:27 +09:00
b7eabdce59 Update documentation 2020-06-30 16:39:01 +09:00
43dc723813 Update documentation 2020-06-30 16:05:44 +09:00
4d3b0a48ef Merge pull request #394 from peter-evans/update-distribution
Update distribution
2020-06-27 17:10:28 +09:00
e9a825aacd Update distribution 2020-06-27 08:06:58 +00:00
3509fd45ae Merge pull request #389 from peter-evans/dev
Parse repo urls with credentials
2020-06-27 17:03:41 +09:00
14ee9d1df2 Parse repo urls with credentials 2020-06-27 16:45:24 +09:00
5d969a55c1 Add gradle example 2020-06-05 18:23:04 +09:00
44130f6fc9 Merge pull request #369 from peter-evans/types
Add missing types
2020-06-03 17:09:43 +09:00
86ccd8cdef Add missing types 2020-06-03 16:47:02 +09:00
7e7fa32a5f Merge pull request #364 from peter-evans/fix-ci
Fix ci artifacts
2020-06-02 18:21:51 +09:00
5f7beeb2ff Fix ci artifacts 2020-06-02 18:16:23 +09:00
926d56fcba Update documentation 2020-06-02 16:44:14 +09:00
8d744a2cd3 Remove reaction-token 2020-06-02 15:58:02 +09:00
c2d829c681 Update documentation 2020-05-27 11:43:25 +09:00
d77392faf0 Update slash command dispatch token 2020-05-25 17:15:16 +09:00
ccd2b64012 Add rebase slash command 2020-05-25 16:12:13 +09:00
58fb221778 Merge pull request #339 from peter-evans/update-distribution
Update distribution
2020-05-24 09:36:26 +09:00
7a856e8b5d Update distribution 2020-05-24 00:34:21 +00:00
65d7a66451 Merge pull request #293 from peter-evans/renovate/setuptools-46.x
Update dependency setuptools to v46.4.0
2020-05-24 09:30:21 +09:00
44a7f59b6f Update dependency setuptools to v46.4.0 2020-05-23 06:24:24 +00:00
8acaf6bb4c Merge pull request #330 from peter-evans/int-tests
Integration testing
2020-05-23 15:16:37 +09:00
498d78cb23 Add integration testing 2020-05-23 14:43:18 +09:00
172ec762f8 Merge pull request #301 from peter-evans/update-distribution
Update distribution
2020-05-17 18:28:48 +09:00
5cb0d674f3 Update distribution 2020-05-17 09:26:30 +00:00
eb892d7803 Merge pull request #308 from peter-evans/typescript
Typescript
2020-05-17 18:24:18 +09:00
f8274253bd Convert to typescript 2020-05-17 18:02:41 +09:00
0f423da02c Merge pull request #315 from peter-evans/input-def
Add missing draft input definition
2020-05-17 17:55:03 +09:00
9573f479a0 Add missing draft input definition 2020-05-17 17:47:54 +09:00
eb4cde120d Update documentation 2020-05-17 14:42:46 +09:00
25902ccdd1 Remove dockerhub-description workflow 2020-05-16 14:36:18 +09:00
39b337e8bb Remove codeowners 2020-05-14 10:19:06 +09:00
7e70d8e63c Skip test job for pull requests from forks 2020-05-13 17:25:18 +09:00
1a640f5b01 Update README 2020-05-11 14:31:26 +09:00
9faa8dc1d9 Update pull request example image 2020-05-11 14:28:02 +09:00
afcf57957d Merge pull request #287 from peter-evans/update-distribution
Update distribution
2020-05-11 14:09:44 +09:00
8cc3564bf3 Update distribution 2020-05-11 05:09:19 +00:00
6910c5cd03 Merge pull request #271 from peter-evans/renovate/setuptools-46.x
Update dependency setuptools to v46.2.0
2020-05-11 14:07:27 +09:00
14836c6ff3 Update dependency setuptools to v46.2.0 2020-05-11 05:04:42 +00:00
8fbfcfbcbb Revert "Temporarily use deprecated output"
This reverts commit fbb7e0e650.
2020-05-11 14:01:43 +09:00
326f260418 Merge pull request #278 from peter-evans/update-distribution
Update distribution
2020-05-11 13:59:07 +09:00
75104b7d7e Update distribution 2020-05-11 04:58:23 +00:00
fbb7e0e650 Temporarily use deprecated output 2020-05-11 13:55:32 +09:00
0f1e60a1f8 Merge pull request #264 from peter-evans/dev
Deprecate pr_number, project and project-column
2020-05-11 13:50:08 +09:00
caa116d991 Deprecate project and project-column 2020-05-10 19:02:35 +09:00
d2f72f0799 Update workflows 2020-05-10 18:09:48 +09:00
ded05960f3 Deprecate pr_number output 2020-05-10 18:06:32 +09:00
eb605db8a3 Fix casing 2020-05-10 17:58:21 +09:00
b11e4c665b Merge pull request #263 from christopherthielen/patch-1
docs: request-on-parent  ->  request-to-parent
2020-05-09 07:43:25 +09:00
65327d17a5 docs: request-on-parent -> request-to-parent 2020-05-08 11:03:56 -07:00
0837238e66 Merge pull request #239 from peter-evans/update-distribution
Update distribution
2020-05-06 12:47:46 +09:00
17bd947e89 Update distribution 2020-05-06 03:42:38 +00:00
24b42ba7f4 Merge pull request #240 from peter-evans/renovate/gitpython-3.x
Update dependency GitPython to v3.1.2
2020-05-06 12:40:52 +09:00
c0aaf5bab9 Update documentation 2020-05-06 11:37:48 +09:00
968cb0f4d9 Ignore documentation paths 2020-05-06 11:31:35 +09:00
9d6f73d546 Update documentation 2020-05-06 11:23:37 +09:00
70d240d0c4 Add update dependencies workflow 2020-05-06 10:51:06 +09:00
7bb7d96c96 Update dependency GitPython to v3.1.2 2020-05-06 01:49:21 +00:00
66fcd19e8d Whitelist pip requirements updates 2020-05-06 10:46:29 +09:00
d93f2b46fd Update dependency jest to v26.0.1 2020-05-05 12:23:22 +00:00
246328e3d8 Add ci badge 2020-05-05 14:24:35 +09:00
61cff7c673 Update dependency jest to v26 2020-05-04 19:59:11 +00:00
46ba7bdfe8 Merge pull request #229 from peter-evans/update-distribution
Update distribution
2020-05-03 12:18:11 +09:00
d650be7389 Update distribution 2020-05-03 03:15:56 +00:00
2f7173349f Fix dist requirements version 2020-05-03 12:13:39 +09:00
4ca95026d7 Ignore dist for renovate updates 2020-05-03 12:12:19 +09:00
64c4efd526 Merge pull request #219 from peter-evans/renovate/pygithub-1.x
Update dependency PyGithub to v1.51
2020-05-03 11:46:05 +09:00
16e35685ce Update dependency PyGithub to v1.51 2020-05-03 02:36:00 +00:00
3b12cf0165 Merge pull request #220 from peter-evans/fix-ci
Fix CI workflow
2020-05-03 11:35:02 +09:00
2a283f5fc3 Fix ci workflow 2020-05-03 11:31:45 +09:00
8ed207bcca Merge pull request #214 from peter-evans/update-distribution
Update distribution
2020-05-02 21:56:54 +09:00
bd1f6727cd Update distribution 2020-05-02 11:27:54 +00:00
9a3acf8f32 Update dependency jest to v25.5.4 2020-05-02 11:26:02 +00:00
b38fd9eb87 Merge pull request #206 from peter-evans/renovate/actions-tool-cache-1.x
Update dependency @actions/tool-cache to v1.3.4
2020-05-02 19:28:31 +09:00
4a9e76e377 Update dependency @actions/tool-cache to v1.3.4 2020-05-02 09:57:02 +00:00
8cb4c8b741 Merge pull request #201 from peter-evans/update-distribution
Update distribution
2020-05-02 17:47:24 +09:00
b9eb5dd95e Update distribution 2020-05-02 08:45:04 +00:00
5502904068 Merge pull request #191 from peter-evans/renovate/actions-core-1.x
Update dependency @actions/core to v1.2.4
2020-05-02 17:43:01 +09:00
56ad1fed7b Update dependency @actions/core to v1.2.4 2020-05-02 08:40:54 +00:00
2132f428f6 Merge pull request #192 from peter-evans/renovate/actions-exec-1.x
Update dependency @actions/exec to v1.0.4
2020-05-02 17:40:28 +09:00
c558d39395 Update dependency @actions/exec to v1.0.4 2020-05-02 08:30:46 +00:00
db640fa8db Merge pull request #168 from peter-evans/renovate/jest-monorepo
Update dependency jest to v25.5.3
2020-05-02 16:07:29 +09:00
95d6677567 Merge pull request #171 from peter-evans/ci
Add CI workflow
2020-05-02 16:04:14 +09:00
1f4e24248b Update test suite command 2020-05-02 16:02:02 +09:00
08595270b5 Filter by comment author 2020-05-02 15:32:34 +09:00
237244614a Remove author search condition 2020-05-02 15:25:52 +09:00
6295d61f0c Rename job 2020-05-02 15:19:44 +09:00
d4024e2876 Add test suite help comment 2020-05-02 15:13:50 +09:00
ee96ad03d9 Auto merge dev dependency updates 2020-05-02 14:55:39 +09:00
755b39d2ff Pin dependencies 2020-05-02 14:55:07 +09:00
9f95ac6c53 Setup python for missing pip dependency 2020-05-02 14:50:21 +09:00
cedbe4ad47 Add ci workflow 2020-05-02 14:46:15 +09:00
0e48ed8743 Update dependency jest to v25.5.3 2020-04-30 22:19:12 +00:00
e7291b422e Merge pull request #166 from peter-evans/renovate/jest-monorepo
Update dependency jest to v25.5.0
2020-04-29 08:08:26 +09:00
eb824681a8 Update dependency jest to v25.5.0 2020-04-28 19:53:37 +00:00
4cc13107a9 Merge pull request #165 from peter-evans/dev
Update dependency PyGithub to v1.50
2020-04-27 12:06:54 +09:00
c71b8e4206 Update vendored dependencies 2020-04-27 11:48:52 +09:00
e2bf7f9b75 Update dependency PyGithub to v1.50 2020-04-27 11:47:17 +09:00
e1f4cfdcd4 Merge pull request #162 from peter-evans/renovate/jest-monorepo
Update dependency jest to v25.4.0
2020-04-20 10:43:20 +09:00
b3f0552507 Update dependency jest to v25.4.0 2020-04-19 21:52:02 +00:00
f4be118b21 Merge pull request #160 from peter-evans/dev
Update dependency GitPython to v3.1.1
2020-04-14 12:02:29 +09:00
c9f22f86fb Vendor wheel 2020-04-14 11:48:20 +09:00
35d5f3c8ae Vendor setuptools 2020-04-14 11:43:07 +09:00
000a0fc06a Update vendored dependencies 2020-04-13 17:53:37 +09:00
2a59f517a7 Update dependency GitPython to v3.1.1 2020-04-13 17:51:52 +09:00
48ce89bc7d Update documentation 2020-04-13 09:57:57 +09:00
6570353abb Update README 2020-04-13 09:36:37 +09:00
8f6cecd6c4 Update workflow 2020-04-10 17:11:29 +09:00
e14ef3b543 Update README 2020-04-10 17:10:06 +09:00
c5778e5181 Merge pull request #157 from peter-evans/renovate/jest-monorepo
Update dependency jest to v25.3.0
2020-04-09 00:23:26 +09:00
374fc61fef Update dependency jest to v25.3.0 2020-04-08 14:53:23 +00:00
6fa547cc6f Update documentation 2020-04-06 09:37:35 +09:00
4db3619128 Merge pull request #154 from peter-evans/renovate/zeit-ncc-0.x
Update dependency @zeit/ncc to v0.22.1
2020-04-06 09:10:47 +09:00
989a8308ec Update dependency @zeit/ncc to v0.22.1 2020-04-05 20:34:21 +00:00
6249109e58 Update documentation 2020-04-05 18:17:05 +09:00
c9b850c450 Update workflow 2020-04-04 18:26:59 +09:00
340e629d2f Merge pull request #152 from peter-evans/dev
Add input for draft pull requests
2020-04-04 09:50:05 +09:00
abc19caa82 Add input for draft pull requests 2020-04-04 09:47:58 +09:00
3474dda921 Update documentation 2020-04-03 17:26:11 +09:00
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
86aa5be8bf Update dependency jest to v25.2.7 2020-04-03 07:58:49 +00:00
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
cc84a2389e Update dependency jest to v25.2.6 2020-04-02 10:36:04 +00:00
7e7150d0e8 Merge pull request #147 from peter-evans/dev
Default token to github.token
2020-04-01 19:09:39 +09:00
eb99d45ce6 Default token to github.token 2020-04-01 18:50:53 +09:00
115b7391e1 Revert "Update documentation"
This reverts commit 628c2d7d35.
2020-03-30 17:36:34 +09:00
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
32f5c5dd5f Update dependency jest to v25.2.4 2020-03-29 20:05:26 +00:00
628c2d7d35 Update documentation 2020-03-29 21:34:47 +09:00
37582e8764 Update documentation 2020-03-29 21:27:56 +09:00
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
a70c6ebe2a Merge pull request #144 from jderusse/fork
Allow custom repository when pushin in fork
2020-03-29 20:47:00 +09:00
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
26bc40eea1 Add link in TOC 2020-03-29 12:44:57 +02:00
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
4c347a4514 Update docs/concepts-guidelines.md
Co-Authored-By: Tobias Nyholm <tobias.nyholm@gmail.com>
2020-03-28 16:42:57 +01:00
cff2c3381d Add doc 2020-03-28 13:27:58 +01:00
e48dab0c1c Add PR creation from Fork 2020-03-28 13:10:12 +01:00
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
3ff256ce08 Update dependency jest to v25.2.3 2020-03-26 20:38:32 +00:00
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
3c4b2793c1 Update dependency jest to v25.2.1 2020-03-26 09:43:37 +00:00
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
e324a22ee1 Update dependency jest to v25.2.0 2020-03-25 18:18:56 +00:00
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
6852d55922 Update dependency @zeit/ncc to v0.22.0 2020-03-23 22:31:46 +00:00
32e5bb80a5 Merge pull request #134 from peter-evans/dev
Update dependencies
2020-03-21 11:38:19 +09:00
619cf2115d Update dependencies due to security vulnerabilities 2020-03-21 11:31:34 +09:00
69008aa567 Update vendored dependencies 2020-03-21 11:29:37 +09:00
ae4278bf24 Update dependency PyGithub to v1.47 2020-03-21 11:23:42 +09:00
88da40fea7 Merge pull request #132 from peter-evans/dev
Update dependency GitPython to v3.1.0
2020-03-07 09:08:24 +09:00
694e068136 Update vendored dependencies 2020-03-07 08:57:59 +09:00
64c34f6885 Update README 2020-03-03 09:49:52 +09:00
52ada17960 Update dependency GitPython to v3.1.0 2020-02-25 13:12:00 +09:00
ce00b952cf Merge pull request #128 from peter-evans/dev
Unset and restore authorization extraheader only
2020-02-22 17:02:15 +09:00
0d42c285a3 Unset and restore authorization extraheader only 2020-02-22 16:56:42 +09:00
ea1eaf1734 Merge pull request #127 from peter-evans/dev
Unset and restore extraheader config option
2020-02-22 14:53:46 +09:00
d5c5ea3e20 Unset and restore extraheader config option 2020-02-22 14:08:54 +09:00
c7b64af0a4 Merge pull request #123 from peter-evans/dev
Authenticate with git extraheader
2020-02-18 19:49:13 +09:00
289fda9fea Authenticate with git extraheader 2020-02-18 19:35:15 +09:00
b021b9e27a Update vendored dependencies 2020-02-18 15:59:18 +09:00
c26314237b Update dependency GitPython to v3.0.8 2020-02-18 15:57:13 +09:00
ed7dd8d236 Update documentation 2020-02-14 20:10:27 +09:00
ca0e9d75fd Update documentation 2020-02-14 00:23:21 +09:00
87c27ee3eb Merge pull request #118 from peter-evans/dev
Assume python3 on PATH when running in a container
2020-02-14 00:07:03 +09:00
4beea725d3 Call python3 when running in a container 2020-02-13 17:37:08 +09:00
9d58699da5 Skip python setup when running in a container 2020-02-13 16:26:04 +09:00
bceebba814 Merge pull request #117 from peter-evans/renovate/zeit-ncc-0.x
Update dependency @zeit/ncc to v0.21.1
2020-02-13 09:58:46 +09:00
0b82710b2e Update dependency @zeit/ncc to v0.21.1 2020-02-12 16:54:11 +00:00
4aaaa0e760 Update README 2020-02-11 16:36:16 +09:00
918bfcb8a3 Update README 2020-02-11 16:28:16 +09:00
1ecfd1ae40 Merge pull request #116 from peter-evans/dev
Update dependency PyGithub to v1.46
2020-02-11 14:03:17 +09:00
4dd195d7c3 Update vendored dependencies 2020-02-11 13:51:59 +09:00
72b5f45bb4 Update dependency PyGithub to v1.46 2020-02-11 13:49:50 +09:00
5394814b39 Update documentation 2020-02-11 01:21:05 +09:00
83918398f5 Update documentation 2020-02-11 01:15:59 +09:00
b6a458d96a Merge pull request #114 from peter-evans/dev
Add support for ssh protocol
2020-02-10 23:06:03 +09:00
7b5ff6b642 Add support for ssh protocol 2020-02-10 22:52:00 +09:00
82eddd8828 Merge pull request #112 from peter-evans/dev
Skip python setup for alpine linux
2020-02-10 18:47:40 +09:00
6df2a462d1 Skip python setup for alpine linux 2020-02-10 09:53:43 +09:00
3689bd07d7 Merge pull request #110 from peter-evans/dev
Update dependency GitPython to v3.0.7
2020-02-08 16:45:18 +09:00
943f19ac64 Update vendored dependencies 2020-02-08 16:12:36 +09:00
e59d6c7fff Update dependency GitPython to v3.0.7 2020-02-08 16:09:50 +09:00
c65a4f39b3 Update documentation 2020-02-08 16:04:23 +09:00
2d18371789 Update documentation 2020-02-08 12:52:06 +09:00
cc7020a609 Merge pull request #107 from peter-evans/dev
Determine target github repository from git config
2020-02-07 19:01:09 +09:00
d8700620d6 Determine target github repository from git config 2020-02-07 11:05:01 +09:00
b7064071dc Move assets 2020-01-25 16:29:22 +09:00
339e82d37b Update documentation 2020-01-24 13:00:38 +09:00
a319015452 Merge pull request #102 from peter-evans/dev
Vendor python dependencies
2020-01-23 18:59:19 +09:00
df0d07269b Vendor python dependencies 2020-01-23 16:59:19 +09:00
2aa04baf2e Merge pull request #101 from peter-evans/dev
Update title and body when pr exists
2020-01-23 09:54:43 +09:00
d29f1e9296 Update title and body when pr exists 2020-01-23 09:47:35 +09:00
8ee12880b0 Update documentation 2020-01-21 22:35:00 +09:00
8d39de8771 Update documentation 2020-01-21 22:27:02 +09:00
c202684c92 Merge pull request #98 from peter-evans/dev
Follow the python minor version
2020-01-17 17:48:11 +09:00
e970adccb4 Follow the python minor version 2020-01-17 17:39:10 +09:00
9f9af3e969 Merge pull request #97 from peter-evans/dev
Update Python to version 3.8.1
2020-01-17 15:52:01 +09:00
615d7c82e3 Update Python to version 3.8.1 2020-01-17 15:46:49 +09:00
8246a6aea9 Merge pull request #95 from peter-evans/dev
Add path input
2020-01-10 00:35:16 +09:00
1e09ec2f22 Add path input 2020-01-10 00:11:42 +09:00
4c018f4174 Merge pull request #93 from peter-evans/renovate/zeit-ncc-0.x
Update dependency @zeit/ncc to v0.21.0
2020-01-05 08:08:32 +09:00
080aaa90aa Update dependency @zeit/ncc to v0.21.0 2020-01-04 15:45:00 +00:00
6ac64298f6 Update slash command 2020-01-04 21:44:01 +09:00
76e932f3c9 Update slash command 2020-01-04 21:38:54 +09:00
06078e295b Update examples 2020-01-04 20:02:09 +09:00
004434a414 Update examples 2020-01-04 12:08:41 +09:00
4661d6d7af Update docs 2020-01-03 19:22:46 +09:00
a972260284 Update docs 2020-01-03 17:50:03 +09:00
f1d6c2dca3 Update example screenshot 2020-01-03 14:52:21 +09:00
aa1cba4c18 Update cpr example workflow 2020-01-03 14:44:00 +09:00
9b33a4edd8 Add slash command for cpr example 2020-01-03 14:37:39 +09:00
938e6aea6f Merge pull request #90 from peter-evans/v2-beta
v2 beta
2020-01-03 14:18:38 +09:00
699d304845 Update docs to v2 2020-01-03 14:18:10 +09:00
2ce0b003ee Merge branch 'master' into v2-beta 2020-01-03 14:00:21 +09:00
10653669e8 Update npm packages 2020-01-03 12:32:22 +09:00
c39f04a86a Add issue template 2020-01-03 12:20:20 +09:00
430f28afbf Add gitgraph to docs 2020-01-03 11:53:45 +09:00
8e07307f04 Remove multi workflow 2020-01-03 10:05:05 +09:00
c8fed30c65 Move docs 2020-01-03 09:51:43 +09:00
11c388252c Add concepts and guidelines doc 2020-01-03 09:33:16 +09:00
e41956c7e7 Update README 2019-12-31 16:40:36 +09:00
f3583f71f8 Update README 2019-12-31 16:39:30 +09:00
e8e53ed431 Update fixture paths 2019-12-31 13:40:46 +09:00
cff82c7ec9 Update fixture paths 2019-12-31 12:57:14 +09:00
c388aba95a Add env override for repo path 2019-12-31 12:33:03 +09:00
02f0ffd558 Update test fixture 2019-12-31 12:02:17 +09:00
b616fd026e Add pytest slash command 2019-12-30 14:18:41 +09:00
ba79823749 Update examples 2019-12-30 12:36:39 +09:00
0af5090b86 Update README 2019-12-30 12:11:55 +09:00
b750589747 Update README 2019-12-30 11:10:22 +09:00
894d4b1412 Update README 2019-12-29 17:35:53 +09:00
95615643f0 Add updating doc 2019-12-29 17:33:07 +09:00
fb48683668 Fix bug when symbolic ref fails 2019-12-29 16:41:59 +09:00
0fb7b7c32a Update README 2019-12-29 16:29:30 +09:00
3e4ab24cbb Update examples 2019-12-29 16:15:13 +09:00
8c86d0f83f Update workflows 2019-12-29 16:05:24 +09:00
673922cfd2 Update README 2019-12-29 15:50:32 +09:00
b11cb71e96 Update input defaults 2019-12-29 15:14:33 +09:00
bdadb3b4a0 Update PyGithub to v1.45 2019-12-29 14:40:49 +09:00
9bdc8b271f Bump version 2019-12-29 14:22:44 +09:00
c208033c6a Remove v1 action code 2019-12-29 14:22:23 +09:00
01aec28fd9 Remove todo comment 2019-12-28 19:05:35 +09:00
484de7fc89 Delete the branch if there is no diff with the base 2019-12-28 18:34:32 +09:00
71f4fe31a8 Update integration tests 2019-12-28 17:31:19 +09:00
883f800b96 Change missing project and column to an error 2019-12-28 17:10:28 +09:00
b3805d65e3 Update string formatting 2019-12-28 17:09:58 +09:00
4f8d5b9d3e Add a check for user config set in the workflow 2019-12-27 18:29:37 +09:00
efbd4fa1ef Fix setting author and committer 2019-12-27 15:32:37 +09:00
b7565b81a7 Add v2 alpha 2019-12-27 14:40:11 +09:00
ec6352b0a0 Merge pull request #85 from peter-evans/dev
Minor refactor to set url via git params
2019-12-08 16:30:10 +09:00
ce4df54075 Bump version 2019-12-08 16:28:43 +09:00
c855a500d1 Add clean slash command 2019-12-08 15:36:00 +09:00
baf52378ae Minor refactor to set url via git params 2019-12-08 15:02:54 +09:00
e6ebd7ca5c Merge pull request #83 from peter-evans/dev
Add inputs for committer-name and committer-email
2019-12-06 19:17:09 +09:00
83fef4e8a1 Update README 2019-12-06 18:36:27 +09:00
d3dc225920 Add inputs for committer-name and committer-email 2019-12-06 17:06:49 +09:00
6342438c4e Updated README 2019-12-05 18:28:50 +09:00
324fe6cdde Add slash command dispatch workflow 2019-12-03 19:50:15 +09:00
4faa5d5a97 Update README 2019-11-24 09:28:14 +09:00
381bc30cef Update example screenshot 2019-11-24 09:14:05 +09:00
7531167f24 Merge pull request #76 from peter-evans/dev
Add feature to create project card for pull request
2019-11-24 09:04:44 +09:00
66a1436815 Update input descriptions 2019-11-24 09:00:31 +09:00
1d1fedd99c Add feature to create project card for pull request 2019-11-24 08:48:32 +09:00
823751817d Update examples 2019-11-16 10:19:03 +09:00
1edcf07a19 Update examples 2019-11-16 10:17:29 +09:00
4c95214a9b Update README 2019-11-16 09:27:21 +09:00
b37c0a038c Update input description 2019-11-16 09:26:07 +09:00
d9841567d1 Update README 2019-11-16 09:25:06 +09:00
2cce94bfb0 Bump version 2019-11-16 09:25:00 +09:00
d968e8b11b Add warning and fail gracefully when ref is invalid for base 2019-11-16 09:24:46 +09:00
6c73093f9b Merge pull request #74 from peter-evans/renovate/gitpython-3.x
Update dependency GitPython to v3.0.5
2019-11-15 19:46:46 +09:00
d17c882ef3 Update examples 2019-11-15 08:27:12 +09:00
d5f4e48a66 Update dependency GitPython to v3.0.5 2019-11-14 01:46:43 +00:00
484d8bd85d Merge pull request #72 from peter-evans/dev
Logging and handling of PR events from forks
2019-11-13 23:59:38 +09:00
74b6a9337d Update documentation 2019-11-13 23:52:33 +09:00
2dd62d446e Bump version 2019-11-13 19:10:53 +09:00
b6a98c049d Add logging and handling for pr events from forks 2019-11-13 19:10:38 +09:00
67e8822279 Update examples 2019-11-13 11:05:55 +09:00
956a240181 Update examples 2019-11-11 22:49:11 +09:00
179aca65d7 Update examples 2019-11-11 22:45:23 +09:00
e4c8b68e33 Update dockerhub-description workflow 2019-11-10 22:08:30 +09:00
731211fd81 Fix bug with filtering pull requests 2019-11-10 18:14:10 +09:00
006313b45a Fix bug when updating a pull request 2019-11-10 16:56:55 +09:00
3c86e9a421 Add outputs description 2019-11-10 13:07:11 +09:00
e49ebca896 Merge pull request #69 from peter-evans/renovate/pin-dependencies
Pin dependency @zeit/ncc to 0.20.5
2019-11-09 23:36:02 +09:00
d9652cf06a Pin dependency @zeit/ncc to 0.20.5 2019-11-09 14:06:18 +00:00
4517bf7ce3 Merge pull request #68 from peter-evans/dev
Convert to hybrid multi-platfrom
2019-11-09 23:06:00 +09:00
04aa84a2af Update examples 2019-11-09 22:48:30 +09:00
11baa5dc07 Update examples 2019-11-09 22:46:01 +09:00
1281ebd51a Update README 2019-11-09 18:22:57 +09:00
46dc4f23d5 Update workflows 2019-11-09 18:22:03 +09:00
d469aaf0ef Update workflows 2019-11-09 17:59:23 +09:00
5692e041c6 Set a step output 2019-11-09 17:42:11 +09:00
55e7b1ec28 Update action to hybrid multi platform 2019-11-09 17:24:47 +09:00
d99b58f9d5 Merge pull request #67 from peter-evans/renovate/pygithub-1.x
Update dependency PyGithub to v1.44.1
2019-11-08 20:31:06 +09:00
b8ce455e56 Update dependency PyGithub to v1.44.1 2019-11-07 03:57:40 +00:00
c9e477ec05 Update examples 2019-11-05 14:10:23 +09:00
979d417e9d Update examples 2019-11-05 13:23:16 +09:00
b74a77cefc Update examples 2019-11-04 12:19:19 +09:00
2af7d9797a Update documentation 2019-11-04 11:13:18 +09:00
b72489d629 Update image version 2019-11-04 11:08:47 +09:00
1461de7c9d Update README 2019-11-04 11:01:08 +09:00
3061b7bc6e Update workflows 2019-11-04 11:01:00 +09:00
98ee7d63d3 Improvements to updating pull requests 2019-11-04 11:00:38 +09:00
066b4398c0 Merge pull request #66 from staabm/patch-2
Link ::set-output
2019-11-03 18:42:49 +09:00
028e1bbdd5 Link ::set-output 2019-11-03 10:38:30 +01:00
8b8594e5e4 Update examples 2019-11-03 18:29:46 +09:00
cefb562076 Merge pull request #63 from peter-evans/documentation
Update documentation
2019-11-03 17:46:08 +09:00
9eccdd1603 Update README 2019-11-03 17:44:22 +09:00
f429dfef59 Update examples 2019-11-03 17:41:42 +09:00
963e38fd7d Add examples documentation 2019-11-03 17:37:39 +09:00
f411b5902d Merge pull request #62 from peter-evans/asset-location
Update location of assets
2019-11-03 15:47:02 +09:00
97dd1f3ef4 Update location of assets 2019-11-03 15:46:11 +09:00
3413a77ac7 Update README 2019-10-30 16:10:02 +09:00
206756cd93 Update image version 2019-10-30 16:04:28 +09:00
263b5927d1 Remove ignore event logic 2019-10-30 15:27:54 +09:00
a0ad81c6c7 Merge pull request #58 from peter-evans/renovate/gitpython-3.x
Update dependency GitPython to v3.0.4
2019-10-29 13:31:52 +09:00
23846c7f83 Update dependency GitPython to v3.0.4 2019-10-22 11:43:55 +00:00
96ac64ddca Update README 2019-10-22 11:05:42 +09:00
a2ed0052e5 Update image version 2019-10-22 11:01:54 +09:00
6e7e889e01 Minor fixes and refactor 2019-10-22 10:55:33 +09:00
7e18a60b72 Merge pull request #57 from peter-evans/renovate/docker-alpine-3.x
Update alpine Docker tag to v3.10.3
2019-10-22 10:53:31 +09:00
0be4e396cf Update alpine Docker tag to v3.10.3 2019-10-21 17:57:06 +00:00
b86bbce924 Update README 2019-10-21 20:36:01 +09:00
e1e9dd3f1c Update image version 2019-10-21 20:32:02 +09:00
8c2a43987b Add an override for the base branch 2019-10-21 20:17:31 +09:00
c5ff844b40 Update README 2019-10-21 18:42:39 +09:00
1f47cf3861 Update workflows 2019-10-21 18:31:14 +09:00
bcdc7ae6f9 Merge pull request #55 from peter-evans/renovate/pygithub-1.x
Update dependency PyGithub to v1.44
2019-10-19 22:58:42 +09:00
91ca84eab5 Update dependency PyGithub to v1.44 2019-10-19 08:44:24 +00:00
875d189c30 Update README 2019-10-14 18:09:59 +09:00
7c3f5f4833 Update README 2019-10-14 16:12:27 +09:00
7a7e797068 Update README 2019-10-14 16:11:09 +09:00
a41f37fc96 Update README 2019-10-14 16:09:58 +09:00
10554ac6c3 Update README 2019-10-14 15:59:21 +09:00
2439726cfe Update README 2019-10-14 15:51:08 +09:00
4f04f4efd9 Update workflows 2019-10-14 15:50:52 +09:00
32d0abbc7c Update README 2019-10-14 15:07:11 +09:00
ed5b8b1eea Update README 2019-10-14 12:38:52 +09:00
ea241dfc79 Update README 2019-10-14 12:37:36 +09:00
0e70fec054 Update README 2019-10-14 12:36:55 +09:00
5077e8d6bd Rename dockerhub description workflow 2019-10-14 10:26:25 +09:00
901e854f30 Update README 2019-10-14 02:02:55 +09:00
f3b1bd6331 Update image version 2019-10-14 01:58:42 +09:00
51ade9f54b Fix for pull refs 2019-10-14 01:39:53 +09:00
3c86dbf9e6 Update README 2019-10-06 15:13:32 +09:00
b2d426ea4e Update README 2019-10-06 15:06:49 +09:00
fbe0cd3d1a Update README 2019-10-06 14:59:45 +09:00
46 changed files with 31841 additions and 443 deletions

3
.eslintignore Normal file
View File

@ -0,0 +1,3 @@
dist/
lib/
node_modules/

23
.eslintrc.json Normal file
View File

@ -0,0 +1,23 @@
{
"env": { "node": true, "jest": true },
"parser": "@typescript-eslint/parser",
"parserOptions": { "ecmaVersion": 9, "sourceType": "module" },
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript",
"plugin:prettier/recommended"
],
"plugins": ["@typescript-eslint"],
"rules": {
"@typescript-eslint/camelcase": "off"
},
"settings": {
"import/resolver": {
"typescript": {}
}
}
}

1
.github/CODEOWNERS vendored
View File

@ -1 +0,0 @@
* @peter-evans

7
.github/ISSUE_TEMPLATE.md vendored Normal file
View File

@ -0,0 +1,7 @@
### Subject of the issue
Describe your issue here.
### Steps to reproduce
If this issue is describing a possible bug please provide (or link to) your GitHub Actions workflow.

8
.github/dependabot.yml vendored Normal file
View File

@ -0,0 +1,8 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
labels:
- "dependencies"

129
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,129 @@
name: CI
on:
push:
branches: [main]
paths-ignore:
- 'README.md'
- 'docs/**'
pull_request:
branches: [main]
paths-ignore:
- 'README.md'
- 'docs/**'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16.x
cache: npm
- run: npm ci
- run: npm run build
- run: npm run format-check
- run: npm run lint
- run: npm run test
- uses: actions/upload-artifact@v3
with:
name: dist
path: dist
- uses: actions/upload-artifact@v3
with:
name: action.yml
path: action.yml
test:
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository
needs: [build]
runs-on: ubuntu-latest
strategy:
matrix:
target: [built, committed]
steps:
- uses: actions/checkout@v3
with:
ref: main
- if: matrix.target == 'built' || github.event_name == 'pull_request'
uses: actions/download-artifact@v3
with:
name: dist
path: dist
- if: matrix.target == 'built' || github.event_name == 'pull_request'
uses: actions/download-artifact@v3
with:
name: action.yml
path: .
- name: Create change
run: date +%s > report.txt
- name: Create Pull Request
id: cpr
uses: ./
with:
commit-message: '[CI] test ${{ matrix.target }}'
committer: GitHub <noreply@github.com>
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
title: '[CI] test ${{ matrix.target }}'
body: |
- CI test case for target '${{ matrix.target }}'
Auto-generated by [create-pull-request][1]
[1]: https://github.com/peter-evans/create-pull-request
branch: ci-test-${{ matrix.target }}
- name: Close Pull
uses: peter-evans/close-pull@v2
with:
pull-request-number: ${{ steps.cpr.outputs.pull-request-number }}
comment: '[CI] test ${{ matrix.target }}'
delete-branch: true
commentTestSuiteHelp:
if: github.event_name == 'pull_request'
needs: [test]
runs-on: ubuntu-latest
steps:
- name: Find Comment
uses: peter-evans/find-comment@v2
id: fc
with:
issue-number: ${{ github.event.number }}
comment-author: 'github-actions[bot]'
body-includes: Full test suite slash command
- if: steps.fc.outputs.comment-id == ''
name: Create comment
uses: peter-evans/create-or-update-comment@v2
with:
issue-number: ${{ github.event.number }}
body: |
Full test suite slash command (repository admin only)
```
/test repository=${{ github.event.pull_request.head.repo.full_name }} ref=${{ github.event.pull_request.head.ref }} build=true
```
package:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs: [test]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: dist
path: dist
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
commit-message: 'build: update distribution'
title: Update distribution
body: |
- Updates the distribution for changes on `main`
Auto-generated by [create-pull-request][1]
[1]: https://github.com/peter-evans/create-pull-request
branch: update-distribution

View File

@ -0,0 +1,49 @@
name: Create Pull Request Example Command
on:
repository_dispatch:
types: [cpr-example-command]
jobs:
createPullRequest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Make changes to pull request
run: date +%s > report.txt
- name: Create Pull Request
id: cpr
uses: ./
with:
commit-message: Update report
committer: GitHub <noreply@github.com>
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
signoff: false
title: '[Example] Update report'
body: |
Update report
- Updated with *today's* date
- Auto-generated by [create-pull-request][1]
[1]: https://github.com/peter-evans/create-pull-request
labels: |
report
automated pr
assignees: peter-evans
reviewers: peter-evans
milestone: 1
draft: false
branch: example-patches
delete-branch: true
- name: Check output
run: |
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
- name: Add reaction
uses: peter-evans/create-or-update-comment@v2
with:
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
reaction-type: hooray

View File

@ -1,42 +0,0 @@
on:
repository_dispatch:
types: [create-pull-request-multi]
name: create-pull-request workflow
jobs:
createPullRequest:
name: Testing on ${{ matrix.platform }}
strategy:
matrix:
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v1
- name: Create report file
if: matrix.platform == 'ubuntu-latest' || matrix.platform == 'macos-latest'
run: date +%s > report.txt
- name: Create report file (windows)
if: matrix.platform == 'windows-latest'
run: echo %DATE% %TIME% > report.txt
- name: Create Pull Request
uses: peter-evans/create-pull-request@multi-platform-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMIT_MESSAGE: Add report file
COMMIT_AUTHOR_EMAIL: peter-evans@users.noreply.github.com
COMMIT_AUTHOR_NAME: Peter Evans
PULL_REQUEST_TITLE: '[Example] Add report file'
PULL_REQUEST_BODY: >
This PR is auto-generated by
[create-pull-request](https://github.com/peter-evans/create-pull-request).
PULL_REQUEST_LABELS: report, automated pr
PULL_REQUEST_ASSIGNEES: peter-evans
PULL_REQUEST_REVIEWERS: peter-evans
PULL_REQUEST_MILESTONE: 1
PULL_REQUEST_BRANCH: example-patches
BRANCH_SUFFIX: 'random'
- name: Check output environment variable
if: matrix.platform == 'ubuntu-latest' || matrix.platform == 'macos-latest'
run: echo "Pull Request Number - $PULL_REQUEST_NUMBER"
- name: Check output environment variable (windows)
if: matrix.platform == 'windows-latest'
run: echo Pull Request Number - %PULL_REQUEST_NUMBER%

View File

@ -1,30 +0,0 @@
on:
repository_dispatch:
types: [create-pull-request]
name: create-pull-request workflow
jobs:
createPullRequest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Create report file
run: date +%s > report.txt
- name: Create Pull Request
uses: ./
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMIT_MESSAGE: Add report file
COMMIT_AUTHOR_EMAIL: peter-evans@users.noreply.github.com
COMMIT_AUTHOR_NAME: Peter Evans
PULL_REQUEST_TITLE: '[Example] Add report file'
PULL_REQUEST_BODY: >
This PR is auto-generated by
[create-pull-request](https://github.com/peter-evans/create-pull-request).
PULL_REQUEST_LABELS: report, automated pr
PULL_REQUEST_ASSIGNEES: peter-evans
PULL_REQUEST_REVIEWERS: peter-evans
PULL_REQUEST_MILESTONE: 1
PULL_REQUEST_BRANCH: example-patches
BRANCH_SUFFIX: short-commit-hash
- name: Check output environment variable
run: echo "Pull Request Number - $PULL_REQUEST_NUMBER"

View File

@ -1,16 +0,0 @@
name: Update Docker Hub Description
on:
push:
branches:
- master
jobs:
dockerHubDescription:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Docker Hub Description
uses: peter-evans/dockerhub-description@v2.1.0
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
DOCKERHUB_REPOSITORY: peterevans/create-pull-request

View File

@ -0,0 +1,37 @@
name: Slash Command Dispatch
on:
issue_comment:
types: [created]
jobs:
slashCommandDispatch:
runs-on: ubuntu-latest
steps:
- name: Slash Command Dispatch
uses: peter-evans/slash-command-dispatch@v3
with:
token: ${{ secrets.ACTIONS_BOT_TOKEN }}
config: >
[
{
"command": "test",
"permission": "admin",
"repository": "peter-evans/create-pull-request-tests",
"named_args": true
},
{
"command": "clean",
"permission": "admin",
"repository": "peter-evans/create-pull-request-tests"
},
{
"command": "cpr-example",
"permission": "admin",
"issue_type": "issue"
},
{
"command": "rebase",
"permission": "admin",
"repository": "peter-evans/slash-command-dispatch-processor",
"issue_type": "pull-request"
}
]

4
.gitignore vendored
View File

@ -1 +1,5 @@
lib/
node_modules/
.DS_Store
.idea

3
.prettierignore Normal file
View File

@ -0,0 +1,3 @@
dist/
lib/
node_modules/

11
.prettierrc.json Normal file
View File

@ -0,0 +1,11 @@
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": false,
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": false,
"arrowParens": "avoid",
"parser": "typescript"
}

View File

@ -1,20 +0,0 @@
FROM alpine:3.10.2
LABEL maintainer="Peter Evans <mail@peterevans.dev>"
LABEL repository="https://github.com/peter-evans/create-pull-request"
LABEL homepage="https://github.com/peter-evans/create-pull-request"
LABEL com.github.actions.name="Create Pull Request"
LABEL com.github.actions.description="Creates a pull request for changes to your repository in the actions workspace"
LABEL com.github.actions.icon="git-pull-request"
LABEL com.github.actions.color="gray-dark"
COPY LICENSE README.md /
RUN apk add python3-dev git git-lfs
COPY requirements.txt /tmp/
RUN pip3 install --requirement /tmp/requirements.txt
COPY create-pull-request.py /create-pull-request.py
ENTRYPOINT [ "/create-pull-request.py" ]

311
README.md
View File

@ -1,5 +1,6 @@
# <img width="24" height="24" src="logo.svg"> Create Pull Request
[![GitHub Marketplace](https://img.shields.io/badge/Marketplace-Create%20Pull%20Request-blue.svg?colorA=24292e&colorB=0366d6&style=flat&longCache=true&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAYAAAAfSC3RAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAM6wAADOsB5dZE0gAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAERSURBVCiRhZG/SsMxFEZPfsVJ61jbxaF0cRQRcRJ9hlYn30IHN/+9iquDCOIsblIrOjqKgy5aKoJQj4O3EEtbPwhJbr6Te28CmdSKeqzeqr0YbfVIrTBKakvtOl5dtTkK+v4HfA9PEyBFCY9AGVgCBLaBp1jPAyfAJ/AAdIEG0dNAiyP7+K1qIfMdonZic6+WJoBJvQlvuwDqcXadUuqPA1NKAlexbRTAIMvMOCjTbMwl1LtI/6KWJ5Q6rT6Ht1MA58AX8Apcqqt5r2qhrgAXQC3CZ6i1+KMd9TRu3MvA3aH/fFPnBodb6oe6HM8+lYHrGdRXW8M9bMZtPXUji69lmf5Cmamq7quNLFZXD9Rq7v0Bpc1o/tp0fisAAAAASUVORK5CYII=)](https://github.com/marketplace/actions/create-pull-request)
# <img width="24" height="24" src="docs/assets/logo.svg"> Create Pull Request
[![CI](https://github.com/peter-evans/create-pull-request/workflows/CI/badge.svg)](https://github.com/peter-evans/create-pull-request/actions?query=workflow%3ACI)
[![GitHub Marketplace](https://img.shields.io/badge/Marketplace-Create%20Pull%20Request-blue.svg?colorA=24292e&colorB=0366d6&style=flat&longCache=true&logo=github)](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.
@ -9,151 +10,257 @@ The changes will be automatically committed to a new branch and a pull request c
Create Pull Request action will:
1. Check for repository changes in the Actions workspace. This includes untracked (new) files as well as modified files.
2. Commit all changes to a new branch, or update an existing pull request branch. The commit will be made using the name and email of the `HEAD` commit author.
3. Create a pull request to merge the new branch into the currently active branch executing the workflow.
1. Check for repository changes in the Actions workspace. This includes:
- untracked (new) files
- tracked (modified) files
- commits made during the workflow that have not been pushed
2. Commit all changes to a new branch, or update an existing pull request branch.
3. Create a pull request to merge the new branch into the base&mdash;the branch checked out in the workflow.
## Documentation
- [Concepts, guidelines and advanced usage](docs/concepts-guidelines.md)
- [Examples](docs/examples.md)
- [Updating to v4](docs/updating.md)
## Usage
Linux
```yml
- uses: actions/checkout@v3
# Make changes to pull request here
- name: Create Pull Request
uses: peter-evans/create-pull-request@v1.5.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: peter-evans/create-pull-request@v4
```
Multi platform - Linux, MacOS, Windows (beta)
You can also pin to a [specific release](https://github.com/peter-evans/create-pull-request/releases) version in the format `@v4.x.x`
### Workflow permissions
For this action to work you must explicitly allow GitHub Actions to create pull requests.
This setting can be found in a repository's settings under Actions > General > Workflow permissions.
For repositories belonging to an organization, this setting can be managed by admins in organization settings under Actions > General > Workflow permissions.
### Action inputs
All inputs are **optional**. If not set, sensible defaults 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 cannot use the default `GITHUB_TOKEN`. See the [documentation here](docs/concepts-guidelines.md#triggering-further-workflow-runs) for workarounds.
| Name | Description | Default |
| --- | --- | --- |
| `token` | `GITHUB_TOKEN` (permissions `contents: write` and `pull-requests: write`) or a `repo` scoped [Personal Access Token (PAT)](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token). | `GITHUB_TOKEN` |
| `path` | Relative path under `GITHUB_WORKSPACE` to the repository. | `GITHUB_WORKSPACE` |
| `add-paths` | A comma or newline-separated list of file paths to commit. Paths should follow git's [pathspec](https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefpathspecapathspec) syntax. If no paths are specified, all new and modified files are added. See [Add specific paths](#add-specific-paths). | |
| `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. | `GitHub <noreply@github.com>` |
| `author` | The author name and email address in the format `Display Name <email@address.com>`. Defaults to the user who triggered the workflow run. | `${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>` |
| `signoff` | Add [`Signed-off-by`](https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---signoff) line by the committer at the end of the commit log message. | `false` |
| `branch` | The pull request branch name. | `create-pull-request/patch` |
| `delete-branch` | Delete the `branch` when closing pull requests, and when undeleted after merging. Recommend `true`. | `false` |
| `branch-suffix` | The branch suffix type when using the alternative branching strategy. Valid values are `random`, `timestamp` and `short-commit-hash`. See [Alternative strategy](#alternative-strategy---always-create-a-new-pull-request-branch) for details. | |
| `base` | Sets the pull request base branch. | Defaults to the branch checked out in the workflow. |
| `push-to-fork` | A fork of the checked-out parent repository to which the pull request branch will be pushed. e.g. `owner/repo-fork`. The pull request will be created to merge the fork's branch into the parent's base. See [push pull request branches to a fork](docs/concepts-guidelines.md#push-pull-request-branches-to-a-fork) for details. | |
| `title` | The title of the pull request. | `Changes by create-pull-request action` |
| `body` | The body of the pull request. | `Automated changes by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action` |
| `labels` | A comma or newline-separated list of labels. | |
| `assignees` | A comma or newline-separated list of assignees (GitHub usernames). | |
| `reviewers` | A comma or newline-separated list of reviewers (GitHub usernames) to request a review from. | |
| `team-reviewers` | A comma or newline-separated list of GitHub teams to request a review from. Note that a `repo` scoped [PAT](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) may be required. See [this issue](https://github.com/peter-evans/create-pull-request/issues/155). If using a GitHub App, refer to [Authenticating with GitHub App generated tokens](docs/concepts-guidelines.md#authenticating-with-github-app-generated-tokens) for the proper permissions. | |
| `milestone` | The number of the milestone to associate this pull request with. | |
| `draft` | Create a [draft pull request](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests#draft-pull-requests). It is not possible to change draft status after creation except through the web interface. | `false` |
For self-hosted runners behind a corporate proxy set the `https_proxy` environment variable.
```yml
- name: Create Pull Request
uses: peter-evans/create-pull-request@v1.5.0-multi
uses: peter-evans/create-pull-request@v4
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
https_proxy: http://<proxy_address>:<port>
```
**Note**: If you want pull requests created by this action to trigger an `on: pull_request` workflow then you must use a Personal Access Token instead of the default `GITHUB_TOKEN`.
See [this issue](https://github.com/peter-evans/create-pull-request/issues/48) for further details.
### Action outputs
### Environment variables
The following outputs can be used by subsequent workflow steps.
These variables are all optional. If not set, a default value will be used.
- `pull-request-number` - The pull request number.
- `pull-request-url` - The URL of the pull request.
- `pull-request-operation` - The pull request operation performed by the action, `created`, `updated` or `closed`.
- `pull-request-head-sha` - The commit SHA of the pull request branch.
- `COMMIT_MESSAGE` - The message to use when committing changes.
- `PULL_REQUEST_TITLE` - The title of the pull request.
- `PULL_REQUEST_BODY` - The body of the pull request.
- `PULL_REQUEST_LABELS` - A comma separated list of labels.
- `PULL_REQUEST_ASSIGNEES` - A comma separated list of assignees (GitHub usernames).
- `PULL_REQUEST_REVIEWERS` - A comma separated list of reviewers (GitHub usernames) to request a review from.
- `PULL_REQUEST_TEAM_REVIEWERS` - A comma separated list of GitHub teams to request a review from.
- `PULL_REQUEST_MILESTONE` - The number of the milestone to associate this pull request with.
- `PULL_REQUEST_BRANCH` - The branch name. See **Branch naming** below for details.
- `BRANCH_SUFFIX` - The branch suffix type. Valid values are `short-commit-hash` (default), `timestamp`, `random` and `none`. See **Branch naming** below for details.
Step outputs can be accessed as in the following example.
Note that in order to read the step outputs the action step must have an id.
Output environment variables
```yml
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v4
- name: Check outputs
if: ${{ steps.cpr.outputs.pull-request-number }}
run: |
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
```
- `PULL_REQUEST_NUMBER` - The number of the pull request created.
### Action behaviour
The following parameters are available for debugging and troubleshooting.
The default behaviour of the action is to create a pull request that will be continually updated with new changes until it is merged or closed.
Changes are committed and pushed to a fixed-name branch, the name of which can be configured with the `branch` input.
Any subsequent changes will be committed to the *same* branch and reflected in the open pull request.
- `DEBUG_EVENT` - If present, outputs the event data that triggered the workflow.
- `SKIP_IGNORE` - If present, the `ignore_event` function will be skipped.
How the action behaves:
### Branch naming
- If there are changes (i.e. a diff exists with the checked-out base branch), the changes will be pushed to a new `branch` and a pull request created.
- If there are no changes (i.e. no diff exists with the checked-out base branch), no pull request will be created and the action exits silently.
- If a pull request already exists it will be updated if necessary. Local changes in the Actions workspace, or changes on the base branch, can cause an update. If no update is required the action exits silently.
- If a pull request exists and new changes on the base branch make the pull request unnecessary (i.e. there is no longer a diff between the pull request branch and the base), the pull request is automatically closed. Additionally, if `delete-branch` is set to `true` the `branch` will be deleted.
For branch naming there are two strategies. Always create a new branch each time there are changes to be committed, OR, create a fixed-name pull request branch that will be updated with any new commits until it is merged or closed.
For further details about how the action works and usage guidelines, see [Concepts, guidelines and advanced usage](docs/concepts-guidelines.md).
#### Strategy A - Always create a new pull request branch (default)
#### Alternative strategy - Always create a new pull request branch
For this strategy there are three options to suffix the branch name.
The branch name is defined by the variable `PULL_REQUEST_BRANCH` and defaults to `create-pull-request/patch`. The following options are values for `BRANCH_SUFFIX`.
For some use cases it may be desirable to always create a new unique branch each time there are changes to be committed.
This strategy is *not recommended* because if not used carefully it could result in multiple pull requests being created unnecessarily. If in doubt, use the [default strategy](#action-behaviour) of creating an updating a fixed-name branch.
- `short-commit-hash` (default) - Commits will be made to a branch suffixed with the short SHA1 commit hash. e.g. `create-pull-request/patch-fcdfb59`, `create-pull-request/patch-394710b`
To use this strategy, set input `branch-suffix` with one of the following options.
- `random` - Commits will be made to a branch suffixed with a random alpha-numeric string. e.g. `create-pull-request/patch-6qj97jr`, `create-pull-request/patch-5jrjhvd`
- `timestamp` - Commits will be made to a branch suffixed by a timestamp. e.g. `create-pull-request/patch-1569322532`, `create-pull-request/patch-1569322552`
- `random` - Commits will be made to a branch suffixed with a random alpha-numeric string. This option should be used if multiple pull requests will be created during the execution of a workflow. e.g. `create-pull-request/patch-6qj97jr`, `create-pull-request/patch-5jrjhvd`
- `short-commit-hash` - Commits will be made to a branch suffixed with the short SHA1 commit hash. e.g. `create-pull-request/patch-fcdfb59`, `create-pull-request/patch-394710b`
#### Strategy B - Create and update a pull request branch
### Controlling committed files
To use this strategy, set `BRANCH_SUFFIX` to the value `none`. The variable `PULL_REQUEST_BRANCH` defaults to `create-pull-request/patch`. Commits will be made to this branch and a pull request created. Any subsequent changes will be committed to the *same* branch and reflected in the existing pull request.
The action defaults to adding all new and modified files.
If there are files that should not be included in the pull request, you can use the following methods to control the committed content.
### Ignoring files
#### Remove files
The most straightforward way to handle unwanted files is simply to remove them in a step before the action runs.
```yml
- run: |
rm -rf temp-dir
rm temp-file.txt
```
#### Ignore files
If there are files or directories you want to ignore you can simply add them to a `.gitignore` file at the root of your repository. The action will respect this file.
## Examples
#### Add specific paths
Here is an example that sets all the main environment variables.
You can control which files are committed with the `add-paths` input.
Paths should follow git's [pathspec](https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefpathspecapathspec) syntax.
All file changes that do not match one of the paths will be discarded.
```yml
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
add-paths: |
*.java
docs/*.md
```
#### Create your own commits
As well as relying on the action to handle uncommitted changes, you can additionally make your own commits before the action runs.
Note that the repository must be checked out on a branch with a remote, it won't work for [events which checkout a commit](docs/concepts-guidelines.md#events-which-checkout-a-commit).
```yml
steps:
- uses: actions/checkout@v3
- name: Create commits
run: |
git config user.name 'Peter Evans'
git config user.email 'peter-evans@users.noreply.github.com'
date +%s > report.txt
git commit -am "Modify tracked file during workflow"
date +%s > new-report.txt
git add -A
git commit -m "Add untracked file during workflow"
- name: Uncommitted change
run: date +%s > report.txt
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
```
### Create a project card
To create a project card for the pull request, pass the `pull-request-number` step output to [create-or-update-project-card](https://github.com/peter-evans/create-or-update-project-card) action.
```yml
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v4
- name: Create or Update Project Card
if: ${{ steps.cpr.outputs.pull-request-number }}
uses: peter-evans/create-or-update-project-card@v2
with:
project-name: My project
column-name: My column
issue-number: ${{ steps.cpr.outputs.pull-request-number }}
```
### Auto-merge
Auto-merge can be enabled on a pull request allowing it to be automatically merged once requirements have been satisfied.
See [enable-pull-request-automerge](https://github.com/peter-evans/enable-pull-request-automerge) action for usage details.
## Reference Example
The following workflow sets many of the action's inputs for reference purposes.
Check the [defaults](#action-inputs) to avoid setting inputs unnecessarily.
See [examples](docs/examples.md) for more realistic use cases.
```yml
on:
repository_dispatch:
types: [create-pull-request]
name: create-pull-request workflow
jobs:
createPullRequest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Create report file
- uses: actions/checkout@v3
- name: Make changes to pull request
run: date +%s > report.txt
- name: Create Pull Request
uses: peter-evans/create-pull-request@v1.5.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMIT_MESSAGE: Add report file
PULL_REQUEST_TITLE: '[Example] Add report file'
PULL_REQUEST_BODY: >
This PR is auto-generated by
[create-pull-request](https://github.com/peter-evans/create-pull-request).
PULL_REQUEST_LABELS: report, automated pr
PULL_REQUEST_ASSIGNEES: peter-evans
PULL_REQUEST_REVIEWERS: peter-evans
PULL_REQUEST_MILESTONE: 1
PULL_REQUEST_BRANCH: example-patches
BRANCH_SUFFIX: short-commit-hash
- name: Check output environment variable
run: echo "Pull Request Number - $PULL_REQUEST_NUMBER"
id: cpr
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.PAT }}
commit-message: Update report
committer: GitHub <noreply@github.com>
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
signoff: false
branch: example-patches
delete-branch: true
title: '[Example] Update report'
body: |
Update report
- Updated with *today's* date
- Auto-generated by [create-pull-request][1]
[1]: https://github.com/peter-evans/create-pull-request
labels: |
report
automated pr
assignees: peter-evans
reviewers: peter-evans
team-reviewers: |
owners
maintainers
milestone: 1
draft: false
```
This configuration will create pull requests that look like this:
An example based on the above reference configuration creates pull requests that look like this:
![Pull Request Example](https://github.com/peter-evans/create-pull-request/blob/master/pull-request-example.png?raw=true)
### Dynamic configuration using variables
The following examples show how configuration for the action can be dynamically defined in a previous workflow step.
The recommended method is to use `set-output`. Note that the step where output variables are defined must have an id.
```yml
- name: Set output variables
id: vars
run: |
echo ::set-output name=pr_title::"[Test] Add report file $(date +%d-%m-%Y)"
echo ::set-output name=pr_body::"This PR was auto-generated on $(date +%d-%m-%Y) \
by [create-pull-request](https://github.com/peter-evans/create-pull-request)."
- name: Create Pull Request
uses: peter-evans/create-pull-request@v1.5.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PULL_REQUEST_TITLE: ${{ steps.vars.outputs.pr_title }}
PULL_REQUEST_BODY: ${{ steps.vars.outputs.pr_body }}
```
Since the action reads environment variables from the system, it's technically not necessary to explicitly pass them as long as they exist in the environment. So the following method using `set-env` *also* works, but explicitly passing the configuration parameters using the previous method is perferred for its clarity.
```yml
- name: Set environment variables
run: |
echo ::set-env name=PULL_REQUEST_TITLE::"[Test] Add report file $(date +%d-%m-%Y)"
echo ::set-env name=PULL_REQUEST_BODY::"This PR was auto-generated on $(date +%d-%m-%Y) \
by [create-pull-request](https://github.com/peter-evans/create-pull-request)."
- name: Create Pull Request
uses: peter-evans/create-pull-request@v1.5.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
![Pull Request Example](docs/assets/pull-request-example.png)
## License

File diff suppressed because it is too large Load Diff

40
__test__/entrypoint.sh Executable file
View File

@ -0,0 +1,40 @@
#!/bin/sh -l
set -euo pipefail
# Save the working directory
WORKINGDIR=$PWD
# Create and serve a remote repo
mkdir -p /git/remote
git init --bare /git/remote/test-base.git
git daemon --verbose --enable=receive-pack --base-path=/git/remote --export-all /git/remote &>/dev/null &
# Give the daemon time to start
sleep 2
# Create a local clone and make an initial commit
mkdir -p /git/local
git clone git://127.0.0.1/test-base.git /git/local/test-base
cd /git/local/test-base
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
echo "#test-base" > README.md
git add .
git commit -m "initial commit"
git push -u
git log -1 --pretty=oneline
git config --global --unset user.email
git config --global --unset user.name
git config -l
# Clone a server-side fork of the base repo
cd $WORKINGDIR
git clone --mirror git://127.0.0.1/test-base.git /git/remote/test-fork.git
cd /git/remote/test-fork.git
git log -1 --pretty=oneline
# Restore the working directory
cd $WORKINGDIR
# Execute integration tests
jest int --runInBand

View File

@ -0,0 +1,49 @@
import {GitCommandManager} from '../lib/git-command-manager'
import {GitAuthHelper} from '../lib/git-auth-helper'
const REPO_PATH = '/git/local/test-base'
const extraheaderConfigKey = 'http.https://github.com/.extraheader'
describe('git-auth-helper tests', () => {
let git: GitCommandManager
let gitAuthHelper: GitAuthHelper
beforeAll(async () => {
git = await GitCommandManager.create(REPO_PATH)
gitAuthHelper = new GitAuthHelper(git)
})
it('tests save and restore with no persisted auth', async () => {
await gitAuthHelper.savePersistedAuth()
await gitAuthHelper.restorePersistedAuth()
})
it('tests configure and removal of auth', async () => {
await gitAuthHelper.configureToken('github-token')
expect(await git.configExists(extraheaderConfigKey)).toBeTruthy()
expect(await git.getConfigValue(extraheaderConfigKey)).toEqual(
'AUTHORIZATION: basic eC1hY2Nlc3MtdG9rZW46Z2l0aHViLXRva2Vu'
)
await gitAuthHelper.removeAuth()
expect(await git.configExists(extraheaderConfigKey)).toBeFalsy()
})
it('tests save and restore of persisted auth', async () => {
const extraheaderConfigValue = 'AUTHORIZATION: basic ***persisted-auth***'
await git.config(extraheaderConfigKey, extraheaderConfigValue)
await gitAuthHelper.savePersistedAuth()
const exists = await git.configExists(extraheaderConfigKey)
expect(exists).toBeFalsy()
await gitAuthHelper.restorePersistedAuth()
const configValue = await git.getConfigValue(extraheaderConfigKey)
expect(configValue).toEqual(extraheaderConfigValue)
await gitAuthHelper.removeAuth()
})
})

23
__test__/integration-tests.sh Executable file
View File

@ -0,0 +1,23 @@
#!/usr/bin/env bash
set -euo pipefail
IMAGE="cpr-integration-tests:latest"
ARG1=${1:-}
if [[ "$(docker images -q $IMAGE 2> /dev/null)" == "" || $ARG1 == "build" ]]; then
echo "Building Docker image $IMAGE ..."
cat > Dockerfile << EOF
FROM node:12-alpine
RUN apk --no-cache add git git-daemon
RUN npm install jest jest-environment-jsdom --global
WORKDIR /cpr
COPY __test__/entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
EOF
docker build --no-cache -t $IMAGE .
rm Dockerfile
fi
docker run -v $PWD:/cpr $IMAGE

130
__test__/utils.unit.test.ts Normal file
View File

@ -0,0 +1,130 @@
import * as path from 'path'
import * as utils from '../lib/utils'
const originalGitHubWorkspace = process.env['GITHUB_WORKSPACE']
describe('utils tests', () => {
beforeAll(() => {
// GitHub workspace
process.env['GITHUB_WORKSPACE'] = __dirname
})
afterAll(() => {
// Restore GitHub workspace
delete process.env['GITHUB_WORKSPACE']
if (originalGitHubWorkspace) {
process.env['GITHUB_WORKSPACE'] = originalGitHubWorkspace
}
})
test('getStringAsArray splits string input by newlines and commas', async () => {
const array = utils.getStringAsArray('1, 2, 3\n4, 5, 6')
expect(array.length).toEqual(6)
const array2 = utils.getStringAsArray('')
expect(array2.length).toEqual(0)
})
test('getRepoPath successfully returns the path to the repository', async () => {
expect(utils.getRepoPath()).toEqual(process.env['GITHUB_WORKSPACE'])
expect(utils.getRepoPath('foo')).toEqual(
path.resolve(process.env['GITHUB_WORKSPACE'] || '', 'foo')
)
})
test('getRemoteDetail successfully parses remote URLs', async () => {
const remote1 = utils.getRemoteDetail(
'https://github.com/peter-evans/create-pull-request'
)
expect(remote1.protocol).toEqual('HTTPS')
expect(remote1.repository).toEqual('peter-evans/create-pull-request')
const remote2 = utils.getRemoteDetail(
'https://xxx:x-oauth-basic@github.com/peter-evans/create-pull-request'
)
expect(remote2.protocol).toEqual('HTTPS')
expect(remote2.repository).toEqual('peter-evans/create-pull-request')
const remote3 = utils.getRemoteDetail(
'git@github.com:peter-evans/create-pull-request.git'
)
expect(remote3.protocol).toEqual('SSH')
expect(remote3.repository).toEqual('peter-evans/create-pull-request')
const remote4 = utils.getRemoteDetail(
'https://github.com/peter-evans/create-pull-request.git'
)
expect(remote4.protocol).toEqual('HTTPS')
expect(remote4.repository).toEqual('peter-evans/create-pull-request')
})
test('getRemoteDetail fails to parse a remote URL', async () => {
const remoteUrl = 'https://github.com/peter-evans'
try {
utils.getRemoteDetail(remoteUrl)
// Fail the test if an error wasn't thrown
expect(true).toEqual(false)
} catch (e: any) {
expect(e.message).toEqual(
`The format of '${remoteUrl}' is not a valid GitHub repository URL`
)
}
})
test('getRemoteUrl successfully returns remote URLs', async () => {
const url1 = utils.getRemoteUrl('HTTPS', 'peter-evans/create-pull-request')
expect(url1).toEqual('https://github.com/peter-evans/create-pull-request')
const url2 = utils.getRemoteUrl('SSH', 'peter-evans/create-pull-request')
expect(url2).toEqual('git@github.com:peter-evans/create-pull-request.git')
})
test('secondsSinceEpoch returns the number of seconds since the Epoch', async () => {
const seconds = `${utils.secondsSinceEpoch()}`
expect(seconds.length).toEqual(10)
})
test('randomString returns strings of length 7', async () => {
for (let i = 0; i < 1000; i++) {
expect(utils.randomString().length).toEqual(7)
}
})
test('parseDisplayNameEmail successfully parses display name email formats', async () => {
const parsed1 = utils.parseDisplayNameEmail('abc def <abc@def.com>')
expect(parsed1.name).toEqual('abc def')
expect(parsed1.email).toEqual('abc@def.com')
const parsed2 = utils.parseDisplayNameEmail(
'github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>'
)
expect(parsed2.name).toEqual('github-actions[bot]')
expect(parsed2.email).toEqual(
'41898282+github-actions[bot]@users.noreply.github.com'
)
})
test('parseDisplayNameEmail fails to parse display name email formats', async () => {
const displayNameEmail1 = 'abc@def.com'
try {
utils.parseDisplayNameEmail(displayNameEmail1)
// Fail the test if an error wasn't thrown
expect(true).toEqual(false)
} catch (e: any) {
expect(e.message).toEqual(
`The format of '${displayNameEmail1}' is not a valid email address with display name`
)
}
const displayNameEmail2 = ' < >'
try {
utils.parseDisplayNameEmail(displayNameEmail2)
// Fail the test if an error wasn't thrown
expect(true).toEqual(false)
} catch (e: any) {
expect(e.message).toEqual(
`The format of '${displayNameEmail2}' is not a valid email address with display name`
)
}
})
})

View File

@ -1,9 +1,86 @@
name: 'Create Pull Request'
author: 'Peter Evans'
description: 'Creates a pull request for changes to your repository in the actions workspace'
inputs:
token:
description: 'GITHUB_TOKEN or a `repo` scoped Personal Access Token (PAT)'
default: ${{ github.token }}
path:
description: >
Relative path under $GITHUB_WORKSPACE to the repository.
Defaults to $GITHUB_WORKSPACE.
add-paths:
description: >
A comma or newline-separated list of file paths to commit.
Paths should follow git's pathspec syntax.
Defaults to adding all new and modified files.
commit-message:
description: 'The message to use when committing changes.'
default: '[create-pull-request] automated change'
committer:
description: >
The committer name and email address in the format `Display Name <email@address.com>`.
Defaults to the GitHub Actions bot user.
default: 'GitHub <noreply@github.com>'
author:
description: >
The author name and email address in the format `Display Name <email@address.com>`.
Defaults to the user who triggered the workflow run.
default: '${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>'
signoff:
description: 'Add `Signed-off-by` line by the committer at the end of the commit log message.'
default: false
branch:
description: 'The pull request branch name.'
default: 'create-pull-request/patch'
delete-branch:
description: >
Delete the `branch` when closing pull requests, and when undeleted after merging.
Recommend `true`.
default: false
branch-suffix:
description: 'The branch suffix type when using the alternative branching strategy.'
base:
description: >
The pull request base branch.
Defaults to the branch checked out in the workflow.
push-to-fork:
description: >
A fork of the checked out parent repository to which the pull request branch will be pushed.
e.g. `owner/repo-fork`.
The pull request will be created to merge the fork's branch into the parent's base.
title:
description: 'The title of the pull request.'
default: 'Changes by create-pull-request action'
body:
description: 'The body of the pull request.'
default: 'Automated changes by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action'
labels:
description: 'A comma or newline separated list of labels.'
assignees:
description: 'A comma or newline separated list of assignees (GitHub usernames).'
reviewers:
description: 'A comma or newline separated list of reviewers (GitHub usernames) to request a review from.'
team-reviewers:
description: >
A comma or newline separated list of GitHub teams to request a review from.
Note that a `repo` scoped Personal Access Token (PAT) may be required.
milestone:
description: 'The number of the milestone to associate the pull request with.'
draft:
description: 'Create a draft pull request. It is not possible to change draft status after creation except through the web interface'
default: false
outputs:
pull-request-number:
description: 'The pull request number'
pull-request-url:
description: 'The URL of the pull request.'
pull-request-operation:
description: 'The pull request operation performed by the action, `created`, `updated` or `closed`.'
pull-request-head-sha:
description: 'The commit SHA of the pull request branch.'
runs:
using: 'docker'
image: 'docker://peterevans/create-pull-request:1.5.1'
using: 'node16'
main: 'dist/index.js'
branding:
icon: 'git-pull-request'
icon: 'git-pull-request'
color: 'gray-dark'

View File

@ -1,221 +0,0 @@
#!/usr/bin/env python3
''' Create Pull Request '''
import json
import os
import random
import string
import sys
import time
from git import Repo
from github import Github
def get_github_event(github_event_path):
with open(github_event_path) as f:
github_event = json.load(f)
if bool(os.environ.get('DEBUG_EVENT')):
print(os.environ['GITHUB_EVENT_NAME'])
print(json.dumps(github_event, sort_keys=True, indent=2))
return github_event
def ignore_event(event_name, event_data):
if event_name == "push":
# Ignore push events on deleted branches
# The event we want to ignore occurs when a PR is created but the repository owner decides
# not to commit the changes. They close the PR and delete the branch. This creates a
# "push" event that we want to ignore, otherwise it will create another branch and PR on
# the same commit.
deleted = "{deleted}".format(**event_data)
if deleted == "True":
print("Ignoring delete branch event.")
return True
ref = "{ref}".format(**event_data)
if not ref.startswith('refs/heads/'):
print("Ignoring events for tags and remotes.")
return True
return False
def get_head_short_sha1(repo):
return repo.git.rev_parse('--short', 'HEAD')
def get_random_suffix(size=7, chars=string.ascii_lowercase + string.digits):
return ''.join(random.choice(chars) for _ in range(size))
def remote_branch_exists(repo, branch):
for ref in repo.remotes.origin.refs:
if ref.name == ("origin/%s" % branch):
return True
return False
def get_author_default(event_name, event_data):
if event_name == "push":
email = "{head_commit[author][email]}".format(**event_data)
name = "{head_commit[author][name]}".format(**event_data)
else:
email = os.environ['GITHUB_ACTOR'] + '@users.noreply.github.com'
name = os.environ['GITHUB_ACTOR']
return email, name
def set_git_config(git, email, name):
git.config('--global', 'user.email', '"%s"' % email)
git.config('--global', 'user.name', '"%s"' % name)
def set_git_remote_url(git, token, github_repository):
git.remote('set-url', 'origin', "https://x-access-token:%s@github.com/%s" % (token, github_repository))
def checkout_branch(git, remote_exists, branch):
if remote_exists:
git.stash('--include-untracked')
git.checkout(branch)
try:
git.stash('pop')
except:
git.checkout('--theirs', '.')
git.reset()
else:
git.checkout('HEAD', b=branch)
def push_changes(git, branch, commit_message):
git.add('-A')
git.commit(m=commit_message)
return git.push('-f', '--set-upstream', 'origin', branch)
def cs_string_to_list(str):
# Split the comma separated string into a list
l = [i.strip() for i in str.split(',')]
# Remove empty strings
return list(filter(None, l))
def process_event(event_name, event_data, repo, branch, base, remote_exists):
# Fetch required environment variables
github_token = os.environ['GITHUB_TOKEN']
github_repository = os.environ['GITHUB_REPOSITORY']
# Fetch optional environment variables with default values
commit_message = os.getenv(
'COMMIT_MESSAGE',
"Auto-committed changes by create-pull-request action")
title = os.getenv(
'PULL_REQUEST_TITLE',
"Auto-generated by create-pull-request action")
body = os.getenv(
'PULL_REQUEST_BODY', "Auto-generated pull request by "
"[create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub Action")
# Fetch optional environment variables with no default values
pull_request_labels = os.environ.get('PULL_REQUEST_LABELS')
pull_request_assignees = os.environ.get('PULL_REQUEST_ASSIGNEES')
pull_request_milestone = os.environ.get('PULL_REQUEST_MILESTONE')
pull_request_reviewers = os.environ.get('PULL_REQUEST_REVIEWERS')
pull_request_team_reviewers = os.environ.get('PULL_REQUEST_TEAM_REVIEWERS')
# Update URL for the 'origin' remote
set_git_remote_url(repo.git, github_token, github_repository)
# Push the local changes to the remote branch
print("Pushing changes.")
push_result = push_changes(repo.git, branch, commit_message)
print(push_result)
# If the remote existed then a PR likely exists and we can finish here
if remote_exists:
print("Updated pull request branch %s." % branch)
sys.exit()
# Create the pull request
print("Creating a request to pull %s into %s." % (branch, base))
github_repo = Github(github_token).get_repo(github_repository)
pull_request = github_repo.create_pull(
title=title,
body=body,
base=base,
head=branch)
print("Created pull request %d." % pull_request.number)
os.system('echo ::set-env name=PULL_REQUEST_NUMBER::%d' % pull_request.number)
# Set labels, assignees and milestone
if pull_request_labels is not None:
print("Applying labels")
pull_request.as_issue().edit(labels=cs_string_to_list(pull_request_labels))
if pull_request_assignees is not None:
print("Applying assignees")
pull_request.as_issue().edit(assignees=cs_string_to_list(pull_request_assignees))
if pull_request_milestone is not None:
print("Applying milestone")
milestone = github_repo.get_milestone(int(pull_request_milestone))
pull_request.as_issue().edit(milestone=milestone)
# Set pull request reviewers and team reviewers
if pull_request_reviewers is not None:
print("Requesting reviewers")
pull_request.create_review_request(reviewers=cs_string_to_list(pull_request_reviewers))
if pull_request_team_reviewers is not None:
print("Requesting team reviewers")
pull_request.create_review_request(team_reviewers=cs_string_to_list(pull_request_team_reviewers))
# Get the JSON event data
event_name = os.environ['GITHUB_EVENT_NAME']
event_data = get_github_event(os.environ['GITHUB_EVENT_PATH'])
# Check if this event should be ignored
skip_ignore_event = bool(os.environ.get('SKIP_IGNORE'))
if skip_ignore_event or not ignore_event(event_name, event_data):
# Set the repo to the working directory
repo = Repo(os.getcwd())
# Fetch/Set the branch name
branch = os.getenv('PULL_REQUEST_BRANCH', 'create-pull-request/patch')
# Set the current branch as the target base branch
base = os.environ['GITHUB_REF'][11:]
# Skip if the current branch is a PR branch created by this action
if base.startswith(branch):
print("Branch '%s' was created by this action. Skipping." % base)
sys.exit()
# Fetch an optional environment variable to determine the branch suffix
branch_suffix = os.getenv('BRANCH_SUFFIX', 'short-commit-hash')
if branch_suffix == "short-commit-hash":
# Suffix with the short SHA1 hash
branch = "%s-%s" % (branch, get_head_short_sha1(repo))
elif branch_suffix == "timestamp":
# Suffix with the current timestamp
branch = "%s-%s" % (branch, int(time.time()))
elif branch_suffix == "random":
# Suffix with the current timestamp
branch = "%s-%s" % (branch, get_random_suffix())
# Check if the remote branch exists
remote_exists = remote_branch_exists(repo, branch)
# If using short commit hash prefixes, check if a remote
# branch already exists for this HEAD commit
if branch_suffix == 'short-commit-hash' and remote_exists:
print("Pull request branch '%s' already exists for this commit. Skipping." % branch)
sys.exit()
# Get the default for author email and name
author_email, author_name = get_author_default(event_name, event_data)
# Set commit author overrides
author_email = os.getenv('COMMIT_AUTHOR_EMAIL', author_email)
author_name = os.getenv('COMMIT_AUTHOR_NAME', author_name)
# Set git configuration
set_git_config(repo.git, author_email, author_name)
# Checkout branch
checkout_branch(repo.git, remote_exists, branch)
# Check if there are changes to pull request
if repo.is_dirty() or len(repo.untracked_files) > 0:
print("Repository has modified or untracked files.")
process_event(event_name, event_data, repo, branch, base, remote_exists)
else:
print("Repository has no modified or untracked files. Skipping.")

13194
dist/index.js vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,68 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>create-pull-request GitHub action</title>
</head>
<body>
<!-- partial:index.partial.html -->
<div id="graph-container"></div>
<!-- partial -->
<script src='https://cdn.jsdelivr.net/npm/@gitgraph/js'></script>
<script>
const graphContainer = document.getElementById("graph-container");
const customTemplate = GitgraphJS.templateExtend(GitgraphJS.TemplateName.Metro, {
commit: {
message: {
displayAuthor: false,
displayHash: false,
},
},
});
// Instantiate the graph.
const gitgraph = GitgraphJS.createGitgraph(graphContainer, {
template: customTemplate,
orientation: "vertical-reverse"
});
const main = gitgraph.branch("main");
main.commit("Last commit on base");
const localMain = gitgraph.branch("<#1> main (local)");
localMain.commit({
subject: "<uncommitted changes>",
body: "Changes to the local base during the workflow",
})
const remotePatch = gitgraph.branch("create-pull-request/patch");
remotePatch.merge({
branch: localMain,
commitOptions: {
subject: "[create-pull-request] automated change",
body: "Changes pushed to create the remote branch",
},
});
main.commit("New commit on base");
const localMain2 = gitgraph.branch("<#2> main (local)");
localMain2.commit({
subject: "<uncommitted changes>",
body: "Changes to the updated local base during the workflow",
})
remotePatch.merge({
branch: localMain2,
commitOptions: {
subject: "[create-pull-request] automated change",
body: "Changes force pushed to update the remote branch",
},
});
main.merge(remotePatch);
</script>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 KiB

View File

Before

Width:  |  Height:  |  Size: 416 B

After

Width:  |  Height:  |  Size: 416 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 327 KiB

370
docs/concepts-guidelines.md Normal file
View File

@ -0,0 +1,370 @@
# Concepts, guidelines and advanced usage
This document covers terminology, how the action works, general usage guidelines, and advanced usage.
- [Terminology](#terminology)
- [Events and checkout](#events-and-checkout)
- [How the action works](#how-the-action-works)
- [Guidelines](#guidelines)
- [Providing a consistent base](#providing-a-consistent-base)
- [Events which checkout a commit](#events-which-checkout-a-commit)
- [Restrictions on repository forks](#restrictions-on-repository-forks)
- [Triggering further workflow runs](#triggering-further-workflow-runs)
- [Security](#security)
- [Advanced usage](#advanced-usage)
- [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 pull request branches to a fork](#push-pull-request-branches-to-a-fork)
- [Authenticating with GitHub App generated tokens](#authenticating-with-github-app-generated-tokens)
- [GPG commit signature verification](#gpg-commit-signature-verification)
- [Running in a container or on self-hosted runners](#running-in-a-container-or-on-self-hosted-runners)
## Terminology
[Pull requests](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests#about-pull-requests) are proposed changes to a repository branch that can be reviewed by a repository's collaborators before being accepted or rejected.
A pull request references two branches:
- The `base` of a pull request is the branch you intend to change once the proposed changes are merged.
- The `branch` of a pull request represents what you intend the `base` to look like when merged. It is the `base` branch *plus* changes that have been made to it.
## Events and checkout
This action expects repositories to be checked out with the official GitHub Actions [checkout](https://github.com/actions/checkout) action.
For each [event type](https://docs.github.com/en/actions/reference/events-that-trigger-workflows) there is a default `GITHUB_SHA` that will be checked out.
The default can be overridden by specifying a `ref` on checkout.
```yml
- uses: actions/checkout@v3
with:
ref: develop
```
## How the action works
Unless the `base` input is supplied, the action expects the target repository to be checked out on the pull request `base`&mdash;the branch you intend to modify with the proposed changes.
Workflow steps:
1. Checkout the `base` branch
2. Make changes
3. Execute `create-pull-request` action
The following git diagram shows how the action creates and updates a pull request branch.
![Create Pull Request GitGraph](assets/cpr-gitgraph.png)
## Guidelines
### Providing a consistent base
For the action to work correctly it should be executed in a workflow that checks out a *consistent* base branch. This will be the base of the pull request unless overridden with the `base` input.
This means your workflow should be consistently checking out the branch that you intend to modify once the PR is merged.
In the following example, the [`push`](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#push) and [`create`](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#create) events both trigger the same workflow. This will cause the checkout action to checkout inconsistent branches and commits. Do *not* do this. It will cause multiple pull requests to be created for each additional `base` the action is executed against.
```yml
on:
push:
create:
jobs:
example:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
```
There may be use cases where it makes sense to execute the workflow on a branch that is not the base of the pull request. In these cases, the base branch can be specified with the `base` action input. The action will attempt to rebase changes made during the workflow on to the actual base.
### Events which checkout a commit
The [default checkout](#events-and-checkout) for the majority of events will leave the repository checked out on a branch.
However, some events such as `release` and `pull_request` will leave the repository in a "detached HEAD" state.
This is because they checkout a commit, not a branch.
In these cases, you *must supply* the `base` input so the action can rebase changes made during the workflow for the pull request.
Workflows triggered by [`pull_request`](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#pull_request) events will by default check out a merge commit. Set the `base` input as follows to base the new pull request on the current pull request's branch.
```yml
- uses: peter-evans/create-pull-request@v4
with:
base: ${{ github.head_ref }}
```
Workflows triggered by [`release`](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#release) events will by default check out a tag. For most use cases, you will need to set the `base` input to the branch name of the tagged commit.
```yml
- uses: peter-evans/create-pull-request@v4
with:
base: main
```
### Restrictions on repository forks
GitHub Actions have imposed restrictions on workflow runs triggered by public repository forks.
Private repositories can be configured to [enable workflows](https://docs.github.com/en/github/administering-a-repository/disabling-or-limiting-github-actions-for-a-repository#enabling-workflows-for-private-repository-forks) from forks to run without restriction.
The restrictions apply to the `pull_request` event triggered by a fork opening a pull request in the upstream repository.
- Events from forks cannot access secrets, except for the default `GITHUB_TOKEN`.
> With the exception of GITHUB_TOKEN, secrets are not passed to the runner when a workflow is triggered from a forked repository.
[GitHub Actions: Using encrypted secrets in a workflow](https://docs.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets#using-encrypted-secrets-in-a-workflow)
- The `GITHUB_TOKEN` has read-only access when an event is triggered by a forked repository.
[GitHub Actions: Permissions for the GITHUB_TOKEN](https://docs.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token#permissions-for-the-github_token)
These restrictions mean that during a `pull_request` event triggered by a forked repository, actions have no write access to GitHub resources and will fail on any attempt.
A job condition can be added to prevent workflows from executing when triggered by a repository fork.
```yml
on: pull_request
jobs:
example:
runs-on: ubuntu-latest
# Check if the event is not triggered by a fork
if: github.event.pull_request.head.repo.full_name == github.repository
```
For further reading regarding the security of pull requests, see this GitHub blog post titled [Keeping your GitHub Actions and workflows secure: Preventing pwn requests](https://securitylab.github.com/research/github-actions-preventing-pwn-requests/)
### Triggering further workflow runs
Pull requests created by the action using the default `GITHUB_TOKEN` cannot trigger other workflows. If you have `on: pull_request` or `on: push` workflows acting as checks on pull requests, they will not run.
> When you use the repository's `GITHUB_TOKEN` to perform tasks, events triggered by the `GITHUB_TOKEN` will not create a new workflow run. This prevents you from accidentally creating recursive workflow runs. For example, if a workflow run pushes code using the repository's `GITHUB_TOKEN`, a new workflow will not run even when the repository contains a workflow configured to run when `push` events occur.
[GitHub Actions: Triggering a workflow from a workflow](https://docs.github.com/en/actions/using-workflows/triggering-a-workflow#triggering-a-workflow-from-a-workflow)
#### Workarounds to trigger further workflow runs
There are a number of workarounds with different pros and cons.
- Use the default `GITHUB_TOKEN` and allow the action to create pull requests that have no checks enabled. Manually close pull requests and immediately reopen them. This will enable `on: pull_request` workflows to run and be added as checks. To prevent merging of pull requests without checks erroneously, use [branch protection rules](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests).
- Use a `repo` scoped [Personal Access Token (PAT)](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) created on an account that has write access to the repository that pull requests are being created in. This is the standard workaround and [recommended by GitHub](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#triggering-new-workflows-using-a-personal-access-token). However, the PAT cannot be scoped to a specific repository so the token becomes a very sensitive secret. If this is a concern, the PAT can instead be created for a dedicated [machine account](https://docs.github.com/en/github/site-policy/github-terms-of-service#3-account-requirements) that has collaborator access to the repository. Also note that because the account that owns the PAT will be the creator of pull requests, that user account will be unable to perform actions such as request changes or approve the pull request.
- Use [SSH (deploy keys)](#push-using-ssh-deploy-keys) to push the pull request branch. This is arguably more secure than using a PAT because deploy keys can be set per repository. However, this method will only trigger `on: push` workflows.
- Use a [machine account that creates pull requests from its own fork](#push-pull-request-branches-to-a-fork). This is the most secure because the PAT created only grants access to the machine account's fork, not the main repository. This method will trigger `on: pull_request` workflows to run. Workflows triggered `on: push` will not run because the push event is in the fork.
- Use a [GitHub App to generate a token](#authenticating-with-github-app-generated-tokens) that can be used with this action. GitHub App generated tokens are more secure than using a PAT because GitHub App access permissions can be set with finer granularity and are scoped to only repositories where the App is installed. This method will trigger both `on: push` and `on: pull_request` workflows.
### 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.
Alternatively, use the action directly and reference the commit hash for the version you want to target.
```yml
- uses: thirdparty/foo-action@172ec762f2ac8e050062398456fccd30444f8f30
```
This action uses [ncc](https://github.com/vercel/ncc) to compile the Node.js code and dependencies into a single JavaScript file under the [dist](https://github.com/peter-evans/create-pull-request/tree/main/dist) directory.
## Advanced usage
### Creating pull requests in a remote repository
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://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) is required.
```yml
- uses: actions/checkout@v3
with:
token: ${{ secrets.PAT }}
repository: owner/repo
# Make changes to pull request here
- uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.PAT }}
```
### Push using SSH (deploy keys)
[Deploy keys](https://developer.github.com/v3/guides/managing-deploy-keys/#deploy-keys) can be set per repository and so are arguably more secure than using a `repo` scoped [Personal Access Token (PAT)](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token).
Allowing the action to push with a configured deploy key will trigger `on: push` workflows. This makes it an alternative to using a PAT to trigger checks for pull requests.
Note that you cannot use deploy keys alone to [create a pull request in a remote repository](#creating-pull-requests-in-a-remote-repository) because then using a PAT would become a requirement. This method only makes sense if creating a pull request in the repository where the workflow is running.
How to use SSH (deploy keys) with create-pull-request action:
1. [Create a new SSH key pair](https://docs.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."
3. Add a secret to the repository containing the entire contents of the private key.
4. As shown in the example below, configure `actions/checkout` to use the deploy key you have created.
```yml
steps:
- uses: actions/checkout@v3
with:
ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}
# Make changes to pull request here
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
```
### 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://docs.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://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token).
4. Logout and log back into your main user account.
5. Add a secret to your repository containing the above PAT.
6. As shown in the following example workflow, set the `push-to-fork` input to the full repository name of the fork.
```yaml
- uses: actions/checkout@v3
# Make changes to pull request here
- uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.MACHINE_USER_PAT }}
push-to-fork: machine-user/fork-of-repository
```
### Authenticating with GitHub App generated tokens
A GitHub App can be created for the sole purpose of generating tokens for use with GitHub actions.
These tokens can be used in place of `GITHUB_TOKEN` or a [Personal Access Token (PAT)](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token).
GitHub App generated tokens are more secure than using a PAT because GitHub App access permissions can be set with finer granularity and are scoped to only repositories where the App is installed.
1. Create a minimal [GitHub App](https://docs.github.com/en/developers/apps/creating-a-github-app), setting the following fields:
- Set `GitHub App name`.
- Set `Homepage URL` to anything you like, such as your GitHub profile page.
- Uncheck `Active` under `Webhook`. You do not need to enter a `Webhook URL`.
- Under `Repository permissions: Contents` select `Access: Read & write`.
- Under `Repository permissions: Pull requests` select `Access: Read & write`.
- Under `Organization permissions: Members` select `Access: Read-only`.
- **NOTE**: Only needed if you would like add teams as reviewers to PRs.
2. Create a Private key from the App settings page and store it securely.
3. Install the App on any repository where workflows will run requiring tokens.
4. Set secrets on your repository containing the GitHub App ID, and the private key you created in step 2. e.g. `APP_ID`, `APP_PRIVATE_KEY`.
5. The following example workflow shows how to use [tibdex/github-app-token](https://github.com/tibdex/github-app-token) to generate a token for use with this action.
```yaml
steps:
- uses: actions/checkout@v3
- uses: tibdex/github-app-token@v1
id: generate-token
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}
# Make changes to pull request here
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
token: ${{ steps.generate-token.outputs.token }}
```
### GPG commit signature verification
The action can use GPG to sign commits with a GPG key that you generate yourself.
1. Follow GitHub's guide to [generate a new GPG key](https://docs.github.com/en/github/authenticating-to-github/generating-a-new-gpg-key).
2. [Add the public key](https://docs.github.com/en/github/authenticating-to-github/adding-a-new-gpg-key-to-your-github-account) to the user account associated with the [Personal Access Token (PAT)](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) that you will use with the action.
3. Copy the private key to your clipboard, replacing `email@example.com` with the email address of your GPG key.
```
# macOS
gpg --armor --export-secret-key email@example.com | pbcopy
```
4. Paste the private key into a repository secret where the workflow will run. e.g. `GPG_PRIVATE_KEY`
5. Create another repository secret for the key's passphrase, if applicable. e.g. `GPG_PASSPHRASE`
6. The following example workflow shows how to use [crazy-max/ghaction-import-gpg](https://github.com/crazy-max/ghaction-import-gpg) to import your GPG key and allow the action to sign commits.
Note that the `committer` email address *MUST* match the email address used to create your GPG key.
```yaml
steps:
- uses: actions/checkout@v3
- uses: crazy-max/ghaction-import-gpg@v3
with:
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.GPG_PASSPHRASE }}
git-user-signingkey: true
git-commit-gpgsign: true
# Make changes to pull request here
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.PAT }}
committer: example <email@example.com>
```
### Running in a container or on self-hosted runners
This action can be run inside a container, or on [self-hosted runners](https://docs.github.com/en/actions/hosting-your-own-runners), by installing the necessary dependencies.
This action requires `git` to be installed and on the `PATH`. Note that `actions/checkout` requires Git 2.18 or higher to be installed, otherwise it will just download the source of the repository instead of cloning it.
The following examples of running in a container show the dependencies being installed during the workflow, but they could also be pre-installed in a custom image.
**Alpine container example:**
```yml
jobs:
createPullRequestAlpine:
runs-on: ubuntu-latest
container:
image: alpine
steps:
- name: Install dependencies
run: apk --no-cache add git
- uses: actions/checkout@v3
# Make changes to pull request here
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
```
**Ubuntu container example:**
```yml
jobs:
createPullRequestAlpine:
runs-on: ubuntu-latest
container:
image: ubuntu
steps:
- name: Install dependencies
run: |
apt-get update
apt-get install -y software-properties-common
add-apt-repository -y ppa:git-core/ppa
apt-get install -y git
- uses: actions/checkout@v3
# Make changes to pull request here
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
```

630
docs/examples.md Normal file
View File

@ -0,0 +1,630 @@
# Examples
- [Use case: Create a pull request to update X on push](#use-case-create-a-pull-request-to-update-x-on-push)
- [Update project authors](#update-project-authors)
- [Keep a branch up-to-date with another](#keep-a-branch-up-to-date-with-another)
- [Use case: Create a pull request to update X on release](#use-case-create-a-pull-request-to-update-x-on-release)
- [Update changelog](#update-changelog)
- [Use case: Create a pull request to update X periodically](#use-case-create-a-pull-request-to-update-x-periodically)
- [Update NPM dependencies](#update-npm-dependencies)
- [Update Gradle dependencies](#update-gradle-dependencies)
- [Update Cargo dependencies](#update-cargo-dependencies)
- [Update SwaggerUI for GitHub Pages](#update-swaggerui-for-github-pages)
- [Keep a fork up-to-date with its upstream](#keep-a-fork-up-to-date-with-its-upstream)
- [Spider and download a website](#spider-and-download-a-website)
- [Use case: Create a pull request to update X by calling the GitHub API](#use-case-create-a-pull-request-to-update-x-by-calling-the-github-api)
- [Call the GitHub API from an external service](#call-the-github-api-from-an-external-service)
- [Call the GitHub API from another GitHub Actions workflow](#call-the-github-api-from-another-github-actions-workflow)
- [Use case: Create a pull request to modify/fix pull requests](#use-case-create-a-pull-request-to-modifyfix-pull-requests)
- [autopep8](#autopep8)
- [Misc workflow tips](#misc-workflow-tips)
- [Filtering push events](#filtering-push-events)
- [Dynamic configuration using variables](#dynamic-configuration-using-variables)
- [Setting the pull request body from a file](#setting-the-pull-request-body-from-a-file)
- [Using a markdown template](#using-a-markdown-template)
- [Debugging GitHub Actions](#debugging-github-actions)
## Use case: Create a pull request to update X on push
This pattern will work well for updating any kind of static content based on pushed changes. Care should be taken when using this pattern in repositories with a high frequency of commits.
### Update project authors
Raises a pull request to update a file called `AUTHORS` with the git user names and email addresses of contributors.
```yml
name: Update AUTHORS
on:
push:
branches:
- main
jobs:
updateAuthors:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Update AUTHORS
run: |
git log --format='%aN <%aE>%n%cN <%cE>' | sort -u > AUTHORS
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
commit-message: update authors
title: Update AUTHORS
body: Credit new contributors by updating AUTHORS
branch: update-authors
```
### Keep a branch up-to-date with another
This is a use case where a branch should be kept up to date with another by opening a pull request to update it. The pull request should then be updated with new changes until it is merged or closed.
In this example scenario, a branch called `production` should be updated via pull request to keep it in sync with `main`. Merging the pull request is effectively promoting those changes to production.
```yml
name: Create production promotion pull request
on:
push:
branches:
- main
jobs:
productionPromotion:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: production
- name: Reset promotion branch
run: |
git fetch origin main:main
git reset --hard main
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
branch: production-promotion
```
## Use case: Create a pull request to update X on release
This pattern will work well for updating any kind of static content based on the tagged commit of a release. Note that because `release` is one of the [events which checkout a commit](concepts-guidelines.md#events-which-checkout-a-commit) it is necessary to supply the `base` input to the action.
### Update changelog
Raises a pull request to update the `CHANGELOG.md` file based on the tagged commit of the release.
Note that [git-chglog](https://github.com/git-chglog/git-chglog/) requires some configuration files to exist in the repository before this workflow will work.
This workflow assumes the tagged release was made on a default branch called `main`.
```yml
name: Update Changelog
on:
release:
types: [published]
jobs:
updateChangelog:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Update Changelog
run: |
curl -o git-chglog -L https://github.com/git-chglog/git-chglog/releases/download/0.9.1/git-chglog_linux_amd64
chmod u+x git-chglog
./git-chglog -o CHANGELOG.md
rm git-chglog
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
commit-message: update changelog
title: Update Changelog
body: Update changelog to reflect release changes
branch: update-changelog
base: main
```
## Use case: Create a pull request to update X periodically
This pattern will work well for updating any kind of static content from an external source. The workflow executes on a schedule and raises a pull request when there are changes.
### Update NPM dependencies
This workflow will create a pull request for npm dependencies.
It works best in combination with a build workflow triggered on `push` and `pull_request`.
A [Personal Access Token (PAT)](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) can be used in order for the creation of the pull request to trigger further workflows. See the [documentation here](concepts-guidelines.md#triggering-further-workflow-runs) for further details.
```yml
name: Update Dependencies
on:
schedule:
- cron: '0 10 * * 1'
jobs:
update-dep:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '16.x'
- name: Update dependencies
run: |
npx -p npm-check-updates ncu -u
npm install
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.PAT }}
commit-message: Update dependencies
title: Update dependencies
body: |
- Dependency updates
Auto-generated by [create-pull-request][1]
[1]: https://github.com/peter-evans/create-pull-request
branch: update-dependencies
```
The above workflow works best in combination with a build workflow triggered on `push` and `pull_request`.
```yml
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16.x
- run: npm ci
- run: npm run test
- run: npm run build
```
### Update Gradle dependencies
The following workflow will create a pull request for Gradle dependencies.
It requires first configuring your project to use Gradle lockfiles.
See [here](https://github.com/peter-evans/gradle-auto-dependency-updates) for how to configure your project and use the following workflow.
```yml
name: Update Dependencies
on:
schedule:
- cron: '0 1 * * 1'
jobs:
update-dep:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v2
with:
distribution: 'temurin'
java-version: 1.8
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Perform dependency resolution and write new lockfiles
run: ./gradlew dependencies --write-locks
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.PAT }}
commit-message: Update dependencies
title: Update dependencies
body: |
- Dependency updates
Auto-generated by [create-pull-request][1]
[1]: https://github.com/peter-evans/create-pull-request
branch: update-dependencies
```
### Update Cargo dependencies
The following workflow will create a pull request for Cargo dependencies.
It optionally uses [`cargo-edit`](https://github.com/killercup/cargo-edit) to update `Cargo.toml` and keep it in sync with `Cargo.lock`.
```yml
name: Update Dependencies
on:
schedule:
- cron: '0 1 * * 1'
jobs:
update-dep:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Update dependencies
run: |
cargo install cargo-edit
cargo update
cargo upgrade --to-lockfile
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.PAT }}
commit-message: Update dependencies
title: Update dependencies
body: |
- Dependency updates
Auto-generated by [create-pull-request][1]
[1]: https://github.com/peter-evans/create-pull-request
branch: update-dependencies
```
### Update SwaggerUI for GitHub Pages
When using [GitHub Pages to host Swagger documentation](https://github.com/peter-evans/swagger-github-pages), this workflow updates the repository with the latest distribution of [SwaggerUI](https://github.com/swagger-api/swagger-ui).
You must create a file called `swagger-ui.version` at the root of your repository before running.
```yml
name: Update Swagger UI
on:
schedule:
- cron: '0 10 * * *'
jobs:
updateSwagger:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Get Latest Swagger UI Release
id: swagger-ui
run: |
echo ::set-output name=release_tag::$(curl -sL https://api.github.com/repos/swagger-api/swagger-ui/releases/latest | jq -r ".tag_name")
echo ::set-output name=current_tag::$(<swagger-ui.version)
- name: Update Swagger UI
if: steps.swagger-ui.outputs.current_tag != steps.swagger-ui.outputs.release_tag
env:
RELEASE_TAG: ${{ steps.swagger-ui.outputs.release_tag }}
SWAGGER_YAML: "swagger.yaml"
run: |
# Delete the dist directory and index.html
rm -fr dist index.html
# Download the release
curl -sL -o $RELEASE_TAG https://api.github.com/repos/swagger-api/swagger-ui/tarball/$RELEASE_TAG
# Extract the dist directory
tar -xzf $RELEASE_TAG --strip-components=1 $(tar -tzf $RELEASE_TAG | head -1 | cut -f1 -d"/")/dist
rm $RELEASE_TAG
# Move index.html to the root
mv dist/index.html .
# Fix references in index.html
sed -i "s|https://petstore.swagger.io/v2/swagger.json|$SWAGGER_YAML|g" index.html
sed -i "s|href=\"./|href=\"dist/|g" index.html
sed -i "s|src=\"./|src=\"dist/|g" index.html
# Update current release
echo ${{ steps.swagger-ui.outputs.release_tag }} > swagger-ui.version
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
commit-message: Update swagger-ui to ${{ steps.swagger-ui.outputs.release_tag }}
title: Update SwaggerUI to ${{ steps.swagger-ui.outputs.release_tag }}
body: |
Updates [swagger-ui][1] to ${{ steps.swagger-ui.outputs.release_tag }}
Auto-generated by [create-pull-request][2]
[1]: https://github.com/swagger-api/swagger-ui
[2]: https://github.com/peter-evans/create-pull-request
labels: dependencies, automated pr
branch: swagger-ui-updates
```
### Keep a fork up-to-date with its upstream
This example is designed to be run in a seperate repository from the fork repository itself.
The aim of this is to prevent committing anything to the fork's default branch would cause it to differ from the upstream.
In the following example workflow, `owner/repo` is the upstream repository and `fork-owner/repo` is the fork. It assumes the default branch of the upstream repository is called `main`.
The [Personal Access Token (PAT)](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) should have `repo` scope. Additionally, if the upstream makes changes to the `.github/workflows` directory, the action will be unable to push the changes to a branch and throw the error "_(refusing to allow a GitHub App to create or update workflow `.github/workflows/xxx.yml` without `workflows` permission)_". To allow these changes to be pushed to the fork, add the `workflow` scope to the PAT. Of course, allowing this comes with the risk that the workflow changes from the upstream could run and do something unexpected. Disabling GitHub Actions in the fork is highly recommended to prevent this.
When you merge the pull request make sure to choose the [`Rebase and merge`](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-request-merges#rebase-and-merge-your-pull-request-commits) option. This will make the fork's commits match the commits on the upstream.
```yml
name: Update fork
on:
schedule:
- cron: '0 0 * * 0'
jobs:
updateFork:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
repository: fork-owner/repo
- name: Reset the default branch with upstream changes
run: |
git remote add upstream https://github.com/owner/repo.git
git fetch upstream main:upstream-main
git reset --hard upstream-main
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.PAT }}
branch: upstream-changes
```
### Spider and download a website
This workflow spiders a website and downloads the content. Any changes to the website will be raised in a pull request.
```yml
name: Download Website
on:
schedule:
- cron: '0 10 * * *'
jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Download website
run: |
wget \
--recursive \
--level=2 \
--wait=1 \
--no-clobber \
--page-requisites \
--html-extension \
--convert-links \
--domains quotes.toscrape.com \
http://quotes.toscrape.com/
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
commit-message: update local website copy
title: Automated Updates to Local Website Copy
body: This is an auto-generated PR with website updates.
branch: website-updates
```
## Use case: Create a pull request to update X by calling the GitHub API
You can use the GitHub API to trigger a webhook event called [`repository_dispatch`](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#repository_dispatch) when you want to trigger a workflow for any activity that happens outside of GitHub.
This pattern will work well for updating any kind of static content from an external source.
You can modify any of the examples in the previous section to work in this fashion.
Set the workflow to execute `on: repository_dispatch`.
```yml
on:
repository_dispatch:
types: [create-pull-request]
```
### Call the GitHub API from an external service
An `on: repository_dispatch` workflow can be triggered by a call to the GitHub API as follows.
- `[username]` is a GitHub username
- `[token]` is a `repo` scoped [Personal Access Token](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token)
- `[repository]` is the name of the repository the workflow resides in.
```
curl -XPOST -u "[username]:[token]" \
-H "Accept: application/vnd.github.everest-preview+json" \
-H "Content-Type: application/json" \
https://api.github.com/repos/[username]/[repository]/dispatches \
--data '{"event_type": "create-pull-request"}'
```
### Call the GitHub API from another GitHub Actions workflow
An `on: repository_dispatch` workflow can be triggered from another workflow with [repository-dispatch](https://github.com/peter-evans/repository-dispatch) action.
```yml
- name: Repository Dispatch
uses: peter-evans/repository-dispatch@v2
with:
token: ${{ secrets.REPO_ACCESS_TOKEN }}
repository: username/my-repo
event-type: create-pull-request
client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}"}'
```
## Use case: Create a pull request to modify/fix pull requests
**Note**: While the following approach does work, my strong recommendation would be to use a slash command style "ChatOps" solution for operations on pull requests. See [slash-command-dispatch](https://github.com/peter-evans/slash-command-dispatch) for such a solution.
This is a pattern that lends itself to automated code linting and fixing. A pull request can be created to fix or modify something during an `on: pull_request` workflow. The pull request containing the fix will be raised with the original pull request as the base. This can be then be merged to update the original pull request and pass any required tests.
Note that due to [token restrictions on public repository forks](https://docs.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token#permissions-for-the-github_token), workflows for this use case do not work for pull requests raised from forks.
Private repositories can be configured to [enable workflows](https://docs.github.com/en/github/administering-a-repository/disabling-or-limiting-github-actions-for-a-repository#enabling-workflows-for-private-repository-forks) from forks to run without restriction.
### autopep8
The following is an example workflow for a use case where [autopep8 action](https://github.com/peter-evans/autopep8) runs as both a check on pull requests and raises a further pull request to apply code fixes.
How it works:
1. When a pull request is raised the workflow executes as a check
2. If autopep8 makes any fixes a pull request will be raised for those fixes to be merged into the current pull request branch. The workflow then deliberately causes the check to fail.
3. When the pull request containing the fixes is merged the workflow runs again. This time autopep8 makes no changes and the check passes.
4. The original pull request can now be merged.
```yml
name: autopep8
on: pull_request
jobs:
autopep8:
# Check if the PR is not raised by this workflow and is not from a fork
if: startsWith(github.head_ref, 'autopep8-patches') == false && github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
- name: autopep8
id: autopep8
uses: peter-evans/autopep8@v1
with:
args: --exit-code --recursive --in-place --aggressive --aggressive .
- name: Set autopep8 branch name
id: vars
run: echo ::set-output name=branch-name::"autopep8-patches/${{ github.head_ref }}"
- name: Create Pull Request
if: steps.autopep8.outputs.exit-code == 2
uses: peter-evans/create-pull-request@v4
with:
commit-message: autopep8 action fixes
title: Fixes by autopep8 action
body: This is an auto-generated PR with fixes by autopep8.
labels: autopep8, automated pr
branch: ${{ steps.vars.outputs.branch-name }}
- name: Fail if autopep8 made changes
if: steps.autopep8.outputs.exit-code == 2
run: exit 1
```
## Misc workflow tips
### Filtering push events
For workflows using `on: push` you may want to ignore push events for tags and only execute for branches. Specifying `branches` causes only events on branches to trigger the workflow. The `'**'` wildcard will match any branch name.
```yml
on:
push:
branches:
- '**'
```
If you have a workflow that contains jobs to handle push events on branches as well as tags, you can make sure that the job where you use `create-pull-request` action only executes when `github.ref` is a branch by using an `if` condition as follows.
```yml
on: push
jobs:
createPullRequest:
if: startsWith(github.ref, 'refs/heads/')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
...
someOtherJob:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
...
```
### Dynamic configuration using variables
The following examples show how configuration for the action can be dynamically defined in a previous workflow step.
The recommended method is to use [`set-output`](https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-output-parameter). Note that the step where output variables are defined must have an id.
```yml
- name: Set output variables
id: vars
run: |
echo ::set-output name=pr_title::"[Test] Add report file $(date +%d-%m-%Y)"
echo ::set-output name=pr_body::"This PR was auto-generated on $(date +%d-%m-%Y) \
by [create-pull-request](https://github.com/peter-evans/create-pull-request)."
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
title: ${{ steps.vars.outputs.pr_title }}
body: ${{ steps.vars.outputs.pr_body }}
```
### Setting the pull request body from a file
This example shows how file content can be read into a variable and passed to the action.
The content must be [escaped to preserve newlines](https://github.community/t/set-output-truncates-multiline-strings/16852/3).
```yml
- id: get-pr-body
run: |
body=$(cat pr-body.txt)
body="${body//'%'/'%25'}"
body="${body//$'\n'/'%0A'}"
body="${body//$'\r'/'%0D'}"
echo ::set-output name=body::$body
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
body: ${{ steps.get-pr-body.outputs.body }}
```
### Using a markdown template
In this example, a markdown template file is added to the repository at `.github/pull-request-template.md` with the following content.
```
This is a test pull request template
Render template variables such as {{ .foo }} and {{ .bar }}.
```
The template is rendered using the [render-template](https://github.com/chuhlomin/render-template) action and the result is used to create the pull request.
```yml
- name: Render template
id: template
uses: chuhlomin/render-template@v1.4
with:
template: .github/pull-request-template.md
vars: |
foo: this
bar: that
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
body: ${{ steps.template.outputs.result }}
```
### Debugging GitHub Actions
#### Runner Diagnostic Logging
[Runner diagnostic logging](https://docs.github.com/en/actions/configuring-and-managing-workflows/managing-a-workflow-run#enabling-runner-diagnostic-logging) provides additional log files that contain information about how a runner is executing an action.
To enable runner diagnostic logging, set the secret `ACTIONS_RUNNER_DEBUG` to `true` in the repository that contains the workflow.
#### Step Debug Logging
[Step debug logging](https://docs.github.com/en/actions/configuring-and-managing-workflows/managing-a-workflow-run#enabling-step-debug-logging) increases the verbosity of a job's logs during and after a job's execution.
To enable step debug logging set the secret `ACTIONS_STEP_DEBUG` to `true` in the repository that contains the workflow.
#### Output Various Contexts
```yml
steps:
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- name: Dump job context
env:
JOB_CONTEXT: ${{ toJson(job) }}
run: echo "$JOB_CONTEXT"
- name: Dump steps context
env:
STEPS_CONTEXT: ${{ toJson(steps) }}
run: echo "$STEPS_CONTEXT"
- name: Dump runner context
env:
RUNNER_CONTEXT: ${{ toJson(runner) }}
run: echo "$RUNNER_CONTEXT"
- name: Dump strategy context
env:
STRATEGY_CONTEXT: ${{ toJson(strategy) }}
run: echo "$STRATEGY_CONTEXT"
- name: Dump matrix context
env:
MATRIX_CONTEXT: ${{ toJson(matrix) }}
run: echo "$MATRIX_CONTEXT"
```

87
docs/updating.md Normal file
View File

@ -0,0 +1,87 @@
## Updating from `v3` to `v4`
### Breaking changes
- The `add-paths` input no longer accepts `-A` as a valid value. When committing all new and modified files the `add-paths` input should be omitted.
- If using self-hosted runners or GitHub Enterprise Server, there are minimum requirements for `v4` to run. See "What's new" below for details.
### What's new
- Updated runtime to Node.js 16
- The action now requires a minimum version of v2.285.0 for the [Actions Runner](https://github.com/actions/runner/releases/tag/v2.285.0).
- If using GitHub Enterprise Server, the action requires [GHES 3.4](https://docs.github.com/en/enterprise-server@3.4/admin/release-notes) or later.
## Updating from `v2` to `v3`
### Breaking changes
- The `author` input now defaults to the user who triggered the workflow run. This default is set via [action.yml](../action.yml) as `${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>`, where `github.actor` is the GitHub user account associated with the run. For example, `peter-evans <peter-evans@users.noreply.github.com>`.
To continue to use the `v2` default, set the `author` input as follows.
```yaml
- uses: peter-evans/create-pull-request@v3
with:
author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
```
- The `author` and `committer` inputs are no longer cross-used if only one is supplied. Additionally, when neither input is set, the `author` and `committer` are no longer determined from an existing identity set in git config. In both cases, the inputs will fall back to their default set in [action.yml](../action.yml).
- Deprecated inputs `project` and `project-column` have been removed in favour of an additional action step. See [Create a project card](https://github.com/peter-evans/create-pull-request#create-a-project-card) for details.
- Deprecated output `pr_number` has been removed in favour of `pull-request-number`.
- Input `request-to-parent` has been removed in favour of `push-to-fork`. This greatly simplifies pushing the pull request branch to a fork of the parent repository. See [Push pull request branches to a fork](concepts-guidelines.md#push-pull-request-branches-to-a-fork) for details.
e.g.
```yaml
- uses: actions/checkout@v2
# Make changes to pull request here
- uses: peter-evans/create-pull-request@v3
with:
token: ${{ secrets.MACHINE_USER_PAT }}
push-to-fork: machine-user/fork-of-repository
```
### What's new
- The action has been converted to Typescript giving it a significant performance improvement.
- If you run this action in a container, or on [self-hosted runners](https://docs.github.com/en/actions/hosting-your-own-runners), `python` and `pip` are no longer required dependencies. See [Running in a container or on self-hosted runners](concepts-guidelines.md#running-in-a-container-or-on-self-hosted-runners) for details.
- Inputs `labels`, `assignees`, `reviewers` and `team-reviewers` can now be newline separated, or comma separated.
e.g.
```yml
labels: |
chore
dependencies
automated
```
## Updating from `v1` to `v2`
### Breaking changes
- `v2` now expects repositories to be checked out with `actions/checkout@v2`
To use `actions/checkout@v1` the following step to checkout the branch is necessary.
```yml
- uses: actions/checkout@v1
- name: Checkout branch
run: git checkout "${GITHUB_REF:11}"
```
- The two branch naming strategies have been swapped. Fixed-branch naming strategy is now the default. i.e. `branch-suffix: none` is now the default and should be removed from configuration if set.
- `author-name`, `author-email`, `committer-name`, `committer-email` have been removed in favour of `author` and `committer`.
They can both be set in the format `Display Name <email@address.com>`
If neither `author` or `committer` are set the action will default to making commits as the GitHub Actions bot user.
### What's new
- Unpushed commits made during the workflow before the action runs will now be considered as changes to be raised in the pull request. See [Create your own commits](https://github.com/peter-evans/create-pull-request#create-your-own-commits) for details.
- New commits made to the pull request base will now be taken into account when pull requests are updated.
- If an updated pull request no longer differs from its base it will automatically be closed and the pull request branch deleted.

11
jest.config.js Normal file
View File

@ -0,0 +1,11 @@
module.exports = {
clearMocks: true,
moduleFileExtensions: ['js', 'ts'],
testEnvironment: 'node',
testMatch: ['**/*.test.ts'],
testRunner: 'jest-circus/runner',
transform: {
'^.+\\.ts$': 'ts-jest'
},
verbose: true
}

13313
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

58
package.json Normal file
View File

@ -0,0 +1,58 @@
{
"name": "create-pull-request",
"version": "4.0.0",
"private": true,
"description": "Creates a pull request for changes to your repository in the actions workspace",
"main": "lib/main.js",
"scripts": {
"build": "tsc && ncc build",
"format": "prettier --write '**/*.ts'",
"format-check": "prettier --check '**/*.ts'",
"lint": "eslint src/**/*.ts",
"test:unit": "jest unit",
"test:int": "__test__/integration-tests.sh",
"test": "npm run test:unit && npm run test:int"
},
"repository": {
"type": "git",
"url": "git+https://github.com/peter-evans/create-pull-request.git"
},
"keywords": [
"actions",
"pull",
"request"
],
"author": "Peter Evans",
"license": "MIT",
"bugs": {
"url": "https://github.com/peter-evans/create-pull-request/issues"
},
"homepage": "https://github.com/peter-evans/create-pull-request",
"dependencies": {
"@actions/core": "^1.6.0",
"@actions/exec": "^1.1.0",
"@octokit/core": "^3.5.1",
"@octokit/plugin-paginate-rest": "^2.17.0",
"@octokit/plugin-rest-endpoint-methods": "^5.13.0",
"https-proxy-agent": "^5.0.0",
"uuid": "^8.3.2"
},
"devDependencies": {
"@types/jest": "^27.5.0",
"@types/node": "^16.11.11",
"@typescript-eslint/parser": "^5.5.0",
"@vercel/ncc": "^0.32.0",
"eslint": "^8.3.0",
"eslint-import-resolver-typescript": "^2.5.0",
"eslint-plugin-github": "^4.3.5",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-jest": "^26.1.5",
"jest": "^28.1.0",
"jest-circus": "^28.1.0",
"jest-environment-jsdom": "^28.1.0",
"js-yaml": "^4.1.0",
"prettier": "^2.5.0",
"ts-jest": "^28.0.2",
"typescript": "^4.5.2"
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 201 KiB

View File

@ -1,5 +0,0 @@
{
"extends": [
"config:base"
]
}

View File

@ -1,2 +0,0 @@
GitPython==3.0.3
PyGithub==1.43.8

View File

@ -0,0 +1,262 @@
import * as core from '@actions/core'
import {GitCommandManager} from './git-command-manager'
import {v4 as uuidv4} from 'uuid'
const CHERRYPICK_EMPTY =
'The previous cherry-pick is now empty, possibly due to conflict resolution.'
export enum WorkingBaseType {
Branch = 'branch',
Commit = 'commit'
}
export async function getWorkingBaseAndType(
git: GitCommandManager
): Promise<[string, WorkingBaseType]> {
const symbolicRefResult = await git.exec(
['symbolic-ref', 'HEAD', '--short'],
true
)
if (symbolicRefResult.exitCode == 0) {
// A ref is checked out
return [symbolicRefResult.stdout.trim(), WorkingBaseType.Branch]
} else {
// A commit is checked out (detached HEAD)
const headSha = await git.revParse('HEAD')
return [headSha, WorkingBaseType.Commit]
}
}
export async function tryFetch(
git: GitCommandManager,
remote: string,
branch: string
): Promise<boolean> {
try {
await git.fetch([`${branch}:refs/remotes/${remote}/${branch}`], remote, [
'--force'
])
return true
} catch {
return false
}
}
// Return true if branch2 is ahead of branch1
async function isAhead(
git: GitCommandManager,
branch1: string,
branch2: string
): Promise<boolean> {
const result = await git.revList(
[`${branch1}...${branch2}`],
['--right-only', '--count']
)
return Number(result) > 0
}
// Return true if branch2 is behind branch1
async function isBehind(
git: GitCommandManager,
branch1: string,
branch2: string
): Promise<boolean> {
const result = await git.revList(
[`${branch1}...${branch2}`],
['--left-only', '--count']
)
return Number(result) > 0
}
// Return true if branch2 is even with branch1
async function isEven(
git: GitCommandManager,
branch1: string,
branch2: string
): Promise<boolean> {
return (
!(await isAhead(git, branch1, branch2)) &&
!(await isBehind(git, branch1, branch2))
)
}
function splitLines(multilineString: string): string[] {
return multilineString
.split('\n')
.map(s => s.trim())
.filter(x => x !== '')
}
export async function createOrUpdateBranch(
git: GitCommandManager,
commitMessage: string,
base: string,
branch: string,
branchRemoteName: string,
signoff: boolean,
addPaths: string[]
): Promise<CreateOrUpdateBranchResult> {
// Get the working base.
// When a ref, it may or may not be the actual base.
// When a commit, we must rebase onto the actual base.
const [workingBase, workingBaseType] = await getWorkingBaseAndType(git)
core.info(`Working base is ${workingBaseType} '${workingBase}'`)
if (workingBaseType == WorkingBaseType.Commit && !base) {
throw new Error(`When in 'detached HEAD' state, 'base' must be supplied.`)
}
// If the base is not specified it is assumed to be the working base.
base = base ? base : workingBase
const baseRemote = 'origin'
// Set the default return values
const result: CreateOrUpdateBranchResult = {
action: 'none',
base: base,
hasDiffWithBase: false,
headSha: ''
}
// Save the working base changes to a temporary branch
const tempBranch = uuidv4()
await git.checkout(tempBranch, 'HEAD')
// Commit any uncommitted changes
if (await git.isDirty(true, addPaths)) {
core.info('Uncommitted changes found. Adding a commit.')
const aopts = ['add']
if (addPaths.length > 0) {
aopts.push(...['--', ...addPaths])
} else {
aopts.push('-A')
}
await git.exec(aopts, true)
const popts = ['-m', commitMessage]
if (signoff) {
popts.push('--signoff')
}
await git.commit(popts)
}
// Remove uncommitted tracked and untracked changes
await git.exec(['reset', '--hard'])
await git.exec(['clean', '-f', '-d'])
// Perform fetch and reset the working base
// Commits made during the workflow will be removed
if (workingBaseType == WorkingBaseType.Branch) {
core.info(`Resetting working base branch '${workingBase}'`)
if (branchRemoteName == 'fork') {
// If pushing to a fork we must fetch with 'unshallow' to avoid the following error on git push
// ! [remote rejected] HEAD -> tests/push-branch-to-fork (shallow update not allowed)
await git.fetch([`${workingBase}:${workingBase}`], baseRemote, [
'--force'
])
} else {
// If the remote is 'origin' we can git reset
await git.checkout(workingBase)
await git.exec(['reset', '--hard', `${baseRemote}/${workingBase}`])
}
}
// If the working base is not the base, rebase the temp branch commits
// This will also be true if the working base type is a commit
if (workingBase != base) {
core.info(
`Rebasing commits made to ${workingBaseType} '${workingBase}' on to base branch '${base}'`
)
// Checkout the actual base
await git.fetch([`${base}:${base}`], baseRemote, ['--force'])
await git.checkout(base)
// Cherrypick commits from the temporary branch starting from the working base
const commits = await git.revList(
[`${workingBase}..${tempBranch}`, '.'],
['--reverse']
)
for (const commit of splitLines(commits)) {
const result = await git.cherryPick(
['--strategy=recursive', '--strategy-option=theirs', commit],
true
)
if (result.exitCode != 0 && !result.stderr.includes(CHERRYPICK_EMPTY)) {
throw new Error(`Unexpected error: ${result.stderr}`)
}
}
// Reset the temp branch to the working index
await git.checkout(tempBranch, 'HEAD')
// Reset the base
await git.fetch([`${base}:${base}`], baseRemote, ['--force'])
}
// Try to fetch the pull request branch
if (!(await tryFetch(git, branchRemoteName, branch))) {
// The pull request branch does not exist
core.info(`Pull request branch '${branch}' does not exist yet.`)
// Create the pull request branch
await git.checkout(branch, tempBranch)
// Check if the pull request branch is ahead of the base
result.hasDiffWithBase = await isAhead(git, base, branch)
if (result.hasDiffWithBase) {
result.action = 'created'
core.info(`Created branch '${branch}'`)
} else {
core.info(
`Branch '${branch}' is not ahead of base '${base}' and will not be created`
)
}
} else {
// The pull request branch exists
core.info(
`Pull request branch '${branch}' already exists as remote branch '${branchRemoteName}/${branch}'`
)
// Checkout the pull request branch
await git.checkout(branch)
// Reset the branch if one of the following conditions is true.
// - If the branch differs from the recreated temp branch.
// - If the recreated temp branch is not ahead of the base. This means there will be
// no pull request diff after the branch is reset. This will reset any undeleted
// branches after merging. In particular, it catches a case where the branch was
// squash merged but not deleted. We need to reset to make sure it doesn't appear
// to have a diff with the base due to different commits for the same changes.
// For changes on base this reset is equivalent to a rebase of the pull request branch.
if (
(await git.hasDiff([`${branch}..${tempBranch}`])) ||
!(await isAhead(git, base, tempBranch))
) {
core.info(`Resetting '${branch}'`)
// Alternatively, git switch -C branch tempBranch
await git.checkout(branch, tempBranch)
}
// Check if the pull request branch has been updated
// If the branch was reset or updated it will be ahead
// It may be behind if a reset now results in no diff with the base
if (!(await isEven(git, `${branchRemoteName}/${branch}`, branch))) {
result.action = 'updated'
core.info(`Updated branch '${branch}'`)
} else {
result.action = 'not-updated'
core.info(
`Branch '${branch}' is even with its remote and will not be updated`
)
}
// Check if the pull request branch is ahead of the base
result.hasDiffWithBase = await isAhead(git, base, branch)
}
// Get the pull request branch SHA
result.headSha = await git.revParse('HEAD')
// Delete the temporary branch
await git.exec(['branch', '--delete', '--force', tempBranch])
return result
}
interface CreateOrUpdateBranchResult {
action: string
base: string
hasDiffWithBase: boolean
headSha: string
}

252
src/create-pull-request.ts Normal file
View File

@ -0,0 +1,252 @@
import * as core from '@actions/core'
import {
createOrUpdateBranch,
getWorkingBaseAndType,
WorkingBaseType
} from './create-or-update-branch'
import {GitHubHelper} from './github-helper'
import {GitCommandManager} from './git-command-manager'
import {GitAuthHelper} from './git-auth-helper'
import * as utils from './utils'
export interface Inputs {
token: string
path: string
addPaths: string[]
commitMessage: string
committer: string
author: string
signoff: boolean
branch: string
deleteBranch: boolean
branchSuffix: string
base: string
pushToFork: string
title: string
body: string
labels: string[]
assignees: string[]
reviewers: string[]
teamReviewers: string[]
milestone: number
draft: boolean
}
export async function createPullRequest(inputs: Inputs): Promise<void> {
let gitAuthHelper
try {
// Get the repository path
const repoPath = utils.getRepoPath(inputs.path)
// Create a git command manager
const git = await GitCommandManager.create(repoPath)
// Save and unset the extraheader auth config if it exists
core.startGroup('Save persisted git credentials')
gitAuthHelper = new GitAuthHelper(git)
await gitAuthHelper.savePersistedAuth()
core.endGroup()
// Init the GitHub client
const githubHelper = new GitHubHelper(inputs.token)
core.startGroup('Determining the base and head repositories')
// Determine the base repository from git config
const remoteUrl = await git.tryGetRemoteUrl()
const baseRemote = utils.getRemoteDetail(remoteUrl)
// Determine the head repository; the target for the pull request branch
const branchRemoteName = inputs.pushToFork ? 'fork' : 'origin'
const branchRepository = inputs.pushToFork
? inputs.pushToFork
: baseRemote.repository
if (inputs.pushToFork) {
// Check if the supplied fork is really a fork of the base
const parentRepository = await githubHelper.getRepositoryParent(
branchRepository
)
if (parentRepository != baseRemote.repository) {
throw new Error(
`Repository '${branchRepository}' is not a fork of '${baseRemote.repository}'. Unable to continue.`
)
}
// Add a remote for the fork
const remoteUrl = utils.getRemoteUrl(
baseRemote.protocol,
branchRepository
)
await git.exec(['remote', 'add', 'fork', remoteUrl])
}
core.endGroup()
core.info(
`Pull request branch target repository set to ${branchRepository}`
)
// Configure auth
if (baseRemote.protocol == 'HTTPS') {
core.startGroup('Configuring credential for HTTPS authentication')
await gitAuthHelper.configureToken(inputs.token)
core.endGroup()
}
core.startGroup('Checking the base repository state')
const [workingBase, workingBaseType] = await getWorkingBaseAndType(git)
core.info(`Working base is ${workingBaseType} '${workingBase}'`)
// When in detached HEAD state (checked out on a commit), we need to
// know the 'base' branch in order to rebase changes.
if (workingBaseType == WorkingBaseType.Commit && !inputs.base) {
throw new Error(
`When the repository is checked out on a commit instead of a branch, the 'base' input must be supplied.`
)
}
// If the base is not specified it is assumed to be the working base.
const base = inputs.base ? inputs.base : workingBase
// Throw an error if the base and branch are not different branches
// of the 'origin' remote. An identically named branch in the `fork`
// remote is perfectly fine.
if (branchRemoteName == 'origin' && base == inputs.branch) {
throw new Error(
`The 'base' and 'branch' for a pull request must be different branches. Unable to continue.`
)
}
// For self-hosted runners the repository state persists between runs.
// This command prunes the stale remote ref when the pull request branch was
// deleted after being merged or closed. Without this the push using
// '--force-with-lease' fails due to "stale info."
// https://github.com/peter-evans/create-pull-request/issues/633
await git.exec(['remote', 'prune', branchRemoteName])
core.endGroup()
// Apply the branch suffix if set
if (inputs.branchSuffix) {
switch (inputs.branchSuffix) {
case 'short-commit-hash':
// Suffix with the short SHA1 hash
inputs.branch = `${inputs.branch}-${await git.revParse('HEAD', [
'--short'
])}`
break
case 'timestamp':
// Suffix with the current timestamp
inputs.branch = `${inputs.branch}-${utils.secondsSinceEpoch()}`
break
case 'random':
// Suffix with a 7 character random string
inputs.branch = `${inputs.branch}-${utils.randomString()}`
break
default:
throw new Error(
`Branch suffix '${inputs.branchSuffix}' is not a valid value. Unable to continue.`
)
}
}
// Output head branch
core.info(
`Pull request branch to create or update set to '${inputs.branch}'`
)
// Configure the committer and author
core.startGroup('Configuring the committer and author')
const parsedAuthor = utils.parseDisplayNameEmail(inputs.author)
const parsedCommitter = utils.parseDisplayNameEmail(inputs.committer)
git.setIdentityGitOptions([
'-c',
`author.name=${parsedAuthor.name}`,
'-c',
`author.email=${parsedAuthor.email}`,
'-c',
`committer.name=${parsedCommitter.name}`,
'-c',
`committer.email=${parsedCommitter.email}`
])
core.info(
`Configured git committer as '${parsedCommitter.name} <${parsedCommitter.email}>'`
)
core.info(
`Configured git author as '${parsedAuthor.name} <${parsedAuthor.email}>'`
)
core.endGroup()
// Create or update the pull request branch
core.startGroup('Create or update the pull request branch')
const result = await createOrUpdateBranch(
git,
inputs.commitMessage,
inputs.base,
inputs.branch,
branchRemoteName,
inputs.signoff,
inputs.addPaths
)
core.endGroup()
if (['created', 'updated'].includes(result.action)) {
// The branch was created or updated
core.startGroup(
`Pushing pull request branch to '${branchRemoteName}/${inputs.branch}'`
)
await git.push([
'--force-with-lease',
branchRemoteName,
`HEAD:refs/heads/${inputs.branch}`
])
core.endGroup()
}
// Set the base. It would have been '' if not specified as an input
inputs.base = result.base
if (result.hasDiffWithBase) {
// Create or update the pull request
core.startGroup('Create or update the pull request')
const pull = await githubHelper.createOrUpdatePullRequest(
inputs,
baseRemote.repository,
branchRepository
)
core.endGroup()
// Set outputs
core.startGroup('Setting outputs')
core.setOutput('pull-request-number', pull.number)
core.setOutput('pull-request-url', pull.html_url)
if (pull.created) {
core.setOutput('pull-request-operation', 'created')
} else if (result.action == 'updated') {
core.setOutput('pull-request-operation', 'updated')
}
core.setOutput('pull-request-head-sha', result.headSha)
// Deprecated
core.exportVariable('PULL_REQUEST_NUMBER', pull.number)
core.endGroup()
} else {
// There is no longer a diff with the base
// Check we are in a state where a branch exists
if (['updated', 'not-updated'].includes(result.action)) {
core.info(
`Branch '${inputs.branch}' no longer differs from base branch '${inputs.base}'`
)
if (inputs.deleteBranch) {
core.info(`Deleting branch '${inputs.branch}'`)
await git.push([
'--delete',
'--force',
branchRemoteName,
`refs/heads/${inputs.branch}`
])
// Set outputs
core.startGroup('Setting outputs')
core.setOutput('pull-request-operation', 'closed')
core.endGroup()
}
}
}
} catch (error: any) {
core.setFailed(error.message)
} finally {
// Remove auth and restore persisted auth config if it existed
core.startGroup('Restore persisted git credentials')
await gitAuthHelper.removeAuth()
await gitAuthHelper.restorePersistedAuth()
core.endGroup()
}
}

126
src/git-auth-helper.ts Normal file
View File

@ -0,0 +1,126 @@
import * as core from '@actions/core'
import * as fs from 'fs'
import {GitCommandManager} from './git-command-manager'
import * as path from 'path'
import {URL} from 'url'
export class GitAuthHelper {
private git: GitCommandManager
private gitConfigPath: string
private extraheaderConfigKey: string
private extraheaderConfigPlaceholderValue = 'AUTHORIZATION: basic ***'
private extraheaderConfigValueRegex = '^AUTHORIZATION:'
private persistedExtraheaderConfigValue = ''
constructor(git: GitCommandManager) {
this.git = git
this.gitConfigPath = path.join(
this.git.getWorkingDirectory(),
'.git',
'config'
)
const serverUrl = this.getServerUrl()
this.extraheaderConfigKey = `http.${serverUrl.origin}/.extraheader`
}
async savePersistedAuth(): Promise<void> {
// Save and unset persisted extraheader credential in git config if it exists
this.persistedExtraheaderConfigValue = await this.getAndUnset()
}
async restorePersistedAuth(): Promise<void> {
if (this.persistedExtraheaderConfigValue) {
try {
await this.setExtraheaderConfig(this.persistedExtraheaderConfigValue)
core.info('Persisted git credentials restored')
} catch (e: any) {
core.warning(e)
}
}
}
async configureToken(token: string): Promise<void> {
// Encode and configure the basic credential for HTTPS access
const basicCredential = Buffer.from(
`x-access-token:${token}`,
'utf8'
).toString('base64')
core.setSecret(basicCredential)
const extraheaderConfigValue = `AUTHORIZATION: basic ${basicCredential}`
await this.setExtraheaderConfig(extraheaderConfigValue)
}
async removeAuth(): Promise<void> {
await this.getAndUnset()
}
private async setExtraheaderConfig(
extraheaderConfigValue: string
): Promise<void> {
// Configure a placeholder value. This approach avoids the credential being captured
// by process creation audit events, which are commonly logged. For more information,
// refer to https://docs.microsoft.com/en-us/windows-server/identity/ad-ds/manage/component-updates/command-line-process-auditing
// See https://github.com/actions/checkout/blob/main/src/git-auth-helper.ts#L267-L274
await this.git.config(
this.extraheaderConfigKey,
this.extraheaderConfigPlaceholderValue
)
// Replace the placeholder
await this.gitConfigStringReplace(
this.extraheaderConfigPlaceholderValue,
extraheaderConfigValue
)
}
private async getAndUnset(): Promise<string> {
let configValue = ''
// Save and unset persisted extraheader credential in git config if it exists
if (
await this.git.configExists(
this.extraheaderConfigKey,
this.extraheaderConfigValueRegex
)
) {
configValue = await this.git.getConfigValue(
this.extraheaderConfigKey,
this.extraheaderConfigValueRegex
)
if (
await this.git.tryConfigUnset(
this.extraheaderConfigKey,
this.extraheaderConfigValueRegex
)
) {
core.info(`Unset config key '${this.extraheaderConfigKey}'`)
} else {
core.warning(
`Failed to unset config key '${this.extraheaderConfigKey}'`
)
}
}
return configValue
}
private async gitConfigStringReplace(
find: string,
replace: string
): Promise<void> {
let content = (await fs.promises.readFile(this.gitConfigPath)).toString()
const index = content.indexOf(find)
if (index < 0 || index != content.lastIndexOf(find)) {
throw new Error(`Unable to replace '${find}' in ${this.gitConfigPath}`)
}
content = content.replace(find, replace)
await fs.promises.writeFile(this.gitConfigPath, content)
}
private getServerUrl(): URL {
// todo: remove GITHUB_URL after support for GHES Alpha is no longer needed
// See https://github.com/actions/checkout/blob/main/src/url-helper.ts#L22-L29
return new URL(
process.env['GITHUB_SERVER_URL'] ||
process.env['GITHUB_URL'] ||
'https://github.com'
)
}
}

300
src/git-command-manager.ts Normal file
View File

@ -0,0 +1,300 @@
import * as exec from '@actions/exec'
import * as io from '@actions/io'
import * as utils from './utils'
import * as path from 'path'
const tagsRefSpec = '+refs/tags/*:refs/tags/*'
export class GitCommandManager {
private gitPath: string
private workingDirectory: string
// Git options used when commands require an identity
private identityGitOptions?: string[]
private constructor(workingDirectory: string, gitPath: string) {
this.workingDirectory = workingDirectory
this.gitPath = gitPath
}
static async create(workingDirectory: string): Promise<GitCommandManager> {
const gitPath = await io.which('git', true)
return new GitCommandManager(workingDirectory, gitPath)
}
setIdentityGitOptions(identityGitOptions: string[]): void {
this.identityGitOptions = identityGitOptions
}
async checkout(ref: string, startPoint?: string): Promise<void> {
const args = ['checkout', '--progress']
if (startPoint) {
args.push('-B', ref, startPoint)
} else {
args.push(ref)
}
// https://github.com/git/git/commit/a047fafc7866cc4087201e284dc1f53e8f9a32d5
args.push('--')
await this.exec(args)
}
async cherryPick(
options?: string[],
allowAllExitCodes = false
): Promise<GitOutput> {
const args = ['cherry-pick']
if (this.identityGitOptions) {
args.unshift(...this.identityGitOptions)
}
if (options) {
args.push(...options)
}
return await this.exec(args, allowAllExitCodes)
}
async commit(options?: string[]): Promise<void> {
const args = ['commit']
if (this.identityGitOptions) {
args.unshift(...this.identityGitOptions)
}
if (options) {
args.push(...options)
}
await this.exec(args)
}
async config(
configKey: string,
configValue: string,
globalConfig?: boolean
): Promise<void> {
await this.exec([
'config',
globalConfig ? '--global' : '--local',
configKey,
configValue
])
}
async configExists(
configKey: string,
configValue = '.',
globalConfig?: boolean
): Promise<boolean> {
const output = await this.exec(
[
'config',
globalConfig ? '--global' : '--local',
'--name-only',
'--get-regexp',
configKey,
configValue
],
true
)
return output.exitCode === 0
}
async fetch(
refSpec: string[],
remoteName?: string,
options?: string[]
): Promise<void> {
const args = ['-c', 'protocol.version=2', 'fetch']
if (!refSpec.some(x => x === tagsRefSpec)) {
args.push('--no-tags')
}
args.push('--progress', '--no-recurse-submodules')
if (
utils.fileExistsSync(path.join(this.workingDirectory, '.git', 'shallow'))
) {
args.push('--unshallow')
}
if (options) {
args.push(...options)
}
if (remoteName) {
args.push(remoteName)
} else {
args.push('origin')
}
for (const arg of refSpec) {
args.push(arg)
}
await this.exec(args)
}
async getConfigValue(configKey: string, configValue = '.'): Promise<string> {
const output = await this.exec([
'config',
'--local',
'--get-regexp',
configKey,
configValue
])
return output.stdout.trim().split(`${configKey} `)[1]
}
getWorkingDirectory(): string {
return this.workingDirectory
}
async hasDiff(options?: string[]): Promise<boolean> {
const args = ['diff', '--quiet']
if (options) {
args.push(...options)
}
const output = await this.exec(args, true)
return output.exitCode === 1
}
async isDirty(untracked: boolean, pathspec?: string[]): Promise<boolean> {
const pathspecArgs = pathspec ? ['--', ...pathspec] : []
// Check untracked changes
const sargs = ['--porcelain', '-unormal']
sargs.push(...pathspecArgs)
if (untracked && (await this.status(sargs))) {
return true
}
// Check working index changes
if (await this.hasDiff(pathspecArgs)) {
return true
}
// Check staged changes
const dargs = ['--staged']
dargs.push(...pathspecArgs)
if (await this.hasDiff(dargs)) {
return true
}
return false
}
async push(options?: string[]): Promise<void> {
const args = ['push']
if (options) {
args.push(...options)
}
await this.exec(args)
}
async revList(
commitExpression: string[],
options?: string[]
): Promise<string> {
const args = ['rev-list']
if (options) {
args.push(...options)
}
args.push(...commitExpression)
const output = await this.exec(args)
return output.stdout.trim()
}
async revParse(ref: string, options?: string[]): Promise<string> {
const args = ['rev-parse']
if (options) {
args.push(...options)
}
args.push(ref)
const output = await this.exec(args)
return output.stdout.trim()
}
async status(options?: string[]): Promise<string> {
const args = ['status']
if (options) {
args.push(...options)
}
const output = await this.exec(args)
return output.stdout.trim()
}
async symbolicRef(ref: string, options?: string[]): Promise<string> {
const args = ['symbolic-ref', ref]
if (options) {
args.push(...options)
}
const output = await this.exec(args)
return output.stdout.trim()
}
async tryConfigUnset(
configKey: string,
configValue = '.',
globalConfig?: boolean
): Promise<boolean> {
const output = await this.exec(
[
'config',
globalConfig ? '--global' : '--local',
'--unset',
configKey,
configValue
],
true
)
return output.exitCode === 0
}
async tryGetRemoteUrl(): Promise<string> {
const output = await this.exec(
['config', '--local', '--get', 'remote.origin.url'],
true
)
if (output.exitCode !== 0) {
return ''
}
const stdout = output.stdout.trim()
if (stdout.includes('\n')) {
return ''
}
return stdout
}
async exec(args: string[], allowAllExitCodes = false): Promise<GitOutput> {
const result = new GitOutput()
const env = {}
for (const key of Object.keys(process.env)) {
env[key] = process.env[key]
}
const stdout: string[] = []
const stderr: string[] = []
const options = {
cwd: this.workingDirectory,
env,
ignoreReturnCode: allowAllExitCodes,
listeners: {
stdout: (data: Buffer) => {
stdout.push(data.toString())
},
stderr: (data: Buffer) => {
stderr.push(data.toString())
}
}
}
result.exitCode = await exec.exec(`"${this.gitPath}"`, args, options)
result.stdout = stdout.join('')
result.stderr = stderr.join('')
return result
}
}
class GitOutput {
stdout = ''
stderr = ''
exitCode = 0
}

183
src/github-helper.ts Normal file
View File

@ -0,0 +1,183 @@
import * as core from '@actions/core'
import {Inputs} from './create-pull-request'
import {Octokit, OctokitOptions} from './octokit-client'
const ERROR_PR_REVIEW_FROM_AUTHOR =
'Review cannot be requested from pull request author'
interface Repository {
owner: string
repo: string
}
interface Pull {
number: number
html_url: string
created: boolean
}
export class GitHubHelper {
private octokit: InstanceType<typeof Octokit>
constructor(token: string) {
const options: OctokitOptions = {}
if (token) {
options.auth = `${token}`
}
options.baseUrl = process.env['GITHUB_API_URL'] || 'https://api.github.com'
this.octokit = new Octokit(options)
}
private parseRepository(repository: string): Repository {
const [owner, repo] = repository.split('/')
return {
owner: owner,
repo: repo
}
}
private async createOrUpdate(
inputs: Inputs,
baseRepository: string,
headRepository: string
): Promise<Pull> {
const [headOwner] = headRepository.split('/')
const headBranch = `${headOwner}:${inputs.branch}`
const headBranchFull = `${headRepository}:${inputs.branch}`
// Try to create the pull request
try {
core.info(`Attempting creation of pull request`)
const {data: pull} = await this.octokit.rest.pulls.create({
...this.parseRepository(baseRepository),
title: inputs.title,
head: headBranch,
base: inputs.base,
body: inputs.body,
draft: inputs.draft
})
core.info(
`Created pull request #${pull.number} (${headBranch} => ${inputs.base})`
)
return {
number: pull.number,
html_url: pull.html_url,
created: true
}
} catch (e: any) {
if (
e.message &&
e.message.includes(`A pull request already exists for`)
) {
core.info(`A pull request already exists for ${headBranch}`)
} else {
throw e
}
}
// Update the pull request that exists for this branch and base
core.info(`Fetching existing pull request`)
const {data: pulls} = await this.octokit.rest.pulls.list({
...this.parseRepository(baseRepository),
state: 'open',
head: headBranchFull,
base: inputs.base
})
core.info(`Attempting update of pull request`)
const {data: pull} = await this.octokit.rest.pulls.update({
...this.parseRepository(baseRepository),
pull_number: pulls[0].number,
title: inputs.title,
body: inputs.body
})
core.info(
`Updated pull request #${pull.number} (${headBranch} => ${inputs.base})`
)
return {
number: pull.number,
html_url: pull.html_url,
created: false
}
}
async getRepositoryParent(headRepository: string): Promise<string> {
const {data: headRepo} = await this.octokit.rest.repos.get({
...this.parseRepository(headRepository)
})
if (!headRepo.parent) {
throw new Error(
`Repository '${headRepository}' is not a fork. Unable to continue.`
)
}
return headRepo.parent.full_name
}
async createOrUpdatePullRequest(
inputs: Inputs,
baseRepository: string,
headRepository: string
): Promise<Pull> {
// Create or update the pull request
const pull = await this.createOrUpdate(
inputs,
baseRepository,
headRepository
)
// Apply milestone
if (inputs.milestone) {
core.info(`Applying milestone '${inputs.milestone}'`)
await this.octokit.rest.issues.update({
...this.parseRepository(baseRepository),
issue_number: pull.number,
milestone: inputs.milestone
})
}
// Apply labels
if (inputs.labels.length > 0) {
core.info(`Applying labels '${inputs.labels}'`)
await this.octokit.rest.issues.addLabels({
...this.parseRepository(baseRepository),
issue_number: pull.number,
labels: inputs.labels
})
}
// Apply assignees
if (inputs.assignees.length > 0) {
core.info(`Applying assignees '${inputs.assignees}'`)
await this.octokit.rest.issues.addAssignees({
...this.parseRepository(baseRepository),
issue_number: pull.number,
assignees: inputs.assignees
})
}
// Request reviewers and team reviewers
const requestReviewersParams = {}
if (inputs.reviewers.length > 0) {
requestReviewersParams['reviewers'] = inputs.reviewers
core.info(`Requesting reviewers '${inputs.reviewers}'`)
}
if (inputs.teamReviewers.length > 0) {
requestReviewersParams['team_reviewers'] = inputs.teamReviewers
core.info(`Requesting team reviewers '${inputs.teamReviewers}'`)
}
if (Object.keys(requestReviewersParams).length > 0) {
try {
await this.octokit.rest.pulls.requestReviewers({
...this.parseRepository(baseRepository),
pull_number: pull.number,
...requestReviewersParams
})
} catch (e: any) {
if (e.message && e.message.includes(ERROR_PR_REVIEW_FROM_AUTHOR)) {
core.warning(ERROR_PR_REVIEW_FROM_AUTHOR)
} else {
throw e
}
}
}
return pull
}
}

38
src/main.ts Normal file
View File

@ -0,0 +1,38 @@
import * as core from '@actions/core'
import {Inputs, createPullRequest} from './create-pull-request'
import {inspect} from 'util'
import * as utils from './utils'
async function run(): Promise<void> {
try {
const inputs: Inputs = {
token: core.getInput('token'),
path: core.getInput('path'),
addPaths: utils.getInputAsArray('add-paths'),
commitMessage: core.getInput('commit-message'),
committer: core.getInput('committer'),
author: core.getInput('author'),
signoff: core.getBooleanInput('signoff'),
branch: core.getInput('branch'),
deleteBranch: core.getBooleanInput('delete-branch'),
branchSuffix: core.getInput('branch-suffix'),
base: core.getInput('base'),
pushToFork: core.getInput('push-to-fork'),
title: core.getInput('title'),
body: core.getInput('body'),
labels: utils.getInputAsArray('labels'),
assignees: utils.getInputAsArray('assignees'),
reviewers: utils.getInputAsArray('reviewers'),
teamReviewers: utils.getInputAsArray('team-reviewers'),
milestone: Number(core.getInput('milestone')),
draft: core.getBooleanInput('draft')
}
core.debug(`Inputs: ${inspect(inputs)}`)
await createPullRequest(inputs)
} catch (error: any) {
core.setFailed(error.message)
}
}
run()

33
src/octokit-client.ts Normal file
View File

@ -0,0 +1,33 @@
import {Octokit as Core} from '@octokit/core'
import {paginateRest} from '@octokit/plugin-paginate-rest'
import {restEndpointMethods} from '@octokit/plugin-rest-endpoint-methods'
import {HttpsProxyAgent} from 'https-proxy-agent'
export {RestEndpointMethodTypes} from '@octokit/plugin-rest-endpoint-methods'
export {OctokitOptions} from '@octokit/core/dist-types/types'
export const Octokit = Core.plugin(
paginateRest,
restEndpointMethods,
autoProxyAgent
)
// Octokit plugin to support the https_proxy and no_proxy environment variable
function autoProxyAgent(octokit: Core) {
const proxy = process.env.https_proxy || process.env.HTTPS_PROXY
const noProxy = process.env.no_proxy || process.env.NO_PROXY
let noProxyArray: string[] = []
if (noProxy) {
noProxyArray = noProxy.split(',')
}
if (!proxy) return
const agent = new HttpsProxyAgent(proxy)
octokit.hook.before('request', options => {
if (noProxyArray.includes(options.request.hostname)) {
return
}
options.request.agent = agent
})
}

152
src/utils.ts Normal file
View File

@ -0,0 +1,152 @@
import * as core from '@actions/core'
import * as fs from 'fs'
import * as path from 'path'
export function getInputAsArray(
name: string,
options?: core.InputOptions
): string[] {
return getStringAsArray(core.getInput(name, options))
}
export function getStringAsArray(str: string): string[] {
return str
.split(/[\n,]+/)
.map(s => s.trim())
.filter(x => x !== '')
}
export function getRepoPath(relativePath?: string): string {
let githubWorkspacePath = process.env['GITHUB_WORKSPACE']
if (!githubWorkspacePath) {
throw new Error('GITHUB_WORKSPACE not defined')
}
githubWorkspacePath = path.resolve(githubWorkspacePath)
core.debug(`githubWorkspacePath: ${githubWorkspacePath}`)
let repoPath = githubWorkspacePath
if (relativePath) repoPath = path.resolve(repoPath, relativePath)
core.debug(`repoPath: ${repoPath}`)
return repoPath
}
interface RemoteDetail {
protocol: string
repository: string
}
export function getRemoteDetail(remoteUrl: string): RemoteDetail {
// Parse the protocol and github repository from a URL
// e.g. HTTPS, peter-evans/create-pull-request
const githubUrl = process.env['GITHUB_SERVER_URL'] || 'https://github.com'
const githubServerMatch = githubUrl.match(/^https?:\/\/(.+)$/i)
if (!githubServerMatch) {
throw new Error('Could not parse GitHub Server name')
}
const httpsUrlPattern = new RegExp(
'^https?://.*@?' + githubServerMatch[1] + '/(.+/.+?)(.git)?$',
'i'
)
const sshUrlPattern = new RegExp(
'^git@' + githubServerMatch[1] + ':(.+/.+).git$',
'i'
)
const httpsMatch = remoteUrl.match(httpsUrlPattern)
if (httpsMatch) {
return {
protocol: 'HTTPS',
repository: httpsMatch[1]
}
}
const sshMatch = remoteUrl.match(sshUrlPattern)
if (sshMatch) {
return {
protocol: 'SSH',
repository: sshMatch[1]
}
}
throw new Error(
`The format of '${remoteUrl}' is not a valid GitHub repository URL`
)
}
export function getRemoteUrl(protocol: string, repository: string): string {
return protocol == 'HTTPS'
? `https://github.com/${repository}`
: `git@github.com:${repository}.git`
}
export function secondsSinceEpoch(): number {
const now = new Date()
return Math.round(now.getTime() / 1000)
}
export function randomString(): string {
return Math.random().toString(36).substr(2, 7)
}
interface DisplayNameEmail {
name: string
email: string
}
export function parseDisplayNameEmail(
displayNameEmail: string
): DisplayNameEmail {
// Parse the name and email address from a string in the following format
// Display Name <email@address.com>
const pattern = /^([^<]+)\s*<([^>]+)>$/i
// Check we have a match
const match = displayNameEmail.match(pattern)
if (!match) {
throw new Error(
`The format of '${displayNameEmail}' is not a valid email address with display name`
)
}
// Check that name and email are not just whitespace
const name = match[1].trim()
const email = match[2].trim()
if (!name || !email) {
throw new Error(
`The format of '${displayNameEmail}' is not a valid email address with display name`
)
}
return {
name: name,
email: email
}
}
export function fileExistsSync(path: string): boolean {
if (!path) {
throw new Error("Arg 'path' must not be empty")
}
let stats: fs.Stats
try {
stats = fs.statSync(path)
} catch (error: any) {
if (error.code === 'ENOENT') {
return false
}
throw new Error(
`Encountered an error when checking whether path '${path}' exists: ${error.message}`
)
}
if (!stats.isDirectory()) {
return true
}
return false
}

16
tsconfig.json Normal file
View File

@ -0,0 +1,16 @@
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"lib": [
"es6"
],
"outDir": "./lib",
"rootDir": "./src",
"declaration": true,
"strict": true,
"noImplicitAny": false,
"esModuleInterop": true
},
"exclude": ["__test__", "lib", "node_modules"]
}