Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Client-side script to send local git changes to a tryserver. | 6 """Client-side script to send local git changes to a tryserver. |
| 7 | 7 |
| 8 It pushes the local feature branch to a private ref on googlesource | 8 It pushes the local feature branch to a private try-ref on the central repo |
| 9 and posts a description of the job to an appengine instance, where it will get | 9 and posts a description of the job to an appengine instance, where it will get |
| 10 picked up by the buildbot tryserver itself. | 10 picked up by the buildbot tryserver itself. |
| 11 """ | 11 """ |
| 12 | 12 |
| 13 from __future__ import print_function | 13 from __future__ import print_function |
| 14 | 14 |
| 15 import json | 15 import json |
| 16 import os | 16 import os |
| 17 import subprocess | 17 import subprocess |
| 18 import sys | 18 import sys |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 continue | 62 continue |
| 63 k, v = line.split(':', 1) | 63 k, v = line.split(':', 1) |
| 64 settings[k.strip()] = v.strip() | 64 settings[k.strip()] = v.strip() |
| 65 return settings | 65 return settings |
| 66 | 66 |
| 67 | 67 |
| 68 def PushBranch(): | 68 def PushBranch(): |
| 69 """Pushes the current local branch to a ref in the try repo. | 69 """Pushes the current local branch to a ref in the try repo. |
| 70 | 70 |
| 71 The try repo is either the remote called 'try', or 'origin' otherwise. | 71 The try repo is either the remote called 'try', or 'origin' otherwise. |
| 72 The ref is '/refs/try/<username>/<local branch>-<short hash>. | 72 The ref is '/refs/tryjobs/<username>/<local branch>-<short hash>. |
| 73 | 73 |
| 74 Returns the ref to which the local branch was pushed.""" | 74 Returns the ref to which the local branch was pushed.""" |
| 75 username = RunGit('config', '--get', 'user.email').split('@', 1)[0] | 75 username = RunGit('config', '--get', 'user.email').split('@', 1)[0] |
| 76 branch = RunGit('symbolic-ref', '--short', '-q', 'HEAD') | 76 branch = RunGit('symbolic-ref', '--short', '-q', 'HEAD') |
| 77 commit = RunGit('rev-parse', branch)[:8] | 77 commit = RunGit('rev-parse', branch)[:8] |
|
iannucci
2013/09/21 00:49:42
I would use the whole hash, I don't think the shor
agable
2013/09/21 00:54:51
I'll think on it some more. There's probably a bet
| |
| 78 remotes = RunGit('remote').splitlines() | 78 remotes = RunGit('remote').splitlines() |
| 79 if not all((username, branch, commit, remotes)): | 79 if not all((username, branch, commit, remotes)): |
| 80 DieWithError('Unable to get necessary git configuration.') | 80 DieWithError('Unable to get necessary git configuration.') |
| 81 | 81 |
| 82 remote = 'try' if 'try' in remotes else 'origin' | 82 remote = 'try' if 'try' in remotes else 'origin' |
| 83 ref = 'refs/try/%s/%s-%s' % (username, branch, commit) | 83 ref = 'refs/tryjobs/%s/%s-%s' % (username, branch, commit) |
| 84 | 84 |
| 85 RunGit('push', remote, '%s:%s' % (branch, ref)) | 85 RunGit('push', remote, '%s:%s' % (branch, ref)) |
| 86 return ref | 86 return ref |
| 87 | 87 |
| 88 | 88 |
| 89 def MakeJob(project, jobname, ref): | 89 def MakeJob(project, jobname, ref): |
| 90 """Creates a job description blob.""" | 90 """Creates a job description blob.""" |
| 91 email = RunGit('config', '--get', 'user.email') | 91 email = RunGit('config', '--get', 'user.email') |
| 92 repository = RunGit('config', '--get', 'remote.origin.url') | 92 repository = RunGit('config', '--get', 'remote.origin.url') |
| 93 job = { | 93 job = { |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 115 conn = urllib.urlopen(url, data) | 115 conn = urllib.urlopen(url, data) |
| 116 except IOError as e: | 116 except IOError as e: |
| 117 DieWithError(e) | 117 DieWithError(e) |
| 118 response = conn.getcode() | 118 response = conn.getcode() |
| 119 if response != 200: | 119 if response != 200: |
| 120 DieWithError('Failed to POST. Got: %d' % response) | 120 DieWithError('Failed to POST. Got: %d' % response) |
| 121 | 121 |
| 122 | 122 |
| 123 def Main(_argv): | 123 def Main(_argv): |
| 124 """Main entry point.""" | 124 """Main entry point.""" |
| 125 # Sanity check. | |
| 125 EnsureInGitRepo() | 126 EnsureInGitRepo() |
| 126 | 127 |
| 128 # Get some settings. | |
| 127 settings = GetCodeReviewSettings() | 129 settings = GetCodeReviewSettings() |
| 128 server = settings.get('TRYSERVER_HTTP_HOST') | 130 server = settings.get('TRYSERVER_HTTP_HOST') |
| 129 project = settings.get('TRYSERVER_PROJECT') | 131 project = settings.get('TRYSERVER_PROJECT') |
| 130 jobnames = settings.get('TRYSERVER_JOB_NAME') | 132 jobnames = settings.get('TRYSERVER_JOB_NAME') |
| 131 if not all((server, project, jobnames)): | 133 if not all((server, project, jobnames)): |
| 132 DieWithError('Missing configuration in codereview.settings.') | 134 DieWithError('Missing configuration in codereview.settings.') |
| 133 | 135 |
| 136 # Do the heavy lifting. | |
| 134 ref = PushBranch() | 137 ref = PushBranch() |
| 135 for jobname in jobnames.split(','): | 138 for jobname in jobnames.split(','): |
| 136 job = MakeJob(project, jobname, ref) | 139 job = MakeJob(project, jobname, ref) |
| 137 PostJob(server, project, job) | 140 PostJob(server, project, job) |
| 138 | 141 |
| 139 | 142 |
| 140 if __name__ == '__main__': | 143 if __name__ == '__main__': |
| 141 sys.exit(Main(sys.argv)) | 144 sys.exit(Main(sys.argv)) |
| OLD | NEW |