blob: 399c996d4db1f827327df5bd98408efb1095e6cc [file] [log] [blame]
Jan Tattermusch7897ae92017-06-07 22:57:36 +02001# Copyright 2017 gRPC authors.
Craig Tiller5431f902017-03-29 08:31:45 -07002#
Jan Tattermusch7897ae92017-06-07 22:57:36 +02003# 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 Tiller5431f902017-03-29 08:31:45 -07006#
Jan Tattermusch7897ae92017-06-07 22:57:36 +02007# http://www.apache.org/licenses/LICENSE-2.0
Craig Tiller5431f902017-03-29 08:31:45 -07008#
Jan Tattermusch7897ae92017-06-07 22:57:36 +02009# 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 Tiller5431f902017-03-29 08:31:45 -070014
15import os
Craig Tiller70abee22017-03-29 12:19:34 -070016import json
Craig Tiller5431f902017-03-29 08:31:45 -070017import urllib2
18
ncteisen05687c32017-12-11 16:54:47 -080019
Craig Tiller5431f902017-03-29 08:31:45 -070020def comment_on_pr(text):
ncteisen05687c32017-12-11 16:54:47 -080021 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()