Skip to content

Commit

Permalink
Initial drop.
Browse files Browse the repository at this point in the history
  • Loading branch information
at-wat committed Aug 7, 2017
0 parents commit fe4e4f6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# gh-pr-comment

## Usage

```
$ gh-pr-comment title comment
```

The script escapes special charactors for json encoding.

## Required environment variables

- ***TRAVIS\_REPO\_SLUG*** = user/repos
- ***TRAVIS\_PULL\_REQUEST*** = pull request number
- ***TRAVIS\_BOT\_GITHUB\_TOKEN*** = token with comment write permission

26 changes: 26 additions & 0 deletions gh-pr-comment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

function gh-pr-comment()
{
if [ $# -lt 2 ];
then
echo "usage: gh-pr-comment title comment" >&2
echo " env:" >&2
echo " - TRAVIS_REPO_SLUG : user/repos" >&2
echo " - TRAVIS_PULL_REQUEST : pull request number" >&2
echo " - TRAVIS_BOT_GITHUB_TOKEN : token with comment write permission" >&2
echo ' note: the script escapes special charactors for json encoding.' >&2

return
fi

if [ ${TRAVIS_PULL_REQUEST} != "false" ];
then
text=`echo "$2" | sed 's/\\\\/\\\\\\\\/g' | sed -n '1h;1!H;${x;s/\n/\\\\n/g;p;}' | sed 's/\"/\\\\"/g' | sed 's/\t/\\\\t/g' | sed 's/\//\\\\\//g'`
curl -vs -X POST -H 'Content-Type:application/json' -d "{\"body\":\"## $1\n\n$text\"}" \
https://api.github.com/repos/${TRAVIS_REPO_SLUG}/issues/${TRAVIS_PULL_REQUEST}/comments?access_token=${TRAVIS_BOT_GITHUB_TOKEN} 2> /dev/null
else
echo 'gh-pr-comment: TRAVIS_PULL_REQUEST is false.' >&2
fi
}

0 comments on commit fe4e4f6

Please sign in to comment.