Skip to content

Commit

Permalink
Merge pull request #39 from rouilj/patch-1
Browse files Browse the repository at this point in the history
Update Using GitHub API section of triggers.md to current API
  • Loading branch information
AnandChowdhary committed Feb 18, 2023
2 parents 97b73e8 + 10874ac commit 2f9a6b0
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions docs/triggers.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,28 +54,40 @@ You will see the message "This workflow has a `workflow_dispatch` event trigger.

### Using the GitHub API

If you want to programmatically trigger updates, you can use the GitHub REST API's repository dispatch events by triggering an event in your repository called `setup`:
If you want to programmatically trigger updates, you can use the GitHub REST API's repository dispatch events by triggering an event in your repository called `Uptime CI` located in the file `uptime.yml` (to trigger the Setup CI workflow, you change `uptime.yml` to `setup.yml`):

```bash
curl \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token {YOUR GITHUB TOKEN}" \
https://api.github.com/repos/{YOUR GITHUB USERNAME}/{YOUR UPPTIME REPO NAME}/dispatches \
-d '{"event_type":"setup"}'
```
To get your gitub token, simply go to settings -> Developer settings -> Personal access tokens -> generate new token
curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer {YOUR GITHUB TOKEN}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-d '{"ref": "master"}' \
https://api.github.com/repos/{YOUR GITHUB USERNAME}/{YOUR UPPTIME REPO NAME}/actions/workflows/uptime.yml/dispatches
```
To get your GitHub token, simply go to settings -> Developer settings -> Personal access tokens. You have two options:

* Fine-grained tokens or
* Tokens (classic)

Fine-grained tokens may still be in beta when you use this. Once you choose one, select the "Generate new token" button.
Fine grained tokens ae preferred as you can limit the token to a specific repository.

In either case Type any note or name you wish, and set Expiration to anything you wish too (*I recommend make it never expire*).

Type any note or name you wish, and set Expiration to anything you wish too (*I recommend make it never expire*) and in "Select scopes" select on *workflow* and generate your new token and save it somewhere safe
* If you are using the fine-grained token option, create a token with "Repository access" restricted to `{YOUR UPPTIME REPO NAME}`.
Once you have selected a repository, under "Repository permissions", set "Actions" to read and write permissions.
* If you are using the classic tokens, in "Select scopes" select on *workflow*.

Then generate your new token using the button at the bottom of the page and save it somewhere safe.

Or, with JavaScript ([@octokit/core.js](https://github.com/octokit/core.js)):
Or, with JavaScript ([@octokit/core.js](https://github.com/octokit/core.js)) (untested):

```js
await octokit.request("POST /repos/{owner}/{repo}/dispatches", {
await octokit.request("POST /repos/{owner}/{repo}/actions/workflows/uptime.yml/dispatches", {
owner: "user",
repo: "repo",
event_type: "setup",
ref: "master",
});
```

Expand Down

0 comments on commit 2f9a6b0

Please sign in to comment.