Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 1 | # This example uses Google APIs Client for Python, you can download it here: |
| 2 | # https://developers.google.com/api-client-library/python/ |
| 3 | |
| 4 | from __future__ import print_function |
| 5 | from __future__ import division |
| 6 | from __future__ import absolute_import |
| 7 | |
| 8 | import apiclient |
| 9 | |
| 10 | import httplib2 |
| 11 | |
| 12 | from oauth2client.file import Storage |
| 13 | |
| 14 | |
| 15 | DISCOVERY_URL = ( |
| 16 | 'https://monorail-staging.appspot.com/_ah/api/discovery/v1/apis/' |
| 17 | '{api}/{apiVersion}/rest') |
| 18 | |
| 19 | |
| 20 | # Get credentials to authorize http object |
| 21 | storage = Storage('Your-local-credential-file') |
| 22 | credentials = storage.get() |
| 23 | http = credentials.authorize(httplib2.Http()) |
| 24 | |
| 25 | # Create monorail client using Google APIs Client for Python |
| 26 | monorail = apiclient.discovery.build( |
| 27 | 'monorail', 'v1', |
| 28 | discoveryServiceUrl=DISCOVERY_URL, |
| 29 | http=http) |
| 30 | |
| 31 | # Create a chromium project issue |
| 32 | insert_response = monorail.issues().insert(projectId='chromium', body={ |
| 33 | 'summary': 'Strange grinding sound', |
| 34 | 'status': 'Untriaged', |
| 35 | 'cc': [{'name':'user1@example.org'}, {'name':'user2@example.org'}] |
| 36 | }).execute() |
| 37 | |
| 38 | new_issue_id = insert_response['id'] |
| 39 | |
| 40 | # Get all issues of chromium |
| 41 | list_response = monorail.issues().list(projectId='chromium').execute() |
| 42 | issues = list_response['items'] |
| 43 | total_issues = list_response['totalResults'] |