Skip to content

Instantly share code, notes, and snippets.

@philip-gai
Last active March 30, 2022 20:03
Show Gist options
  • Save philip-gai/55a1c3b8564c7c29a42c15ae0f35bfd1 to your computer and use it in GitHub Desktop.
Save philip-gai/55a1c3b8564c7c29a42c15ae0f35bfd1 to your computer and use it in GitHub Desktop.
GitHub Actions: Update repository issues using the gh cli
# Sends a reminder to assignees of all open issues in a repo using pwsh
# Uses the built-in GITHUB_TOKEN: https://docs.github.com/en/actions/security-guides/automatic-token-authentication
# Replace the GITHUB_TOKEN environment variable with your own PAT to make the issue comment as yourself
# See example runs: https://github.com/philip-gai/philip-gai/actions/workflows/send_reminders.yml
name: Send Reminders
on:
workflow_dispatch: {}
jobs:
send_reminders:
name: Send Reminders
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- name: Run Send Reminders Script
shell: pwsh
env:
GH_CLI_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
$ErrorActionPreference = 'Stop'
$repository = "${{ github.repository }}"
Write-Host "Logging in..."
$env:GH_CLI_TOKEN | gh auth login --with-token
if(!$?) { exit 1 }
Write-Host "Getting issues..."
$issues = $(gh issue list -R $repository --state open --json "number,assignees" -L 500) | ConvertFrom-Json
if(!$?) { exit 1 }
Write-Host "Found $($issues.Count) issues"
Write-Host "Filtering out issues that are not assigned..."
$issues = $issues | Where-Object { $_.Assignees -ne $null -and $_.Assignees.Count -gt 0 }
if(!$?) { exit 1 }
Write-Host "Found $($issues.Count) issues with assignees"
foreach ($issue in $issues) {
$assigneeLogins = $issue.Assignees | Select-Object -ExpandProperty Login
$assigneesStr = $assigneeLogins -join ", "
$reminderMessage = ""
$assigneeLogins | ForEach-Object {
$reminderMessage += "@$_ This is your friendly (automated) reminder!`n"
}
Write-Host "Sending reminder to $assigneesStr..."
gh issue comment $issue.number `
--body $reminderMessage `
-R $repository
if (!$?) {
Write-Warning "Failed to send reminder to $assignee"
continue
}
}
Write-Host "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment