Tbpgr Blog

Employee Experience Engineer tbpgr(てぃーびー) のブログ

GitHubのIssueテンプレートを生成する isstempl gem を作った

f:id:tbpg:20150928224600j:plain

GitHubのIssueテンプレートを生成する isstempl gem を作りました。

経緯

GitHubのIssueは、URLのクエリーストリングを利用することで
テンプレート化できます。詳しくは下記を参照。

qiita.com

仕様

URLは下記のように構成される。

https://github.com/<account>/<repository>?title=<title>&body=<body>&labels=<label>

各項目をRubyDSLから設定可能にします。
title,bodyについては、URL文字列として内部でエスケープを行います。

DSL

name value example memo
account GitHubのユーザーアカウント tbpgr --
repository リポジトリ issue_test --
title Issueのタイトル ぬるぽがでてるよ 処理中にURLエンコードされる
body Issueの本文 ガッ 処理中にURLエンコードされる
labels IssueのLabels bug 未定義の場合は設定されない
bug
duplicate
enhancement
help wanted
invalid
question
wontfix
独自定義のLabel

Commands

command description
init DSLテンプレートの生成
generate URLの生成

試行

インストール

$ gem install isstempl
$ isstempl
Commands:
  isstempl generate        # Generate GitHub Issue template.
  isstempl help [COMMAND]  # Describe available commands or one specific command
  isstempl init            # generate Isstempl
  isstempl version         # version

Options:
  -h, [--help]     # help message.
      [--version]  # version

テンプレートの生成

$ isstempl init
$ cat Isstempl
# encoding: utf-8

# GitHub Account
# account is required
# account allow only String
# account's default value => ""
account ""

# GitHub Repository
# repository is required
# repository allow only String
# repository's default value => ""
repository ""

# Issue Title
# title is required
# title allow only String
# title's default value => ""
title ""

# Issue Body
# body is required
# body allow only String
# body's default value => ""
body ""

# Issue Labels
# labels is required
# labels allow only String
# labels => bug / duplicate / enhancement / help wanted / invalid / question / wontfix / or user defined Label
# labels's default value => ""
labels ""

テンプレートの編集

# encoding: utf-8

# GitHub Account
# account is required
# account allow only String
# account's default value => ""
account "tbpgr"

# GitHub Repository
# repository is required
# repository allow only String
# repository's default value => ""
repository "waffle_io_test"

# Issue Title
# title is required
# title allow only String
# title's default value => ""
title "Issueタイトル"

# Issue Body
# body is required
# body allow only String
# body's default value => ""
body <<-EOS
## list1
テスト
## list2
テスト
## list3
テスト
EOS

# Issue Labels
# labels is required
# labels allow only String
# labels => bug / duplicate / enhancement / help wanted / invalid / question / wontfix / or user defined Label
# labels's default value => ""
labels "bug"

URLの生成

$ isstempl generate
https://github.com/tbpgr/waffle_io_test/issues/new?title=Issue%E3%82%BF%E3%82%A4%E3%83%88%E3%83%AB&body=%23%23%20list1%0A%E3%83%86%E3%82%B9%E3%83%88%0A%23%23%20list2%0A%E3%83%86%E3%82%B9%E3%83%88%0A%23%23%20list3%0A%E3%83%86%E3%82%B9%E3%83%88%0A&labels=bug

生成したURLでIssueテンプレートを開いてみる

f:id:tbpg:20150928224621p:plain

関連情報