LoginSignup
3
4

More than 5 years have passed since last update.

プルリクにcurlでコメントする

Last updated at Posted at 2017-01-09

なぜそんな

CIサーバーから、GitHubのプルリクにコメントを入れたい。
パイプで渡すと、良き具合に投じてくれるとベスト。

現物

ghpr-comment.sh
#!/bin/bash -e
# how to use:
#   export GITHUB_OAUTH_KEY=....
#   export PR_REPONAME=....
#   export PR_NUMBER=....
#   echo "HELLO WORLD" | ./ghpr-comment.sh
#
# BODY from stdin
BODY=$(cat - | perl -ne 'chomp; s/\\/\\\\/g; s/"/\\"/g; print $_ ."\\n"')
curl -v -X POST \
  -H "Content-type: application/json" -H "Accept: application/json" \
  -u ${GITHUB_OAUTH_KEY}:x-oauth-basic \
  -d "{ \"body\": \"${BODY}\" }" \
  https://api.github.com/repos/uluru/${PR_REPONAME}/issues/${PR_NUMBER}/comments

インストール

置いて +x するだけ

wget https://gist.githubusercontent.com/sasasin/1a1b7534dfe2f6246378615c80ab720b/raw/3b03f25456ce1d557613671c12bb2be4dae5f0f0/ghpr-comment.sh
chmod +x ghpr-comment.sh

使い方

export GITHUB_OAUTH_KEY=....
export PR_REPONAME=....
export PR_NUMBER=....
echo "HELLO WORLD" | ./ghpr-comment.sh

3.jpg

パイプ越しに何でも渡せる。

cat /path/to/bigfile.txt \
| grep ... \
| awk .... \
| cowsay \
| ./ghpr-comment.sh
3
4
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
4