Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 1 | # Copyright 2017 gRPC authors. |
Craig Tiller | 5431f90 | 2017-03-29 08:31:45 -0700 | [diff] [blame] | 2 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
Craig Tiller | 5431f90 | 2017-03-29 08:31:45 -0700 | [diff] [blame] | 6 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
Craig Tiller | 5431f90 | 2017-03-29 08:31:45 -0700 | [diff] [blame] | 8 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
Craig Tiller | 5431f90 | 2017-03-29 08:31:45 -0700 | [diff] [blame] | 14 | |
| 15 | import os |
Craig Tiller | 70abee2 | 2017-03-29 12:19:34 -0700 | [diff] [blame] | 16 | import json |
Craig Tiller | 5431f90 | 2017-03-29 08:31:45 -0700 | [diff] [blame] | 17 | import urllib2 |
| 18 | |
ncteisen | 05687c3 | 2017-12-11 16:54:47 -0800 | [diff] [blame] | 19 | |
Craig Tiller | 5431f90 | 2017-03-29 08:31:45 -0700 | [diff] [blame] | 20 | def comment_on_pr(text): |
ncteisen | 05687c3 | 2017-12-11 16:54:47 -0800 | [diff] [blame] | 21 | if 'JENKINS_OAUTH_TOKEN' not in os.environ: |
| 22 | print 'Missing JENKINS_OAUTH_TOKEN env var: not commenting' |
| 23 | return |
| 24 | if 'ghprbPullId' not in os.environ: |
| 25 | print 'Missing ghprbPullId env var: not commenting' |
| 26 | return |
| 27 | req = urllib2.Request( |
| 28 | url='https://api.github.com/repos/grpc/grpc/issues/%s/comments' % |
| 29 | os.environ['ghprbPullId'], |
| 30 | data=json.dumps({ |
| 31 | 'body': text |
| 32 | }), |
| 33 | headers={ |
| 34 | 'Authorization': 'token %s' % os.environ['JENKINS_OAUTH_TOKEN'], |
| 35 | 'Content-Type': 'application/json', |
| 36 | }) |
| 37 | print urllib2.urlopen(req).read() |