GitHub (Apps step)
GitHub
Lists, creates, updates and comments on GitHub issues.
Use it to track work in GitHub issues from a workflow: open an issue when a job fails, list the open ones for a report, or comment when something ships.
Beta. This step has not yet been checked against a live GitHub account, so treat its first runs as a test, and tell us if an operation does not answer as described.
Find it in the workflow editor's palette under Apps. See Apps steps for what every Apps step has in common.
Set it up
- In GitHub, open Settings › Developer settings › Personal access tokens › Fine-grained tokens and create a token for the repositories you need, with Issues: Read and write.
- In DataMagik, open Script Engine › Credentials and add a "Bearer Token" credential holding the token.
- Add api.github.com to Allowed Domains in the workflow's Script settings.
Credential: A Bearer Token credential holding a GitHub fine-grained personal access token.
Hosts it calls: api.github.com
Operations
| Operation | What it does |
|---|---|
| Issue › List | Lists a repository's issues, following every page up to the step's page limit. |
| Issue › Get | Reads one issue by its number. |
| Issue › Create | Opens an issue in a repository. |
| Issue › Update | Changes an issue's title, body, state or labels. |
| Comment › Add | Adds a comment to an issue or pull request. |
Issue › List
Lists a repository's issues, following every page up to the step's page limit.
Calls GET /repos/{owner}/{repo}/issues. Follows the pages, up to Most pages (10 unless you change it).
| Field | Required | What to put |
|---|---|---|
| Owner | Yes | The user or organization that owns the repository. For example acme. |
| Repository | Yes | The repository's name. For example integrations. |
| State | No | Which issues to list. One of: Open, Closed, All. |
| With labels | No | Only issues with every one of these comma-separated labels. For example bug,plant-1. |
| Page size | No | Issues per request (GitHub's limit is 100). For example 30. |
What comes out: One item per issue: {{ $json.number }}, {{ $json.title }}, {{ $json.state }}, {{ $json.html_url }}, {{ $json.labels }} and {{ $json.user.login }}.
Example: List the open issues labelled plant-1 for a weekly status document.
Issue › Get
Reads one issue by its number.
Calls GET /repos/{owner}/{repo}/issues/{issue_number}.
| Field | Required | What to put |
|---|---|---|
| Owner | Yes | The user or organization that owns the repository. For example acme. |
| Repository | Yes | The repository's name. For example integrations. |
| Issue number | Yes | The number after the # in the issue's title. For example 42. |
What comes out: One item: the issue, with {{ $json.number }}, {{ $json.title }}, {{ $json.state }}, {{ $json.body }} and {{ $json.html_url }}.
Example: Read issue {{ $json.gh_issue }} to see whether it is closed before re-running a fix.
Issue › Create
Opens an issue in a repository.
Calls POST /repos/{owner}/{repo}/issues.
| Field | Required | What to put |
|---|---|---|
| Owner | Yes | The user or organization that owns the repository. For example acme. |
| Repository | Yes | The repository's name. For example integrations. |
| Title | Yes | The issue's title. |
| Body | No | The issue's description, in Markdown. |
| Labels | No | A JSON list of label names. For example ["bug"]. |
What comes out: One item: the new issue, with {{ $json.number }}, {{ $json.html_url }} and {{ $json.id }}.
Example: Open an issue titled Label printer {{ $json.printer }} offline, labelled ops, when a print job fails.
Issue › Update
Changes an issue's title, body, state or labels.
Calls PATCH /repos/{owner}/{repo}/issues/{issue_number}.
| Field | Required | What to put |
|---|---|---|
| Owner | Yes | The user or organization that owns the repository. For example acme. |
| Repository | Yes | The repository's name. For example integrations. |
| Issue number | Yes | The number after the # in the issue's title. For example 42. |
| Title | No | The issue's title. Leave empty to keep it. |
| Body | No | The issue's description, in Markdown. Leave empty to keep it. |
| State | No | Open or close the issue. One of: Open, Closed. |
| Labels | No | A JSON list of label names; it replaces the issue's labels. Leave empty to keep them. For example ["bug"]. |
What comes out: One item: the issue as it now is, with {{ $json.number }}, {{ $json.state }} and {{ $json.html_url }}.
Example: Close issue {{ $json.gh_issue }} when the printer it reported comes back online.
Comment › Add
Adds a comment to an issue or pull request.
Calls POST /repos/{owner}/{repo}/issues/{issue_number}/comments.
| Field | Required | What to put |
|---|---|---|
| Owner | Yes | The user or organization that owns the repository. For example acme. |
| Repository | Yes | The repository's name. For example integrations. |
| Issue number | Yes | The number after the # in the issue's title. For example 42. |
| Comment | Yes | The comment, in Markdown. |
What comes out: One item: the new comment, with {{ $json.id }}, {{ $json.html_url }} and {{ $json.created_at }}.
Example: Comment Fixed in run {{ $json.run_id }} on the issue the failure opened.
Trigger: GitHub: New Items
Under Triggers in the palette. It looks at GitHub on a schedule (every 15 minutes unless you change Look every) with one of these operations: Issue › List, and starts the workflow with the items it has not seen on an earlier look, one item each. Saving the workflow sets up the schedule.
- New means: not seen before, by the item's id (or the field you name in Item field), or newer than the newest one last time, by a date or increasing number.
- On the first run it only remembers what is there, unless you choose Start with everything.
- Test runs show what would be new without remembering it. It remembers the last 5000 ids, so filter the list to keep it shorter than that.
Example
A When a Workflow Fails trigger feeds GitHub › Create issue in acme/integrations, titled Workflow {{ $json.workflow }} failed, with the error in the body.
Tips
- Owner is the user or organization, Repository the name after the slash: acme and integrations for github.com/acme/integrations.
- List issues also returns pull requests (GitHub treats them as issues); filter on {{ $json.pull_request }} being empty to drop them.
- It calls GitHub on test runs too, so create issues in a test repository while building.
Settings every Apps step has
- More query parameters: any query parameter the fields do not offer, sent as is.
- More body fields: a JSON object merged into the request body; nested objects merge, other values replace.
- Most requests per second: spaces the calls out for rate limits. A "too many requests" (429) answer is retried after the wait the API asks for.
- Most pages: for operations that follow pages, the most pages to fetch (10 unless you change it, up to 100). The run warns when it stops with more to get.
- Fail on a non-2xx response: on by default. Turn it off to handle errors yourself.
GitHub's own API documentation: https://docs.github.com/en/rest/issues