From 4e2967f1a4e97b4aa544c7199d5b58905f7c029d Mon Sep 17 00:00:00 2001 From: Kyle Adams Date: Mon, 1 Jul 2024 09:51:00 -0400 Subject: [PATCH 1/2] feat: support pull_request_target events `pull_request` events don't have the necessary privileges to access private repos. Adding support for the `pull_request_target` event will allow private repos to also use commit lint. --- README.md | 2 +- github_actions/run.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 95fd7fc..ad71dab 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ jobs: uses: opensource-nepal/commitlint@v1 ``` -> **_NOTE:_** commitlint GitHub Actions will only be triggered by "push" or "pull_request" events. +> **_NOTE:_** commitlint GitHub Actions will only be triggered by "push", "pull_request", or "pull_request_target" events. The difference between "pull_request" and "pull_request_target" is that "pull_request" is more secure for public repos while "pull_request_target" is necessary for private repos. #### GitHub Action Inputs diff --git a/github_actions/run.py b/github_actions/run.py index 1822bf7..26d576d 100644 --- a/github_actions/run.py +++ b/github_actions/run.py @@ -13,6 +13,7 @@ # Events EVENT_PUSH = "push" EVENT_PULL_REQUEST = "pull_request" +EVENT_PULL_REQUEST_TARGET = "pull_request_target" # Inputs INPUT_FAIL_ON_ERROR = "INPUT_FAIL_ON_ERROR" @@ -176,6 +177,8 @@ def main() -> None: _handle_push_event(event) elif event.event_name == EVENT_PULL_REQUEST: _handle_pr_event(event) + elif event.event_name == EVENT_PULL_REQUEST_TARGET: + _handle_pr_event(event) elif event.event_name is None: sys.stdout.write("No any events, skipping\n") else: From ffc9b34416b0b0e6296c03d61e04d58601d5ea70 Mon Sep 17 00:00:00 2001 From: Kyle Adams Date: Mon, 1 Jul 2024 14:38:39 -0400 Subject: [PATCH 2/2] refactor: consolidate conditionals for PR events Co-authored-by: Sugat Bajracharya <30311933+sugat009@users.noreply.github.com> --- github_actions/run.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/github_actions/run.py b/github_actions/run.py index 26d576d..24ee644 100644 --- a/github_actions/run.py +++ b/github_actions/run.py @@ -175,9 +175,7 @@ def main() -> None: if event.event_name == EVENT_PUSH: _handle_push_event(event) - elif event.event_name == EVENT_PULL_REQUEST: - _handle_pr_event(event) - elif event.event_name == EVENT_PULL_REQUEST_TARGET: + elif event.event_name in {EVENT_PULL_REQUEST, EVENT_PULL_REQUEST_TARGET}: _handle_pr_event(event) elif event.event_name is None: sys.stdout.write("No any events, skipping\n")