Skip to content

Commit

Permalink
Use TRAVIS_PULL_REQUEST_SLUG instead of TRAVIS_REPO_SLUG (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
at-wat authored Feb 21, 2018
1 parent 35eeaea commit 8650da2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ $ pip install gh-pr-comment

## Required environment variables

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

Expand Down
8 changes: 4 additions & 4 deletions gh-pr-comment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ function gh-pr-comment()
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 " - TRAVIS_PULL_REQUEST_SLUG : owner/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
Expand All @@ -24,7 +24,7 @@ function gh-pr-comment()
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
https://api.github.com/repos/${TRAVIS_PULL_REQUEST_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
Expand Down
14 changes: 7 additions & 7 deletions gh_pr_comment/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ def post_main():
sys.stderr.write(
'env:\n')
sys.stderr.write(
'- TRAVIS_REPO_SLUG :'
+ ' user/repos\n')
'- TRAVIS_PULL_REQUEST_SLUG :'
+ ' owner/repos\n')
sys.stderr.write(
'- TRAVIS_PULL_REQUEST :'
'- TRAVIS_PULL_REQUEST :'
+ ' pull request number\n')
sys.stderr.write(
'- TRAVIS_BOT_GITHUB_TOKEN:'
'- TRAVIS_BOT_GITHUB_TOKEN :'
+ ' token with comment write permission\n')
sys.exit(1)

Expand All @@ -30,9 +30,9 @@ def post(title, contents):
sys.stderr.write(
'gh-pr-comment: TRAVIS_BOT_GITHUB_TOKEN is not set.\n')
sys.exit(1)
if 'TRAVIS_REPO_SLUG' not in os.environ:
if 'TRAVIS_PULL_REQUEST_SLUG' not in os.environ:
sys.stderr.write(
'gh-pr-comment: TRAVIS_REPO_SLUG is not set.\n')
'gh-pr-comment: TRAVIS_PULL_REQUEST_SLUG is not set.\n')
sys.exit(1)
if 'TRAVIS_PULL_REQUEST' not in os.environ:
sys.stderr.write(
Expand All @@ -45,7 +45,7 @@ def post(title, contents):
sys.exit(0)

url = 'https://api.github.com/repos/' \
+ os.environ['TRAVIS_REPO_SLUG'] \
+ os.environ['TRAVIS_PULL_REQUEST_SLUG'] \
+ '/issues/' \
+ os.environ['TRAVIS_PULL_REQUEST'] \
+ '/comments?access_token=' \
Expand Down

0 comments on commit 8650da2

Please sign in to comment.