• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2017 gRPC authors.
2#
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
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
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.
14
15import os
16import json
17import urllib2
18
19
20def comment_on_pr(text):
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()
38