Commit 8e6e1e69 authored by smut@google.com's avatar smut@google.com

Add get subcommand to buildbucket.py

BUG=493885

Review URL: https://codereview.chromium.org/1284453002

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@296246 0039d316-1c4b-4281-b951-d872f2087c98
parent 41a9ce45
...@@ -27,7 +27,7 @@ import auth ...@@ -27,7 +27,7 @@ import auth
BUILDBUCKET_URL = 'https://cr-buildbucket.appspot.com' BUILDBUCKET_URL = 'https://cr-buildbucket.appspot.com'
PUT_BUILD_URL = urlparse.urljoin( BUILDBUCKET_API_URL = urlparse.urljoin(
BUILDBUCKET_URL, BUILDBUCKET_URL,
'_ah/api/buildbucket/v1/builds', '_ah/api/buildbucket/v1/builds',
) )
...@@ -41,6 +41,12 @@ def main(argv): ...@@ -41,6 +41,12 @@ def main(argv):
action='store_true', action='store_true',
) )
subparsers = parser.add_subparsers(dest='command') subparsers = parser.add_subparsers(dest='command')
get_parser = subparsers.add_parser('get')
get_parser.add_argument(
'--id',
help='The ID of the build to get the status of.',
required=True,
)
put_parser = subparsers.add_parser('put') put_parser = subparsers.add_parser('put')
put_parser.add_argument( put_parser.add_argument(
'-b', '-b',
...@@ -68,9 +74,13 @@ def main(argv): ...@@ -68,9 +74,13 @@ def main(argv):
help='A file to load a JSON dict of properties from.', help='A file to load a JSON dict of properties from.',
) )
args = parser.parse_args() args = parser.parse_args()
# TODO(smut): When more commands are implemented, refactor this.
assert args.command == 'put'
body = None
if args.command == 'get':
method = 'GET'
url = '%s/%s' % (BUILDBUCKET_API_URL, args.id)
elif args.command == 'put':
changes = [] changes = []
if args.changes: if args.changes:
try: try:
...@@ -89,6 +99,17 @@ def main(argv): ...@@ -89,6 +99,17 @@ def main(argv):
sys.stderr.write('%s contained invalid JSON dict.\n' % args.properties) sys.stderr.write('%s contained invalid JSON dict.\n' % args.properties)
raise raise
body = json.dumps({
'bucket': args.bucket,
'parameters_json': json.dumps({
'builder_name': args.builder_name,
'changes': changes,
'properties': properties,
}),
})
method = 'PUT'
url = BUILDBUCKET_API_URL
authenticator = auth.get_authenticator_for_host( authenticator = auth.get_authenticator_for_host(
BUILDBUCKET_URL, BUILDBUCKET_URL,
auth.make_auth_config(use_oauth2=True), auth.make_auth_config(use_oauth2=True),
...@@ -96,16 +117,9 @@ def main(argv): ...@@ -96,16 +117,9 @@ def main(argv):
http = authenticator.authorize(httplib2.Http()) http = authenticator.authorize(httplib2.Http())
http.force_exception_to_status_code = True http.force_exception_to_status_code = True
response, content = http.request( response, content = http.request(
PUT_BUILD_URL, url,
'PUT', method,
body=json.dumps({ body=body,
'bucket': args.bucket,
'parameters_json': json.dumps({
'builder_name': args.builder_name,
'changes': changes,
'properties': properties,
}),
}),
headers={'Content-Type': 'application/json'}, headers={'Content-Type': 'application/json'},
) )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment