mirror of
https://github.com/peter-evans/repository-dispatch.git
synced 2026-06-14 04:41:26 +00:00
Compare commits
23 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
26b39ed245 | ||
|
|
b155cf1427 | ||
|
|
faa2bf022d | ||
|
|
0bc97bd4b8 | ||
|
|
8ab3ab850d | ||
|
|
defb7de2f3 | ||
|
|
fb1da2a91f | ||
|
|
ec896de369 | ||
|
|
9255d358ad | ||
|
|
f8e700e208 | ||
|
|
3c7e484edb | ||
|
|
cb18cc8cd6 | ||
|
|
1f873ff42d | ||
|
|
73f2fe9d70 | ||
|
|
9b60aa8a4d | ||
|
|
f2696244ec | ||
|
|
2f6d32ce83 | ||
|
|
66463e47e7 | ||
|
|
aebc169929 | ||
|
|
b700ade2f3 | ||
|
|
8e295bb3b1 | ||
|
|
3c4e552d10 | ||
|
|
77fb463884 |
8
.github/dependabot.yml
vendored
8
.github/dependabot.yml
vendored
@@ -3,13 +3,13 @@ updates:
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
interval: "monthly"
|
||||
labels:
|
||||
- "dependencies"
|
||||
|
||||
- package-ecosystem: "npm"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
allow:
|
||||
- dependency-name: "@actions/*"
|
||||
interval: "monthly"
|
||||
labels:
|
||||
- "dependencies"
|
||||
|
||||
13
.github/workflows/automerge-dependabot.yml
vendored
Normal file
13
.github/workflows/automerge-dependabot.yml
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
name: Auto-merge Dependabot
|
||||
on: pull_request
|
||||
|
||||
jobs:
|
||||
automerge:
|
||||
runs-on: ubuntu-latest
|
||||
if: github.actor == 'dependabot[bot]'
|
||||
steps:
|
||||
- uses: peter-evans/enable-pull-request-automerge@v2
|
||||
with:
|
||||
token: ${{ secrets.DEPENDABOT_AUTOMERGE }}
|
||||
pull-request-number: ${{ github.event.pull_request.number }}
|
||||
merge-method: squash
|
||||
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@@ -60,14 +60,12 @@ jobs:
|
||||
- name: Test repository dispatch
|
||||
uses: ./
|
||||
with:
|
||||
token: ${{ secrets.REPO_ACCESS_TOKEN }}
|
||||
event-type: tests
|
||||
client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}"}'
|
||||
|
||||
- name: Test repository dispatch (default payload)
|
||||
uses: ./
|
||||
with:
|
||||
token: ${{ secrets.REPO_ACCESS_TOKEN }}
|
||||
event-type: tests
|
||||
|
||||
package:
|
||||
|
||||
25
README.md
25
README.md
@@ -6,11 +6,20 @@ A GitHub action to create a repository dispatch event.
|
||||
|
||||
## Usage
|
||||
|
||||
Dispatch an event to the current repository.
|
||||
```yml
|
||||
- name: Repository Dispatch
|
||||
uses: peter-evans/repository-dispatch@v2
|
||||
with:
|
||||
token: ${{ secrets.REPO_ACCESS_TOKEN }}
|
||||
event-type: my-event
|
||||
```
|
||||
|
||||
Dispatch an event to a remote repository using a `repo` scoped [Personal Access Token (PAT)](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token).
|
||||
```yml
|
||||
- name: Repository Dispatch
|
||||
uses: peter-evans/repository-dispatch@v2
|
||||
with:
|
||||
token: ${{ secrets.PAT }}
|
||||
event-type: my-event
|
||||
```
|
||||
|
||||
@@ -18,15 +27,17 @@ A GitHub action to create a repository dispatch event.
|
||||
|
||||
| Name | Description | Default |
|
||||
| --- | --- | --- |
|
||||
| `token` | (**required**) A `repo` scoped GitHub [Personal Access Token](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token). See [token](#token) for further details. | |
|
||||
| `token` | `GITHUB_TOKEN` (permissions `contents: write`) or a `repo` scoped [Personal Access Token (PAT)](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token). See [token](#token) for further details. | `GITHUB_TOKEN` |
|
||||
| `repository` | The full name of the repository to send the dispatch. | `github.repository` (current repository) |
|
||||
| `event-type` | (**required**) A custom webhook event name. | |
|
||||
| `client-payload` | JSON payload with extra information about the webhook event that your action or workflow may use. | `{}` |
|
||||
|
||||
#### `token`
|
||||
#### Token
|
||||
|
||||
This action creates [`repository_dispatch`](https://developer.github.com/v3/repos/#create-a-repository-dispatch-event) events.
|
||||
The default `GITHUB_TOKEN` does not have scopes to do this so a `repo` scoped [PAT](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) created on a user with `write` access to the target repository is required.
|
||||
This action creates [`repository_dispatch`](https://docs.github.com/en/rest/repos/repos#create-a-repository-dispatch-event) events.
|
||||
The default `GITHUB_TOKEN` token can only be used if you are dispatching the same repository that the workflow is executing in.
|
||||
|
||||
To dispatch to a remote repository you must create a [Personal Access Token (PAT)](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token) with the `repo` scope and store it as a secret.
|
||||
If you will be dispatching to a public repository then you can use the more limited `public_repo` scope.
|
||||
|
||||
## Example
|
||||
@@ -37,7 +48,7 @@ Here is an example setting all of the input parameters.
|
||||
- name: Repository Dispatch
|
||||
uses: peter-evans/repository-dispatch@v2
|
||||
with:
|
||||
token: ${{ secrets.REPO_ACCESS_TOKEN }}
|
||||
token: ${{ secrets.PAT }}
|
||||
repository: username/my-repo
|
||||
event-type: my-event
|
||||
client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}"}'
|
||||
@@ -80,7 +91,7 @@ jobs:
|
||||
- name: Repository Dispatch
|
||||
uses: peter-evans/repository-dispatch@v2
|
||||
with:
|
||||
token: ${{ secrets.REPO_ACCESS_TOKEN }}
|
||||
token: ${{ secrets.PAT }}
|
||||
repository: ${{ matrix.repo }}
|
||||
event-type: my-event
|
||||
```
|
||||
|
||||
@@ -2,8 +2,8 @@ name: 'Repository Dispatch'
|
||||
description: 'Create a repository dispatch event'
|
||||
inputs:
|
||||
token:
|
||||
description: 'A repo scoped GitHub Personal Access Token'
|
||||
required: true
|
||||
description: 'GITHUB_TOKEN or a `repo` scoped Personal Access Token (PAT)'
|
||||
default: ${{ github.token }}
|
||||
repository:
|
||||
description: 'The full name of the repository to send the dispatch.'
|
||||
default: ${{ github.repository }}
|
||||
|
||||
13
dist/index.js
vendored
13
dist/index.js
vendored
@@ -38,6 +38,15 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
const core = __importStar(__nccwpck_require__(2186));
|
||||
const github = __importStar(__nccwpck_require__(5438));
|
||||
const util_1 = __nccwpck_require__(3837);
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
function hasErrorStatus(error) {
|
||||
return typeof error.code === 'number';
|
||||
}
|
||||
function getErrorMessage(error) {
|
||||
if (error instanceof Error)
|
||||
return error.message;
|
||||
return String(error);
|
||||
}
|
||||
function run() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
@@ -59,11 +68,11 @@ function run() {
|
||||
}
|
||||
catch (error) {
|
||||
core.debug((0, util_1.inspect)(error));
|
||||
if (error.status == 404) {
|
||||
if (hasErrorStatus(error) && error.status == 404) {
|
||||
core.setFailed('Repository not found, OR token has insufficient permissions.');
|
||||
}
|
||||
else {
|
||||
core.setFailed(error.message);
|
||||
core.setFailed(getErrorMessage(error));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
3614
package-lock.json
generated
3614
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
10
package.json
10
package.json
@@ -32,16 +32,16 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^27.0.3",
|
||||
"@types/node": "^16.11.11",
|
||||
"@types/node": "^18.11.11",
|
||||
"@typescript-eslint/parser": "^5.5.0",
|
||||
"@vercel/ncc": "^0.32.0",
|
||||
"@vercel/ncc": "^0.36.0",
|
||||
"eslint": "^8.3.0",
|
||||
"eslint-plugin-github": "^4.3.5",
|
||||
"eslint-plugin-github": "^4.6.0",
|
||||
"eslint-plugin-jest": "^25.3.0",
|
||||
"jest": "^27.4.3",
|
||||
"jest-circus": "^27.4.2",
|
||||
"jest-circus": "^29.3.1",
|
||||
"js-yaml": "^4.1.0",
|
||||
"prettier": "^2.5.0",
|
||||
"prettier": "^2.8.1",
|
||||
"ts-jest": "^27.0.7",
|
||||
"typescript": "^4.5.2"
|
||||
}
|
||||
|
||||
16
src/main.ts
16
src/main.ts
@@ -2,6 +2,16 @@ import * as core from '@actions/core'
|
||||
import * as github from '@actions/github'
|
||||
import {inspect} from 'util'
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
function hasErrorStatus(error: any): error is {status: number} {
|
||||
return typeof error.code === 'number'
|
||||
}
|
||||
|
||||
function getErrorMessage(error: unknown) {
|
||||
if (error instanceof Error) return error.message
|
||||
return String(error)
|
||||
}
|
||||
|
||||
async function run(): Promise<void> {
|
||||
try {
|
||||
const inputs = {
|
||||
@@ -22,14 +32,14 @@ async function run(): Promise<void> {
|
||||
event_type: inputs.eventType,
|
||||
client_payload: JSON.parse(inputs.clientPayload)
|
||||
})
|
||||
} catch (error: any) {
|
||||
} catch (error) {
|
||||
core.debug(inspect(error))
|
||||
if (error.status == 404) {
|
||||
if (hasErrorStatus(error) && error.status == 404) {
|
||||
core.setFailed(
|
||||
'Repository not found, OR token has insufficient permissions.'
|
||||
)
|
||||
} else {
|
||||
core.setFailed(error.message)
|
||||
core.setFailed(getErrorMessage(error))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user