From 8650da2864d29b025b70924457cede169688c7b6 Mon Sep 17 00:00:00 2001 From: Atsushi Watanabe Date: Thu, 22 Feb 2018 00:11:30 +0900 Subject: [PATCH] Use TRAVIS_PULL_REQUEST_SLUG instead of TRAVIS_REPO_SLUG (#11) --- README.md | 2 +- gh-pr-comment.sh | 8 ++++---- gh_pr_comment/comment.py | 14 +++++++------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 0c3ed910..2d2bd183 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/gh-pr-comment.sh b/gh-pr-comment.sh index bd70c0dc..1fea467c 100755 --- a/gh-pr-comment.sh +++ b/gh-pr-comment.sh @@ -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 @@ -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 diff --git a/gh_pr_comment/comment.py b/gh_pr_comment/comment.py index 0ad3556a..cfcc189a 100644 --- a/gh_pr_comment/comment.py +++ b/gh_pr_comment/comment.py @@ -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) @@ -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( @@ -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=' \