File: set_github_status.py

package info (click to toggle)
grpc-java 1.26.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 11,852 kB
  • sloc: java: 146,813; cpp: 1,174; xml: 1,037; sh: 662; makefile: 40; python: 40
file content (64 lines) | stat: -rwxr-xr-x 2,009 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python3
#
# Copyright 2018 The gRPC Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import argparse
import json
import urllib.request, urllib.error, urllib.parse


def run():
  argp = argparse.ArgumentParser(description='Set status on pull request')

  argp.add_argument(
      '--sha1', type=str, help='SHA1 of the commit', required=True)
  argp.add_argument(
      '--state',
      type=str,
      choices=('error', 'failure', 'pending', 'success'),
      help='State to set',
      required=True)
  argp.add_argument(
      '--description', type=str, help='Status description', required=True)
  argp.add_argument('--context', type=str, help='Status context', required=True)
  argp.add_argument(
      '--oauth_file', type=str, help='File with OAuth token', required=True)

  args = argp.parse_args()
  sha1 = args.sha1
  state = args.state
  description = args.description
  context = args.context
  oauth_file = args.oauth_file

  with open(oauth_file, 'r') as oauth_file_reader:
    oauth_token = oauth_file_reader.read().replace('\n', '')

  req = urllib.request.Request(
      url='https://api.github.com/repos/grpc/grpc-java/statuses/%s' % sha1,
      data=json.dumps({
          'state': state,
          'description': description,
          'context': context,
      }),
      headers={
          'Authorization': 'token %s' % oauth_token,
          'Content-Type': 'application/json',
      })
  print(urllib.request.urlopen(req).read())


if __name__ == '__main__':
  run()