Skip to content

Commit

Permalink
fix: support events without a payload (#15)
Browse files Browse the repository at this point in the history
* support events that don't have a payload

For example, 'on: schedule' does not have a payload[1], which results in
an error when attempting to use this action:

    TypeError: Cannot read property 'url' of undefined

This commit updates the code to use the `repo` attribute instead
of parsing out the repo org/name from the repo URL.

1. https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule

* prepare build

```
npm run lint && npm run format && npm run build
```

Added this as a separate commit, as I don't know anything about npm
packages, and it's not clear if all of the package list changes are
desirable.

* README: unify version

It may be preferable to set a v1 link and keep that updated to point to
the latest release.

Also mentioned in PR #11:
#11 (comment)
  • Loading branch information
zackse committed Jun 17, 2022
1 parent 7b29cee commit 21b9739
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 191 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
steps:
- name: <customize name>
id: <customize id>
uses: CircleCI-Public/trigger-circleci-pipeline-action@v1.0
uses: CircleCI-Public/trigger-circleci-pipeline-action@v1.0.4
with:
GHA_Meta: "<custom data>"
env:
Expand Down
6 changes: 2 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12702,10 +12702,8 @@ __nccwpck_require__.r(__webpack_exports__);


(0,_actions_core__WEBPACK_IMPORTED_MODULE_0__.startGroup)("Preparing CircleCI Pipeline Trigger");
const payload = _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.payload;
const pattern = /github\.com\/(repos\/)?(.*)\/(.*)$/gm;
const [, , repoOrg, repoName] = pattern.exec(payload.repository.url);
(0,_actions_core__WEBPACK_IMPORTED_MODULE_0__.info)(`URL: ${payload.repository.url}`);
const repoOrg = _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.owner;
const repoName = _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.repo;
(0,_actions_core__WEBPACK_IMPORTED_MODULE_0__.info)(`Org: ${repoOrg}`);
(0,_actions_core__WEBPACK_IMPORTED_MODULE_0__.info)(`Repo: ${repoName}`);
const ref = _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.ref;
Expand Down
6 changes: 2 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ import { context } from "@actions/github";
import axios from "axios";

startGroup("Preparing CircleCI Pipeline Trigger");
const payload = context.payload;
const pattern = /github\.com\/(repos\/)?(.*)\/(.*)$/gm;
const [, , repoOrg, repoName] = pattern.exec(payload.repository.url);
info(`URL: ${payload.repository.url}`);
const repoOrg = context.repo.owner;
const repoName = context.repo.repo;
info(`Org: ${repoOrg}`);
info(`Repo: ${repoName}`);
const ref = context.ref;
Expand Down
Loading

0 comments on commit 21b9739

Please sign in to comment.