3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

GitHubActionsで放置されたIssueをSlack通知してみた

Posted at

はじめに

気づかずに長期間Issueが放置されている経験は一度はあると思います。
最近GitHubActionsを触っており、せっかくなので放置されてるIssueを通知してくれるGitHubActionsを作成してみました。

概要

一定期間放置されてるIssueに「inactive」ラベルを付与し、そのラベルが付与されたIssueはSlack通知されるようになります。

使用するAciton

GitHubのMarketplaceに一定期間放置されているIssueやPRに対してラベルの付与やクローズなどが実行できる便利なActionがあるので使用します。
https://github.com/marketplace/actions/close-stale-issues

放置されたIssueへラベルを付与する

リポジトリ内で「.github/workflows/add-label.yaml」を作成します。

スクリーンショット 2023-05-23 23.15.26.png

add-label.yaml内に以下を記載します。

name: Add label to inactive issues
on:
  schedule:
    - cron: "0 0 * * *" # UTC表記 毎朝9時の実行

jobs:
  add-label:
    runs-on: ubuntu-latest
    steps:
      - name: add-label
        uses: actions/stale@v5
        with:
          repo-token: ${{ secrets.SAMPLE_TOKEN }}
          stale-issue-label: "inactive"
          days-before-issue-stale: 1
          days-before-issue-close: -1
          days-before-pr-stale: -1
          days-before-pr-close: -1

各パラメーターの説明は以下の通りです。

repo-token
Personal Access Tokenを発行し、secretsにSAMPLE_TOKEとして設定しています。

stale-issue-label
Issueがdays-before-issue-stale で設定した日数を超えてた場合、指定したラベルを付与できます。

days-before-issue-stale
Issueを放置してもいい日数を設定します。

days-before-issue-close
設定した日数を過ぎるとIssueをクローズできますが、今回はクローズしないので-1を設定します。

day-before-pr-stale
PRを放置してもいい日数を設定しますが、今回は不要なので-1を設定します。

days-before-pr-close
設定した日数を過ぎるとPRをクローズできますが、今回はクローズしないので-1を設定します。

実際にdays-before-issue-stale日数が経過するとIssueに「inactive」のラベルが付与されます。

スクリーンショット 2023-05-23 22.33.59.png

Slackへ通知する

追加でリポジトリ内で「.github/workflows/notify.yaml」を作成します。

スクリーンショット 2023-05-23 23.31.21.png

notify.yaml内に以下を記載します。

name: Slack notify
on:
  issues:
    types:
      - labeled # ラベル付与がトリガー
jobs:
  notify:
    if: github.event.label.name == 'inactive' # inactiveのラベルが付与された場合のみ実施
    runs-on: ubuntu-latest
    steps:
      - name: notify
        uses: tokorom/action-slack-incoming-webhook@main
        env:
          INCOMING_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
        with:
          text: Issueが長期間放置されてます。
          attachments: |
            [
              {
                "fields": [
                  {
                    "title": "Issue URL",
                    "value": "${{ github.event.issue.url }}"
                  }
                ]
              }
            ]

実際にIssueに「inactive」のラベルが付与されるとSlackへ通知されます。
今回はIssueのURLだけというシンプルな通知ですが、いろいろ工夫できそうです。

スクリーンショット 2023-05-24 0.17.49.png

おわりに

ほんの遊び心で作ってみましたが、便利なActionが色々とあるので実際の業務でも活用できそうです。
今回も閲覧ありがとうございました!

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?