# Scheduled GitHub pull request digests and issues

Post open pull requests to your team's chat before standup, and open recurring issues for chores, without a GitHub Action that runs on a schedule.

## Example: open PRs to Slack every weekday

```json
{
  "name": "Open PRs to #eng",
  "cron": { "expression": "0 9 * * 1-5", "time_zone": "Europe/Berlin" },
  "nodes": [
    { "id": "prs", "github_list_pull_requests": { "credential_id": "YOUR_GITHUB_CREDENTIAL_ID", "owner": "acme", "repo": "web", "state": "open" } },
    { "id": "lines", "transform": { "template": "{ \"count\": \"{{ $.length }}\", \"lines\": { \"{{#each $}}\": \"• <{{ $.html_url }}|#{{ $.number }}> {{ $.title }} ({{ $.user.login }})\" } }" } },
    { "id": "post", "slack_send_message": {
        "webhook_url": "https://hooks.slack.com/services/T000/B000/XXXX",
        "text": "*{{ $.count }} open pull requests*\n{{ join($.lines, \"\\n\") }}" } }
  ]
}
```

## Example: a monthly dependency review issue

```json
{
  "name": "Monthly dependency review",
  "cron": { "expression": "0 9 * * MON#1", "time_zone": "America/New_York" },
  "nodes": [
    { "id": "issue", "github_create_issue": {
        "credential_id": "YOUR_GITHUB_CREDENTIAL_ID",
        "owner": "acme",
        "repo": "web",
        "title": "Dependency review: {{ format(now:America/New_York, \"MMMM YYYY\") }}",
        "body": "- [ ] Review Dependabot PRs\n- [ ] Check `npm audit`\n- [ ] Bump the Go toolchain" } }
  ]
}
```

## Set up

Create a [fine-grained token](https://github.com/settings/personal-access-tokens) with read access to pull requests (and write access to issues, to open them), and save it as a `bearer_token` credential.

## Reference

### List GitHub pull requests: `github_list_pull_requests`

**Sends** GET `https://api.github.com/repos/<owner>/<repo>/pulls`. **Output** for the next step: A list of pull requests, each with `number`, `title`, `html_url`, `user.login`, `draft` and `created_at`.

| Field | Type | Notes |
| --- | --- | --- |
| `credential_id` | string, required | The id of a `bearer_token` credential holding a GitHub token that can read the repository. |
| `owner` | string, required | The user or organization. |
| `repo` | string, required | The repository name. |
| `state` | string, required | `open`, `closed` or `all`. |
| `per_page` | integer | 1 to 100. Omit for GitHub’s default of 30. |

### Open a GitHub issue: `github_create_issue`

**Sends** POST `https://api.github.com/repos/<owner>/<repo>/issues`. **Output** for the next step: The created issue, with its `number` and `html_url`.

| Field | Type | Notes |
| --- | --- | --- |
| `credential_id` | string, required | The id of a `bearer_token` credential holding a GitHub token that can create issues. |
| `owner` | string, required | The user or organization. |
| `repo` | string, required | The repository name. |
| `title` | string, required | Up to 256 characters. Placeholders allowed. |
| `body` | string | Markdown, up to 65,536 characters. Placeholders allowed. |

## More ideas

- Post stale PRs (open over a week) by filtering in a transform and your own endpoint.
- Open a weekly on-call handoff issue: `0 16 * * FRI`.
- Open a release checklist issue once, at an exact time, with `run_at`.
