1
0

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 5 years have passed since last update.

Issueをランダムに取得するGitHub Actionsを作ってみた

1
Last updated at Posted at 2019-12-23

LGTMすると現場猫が「ヨシ!」してくれるGitHub Actionsをつくった + Tips - Qiitaを見てGitHub Actionsに興味が湧いたので、簡単なアクションを作成してみました。

今回作ったアクション

ラベルを引数にランダムなIssueのタイトルとURLを返します。
溜まるIssueを消費するためのIssueガチャとしてお使いください。

GitHub - matometaru/issue-gacha-action: Get a random issue action

毎週月曜に実行してスラックに通知するアクション例
.github/workflows/xxx.yml
name: Get a random issue and slack notification
on:
  schedule:
  # UTC
  - cron: '0 0 * * 1'
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Get random issue gacha
        uses: matometaru/issue-gacha-action@v1.0.0
        with:
          labels: "test"
        id: gacha
      - name: Slack Notification
        uses: rtCamp/action-slack-notify@master
        env:
          SLACK_CHANNEL: self
          SLACK_ICON: https://github.com/rtCamp.png?size=48
          SLACK_MESSAGE: 'Result: ${{ steps.gacha.outputs.htmlUrl }}'
          SLACK_TITLE: ${{ steps.gacha.outputs.title }}
          SLACK_USERNAME: rtCamp
          SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}

使ったテンプレート

GitHub - actions/javascript-action: Create a JavaScript Action with tests, linting, workflow, publishing, and versioning

Octkit(ライブラリ)

JavaScript用GitHub REST APIクライアントライブラリ

octkit/restのドキュメント

inputsで入力を受け取るコード例

action.yml
inputs:
  token:
    description: 'GitHub Token(scope: repo)'
    required: false
  label:
    description: 'issue labels `lable1,label2,label3`'
    required: false

index.js
const labels = core.getInput('labels');
const token = core.getInput('token');

outputsで変数を出力するコード例

action.yml
outputs:
  title:
    description: 'Issue title'
  htmlUrl:
    description: 'Issue html url'

index.js
core.setOutput('title', randomIssue.title);
core.setOutput('htmlUrl', randomIssue.html_url);

さいごに

labelsを受け取って、IssueのタイトルとURLを返すだけのアクションですが、アクションの作り方を理解するには十分でした。まだまだ便利な機能や、Marketplaceに素晴らしいアクションがあると思うので引き続き調査を続けたいと思います。

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?