from time import sleep
from common.workflow import MailSender
+from common.prerelease import get_tagname_from_prerelease_name
GIT_URL = 'ssh://%s@%s:%s' % (os.getenv('GERRIT_USERNAME'),
os.getenv('GERRIT_HOSTNAME'),
class OverwriteError(Exception): pass
class MergeError(Exception): pass
class SubmitError(Exception): pass
+class SubmitRequestError(Exception): pass
+
+def submit_request(project, branch, commit, tagname):
+ """
+ Submit Request
+ """
+ result = True
+ message = "Auto Sync SR Tag"
+ try:
+
+ tmpdir = tempfile.mkdtemp(prefix=os.getenv('WORKSPACE')+'/')
+ if not git.clone_gitproject(project, os.path.join(tmpdir, project)):
+ raise SubmitRequestError('Submit Request git update failed(%s)' % (project))
+
+ git_dir = os.path.join(tmpdir, project)
+ gitprj = git.Git(git_dir)
+
+ gitprj.set_branch(branch)
+ print 'set branch'
+ gitprj.checkout(commit)
+ print 'checkout'
+ gitprj.create_tag(tagname, message)
+ print 'create_tag'
+ gitprj.push_tag("origin", tagname)
+ print 'push'
+ except Exception as err:
+ result = False
+
+ return result
def submit_gerrit_change(gerritobj, gitprj, project, branch, commit):
result = True
email_to_members = target.get('notify') or []
GIT_PREFIX = target.get('fork') or []
UPSTREAM_BRANCH = "public_" + target.get('source_branch') or []
+ tagname = get_tagname_from_prerelease_name(requests.keys()[0])
request_projects = []
new_private_projects = []
merge_failures = []
merge_successs = []
submit_failures = []
+ submit_request_successs = []
+ submit_request_failures = []
private_projects = private_gerrit.ls_projects()
if ret == None:
raise UpstreamError('create %s branch failed(%s)' % (branch, private_project))
merge_successs.append((private_project, '%s -> %s' %(commit, commit)))
+
+ ret = submit_request(project=private_project, branch=branch, commit=commit, tagname=tagname)
+ if not ret:
+ raise SubmitRequestError('submit request failed(%s, %s)' % (private_project, commit))
+ submit_request_successs.append((private_project, commit, tagname))
+
elif is_mixed_git: ## Merge
if branch in private_gitprj.branch_contains(commit):
print 'already merge %s branch..' % (branch)
if not ret:
raise SubmitError('submit failed(%s, %s)' % (private_project, merge_commit))
merge_successs.append((private_project, '%s -> %s' %(commit, merge_commit)))
+
+ ret = submit_request(project=private_project, branch=branch, commit=merge_commit, tagname=tagname)
+ if not ret:
+ raise SubmitRequestError('submit request failed(%s, %s)' % (private_project, merge_commit))
+ submit_request_successs.append((private_project, merge_commit, tagname))
+
else: ## Overwrite branch
print '\n* Overwrite %s %s %s' % (commit, branch, private_project)
ret, overwrite_commit = private_gitprj.create_overwrite_commit(branch, commit)
raise SubmitError('submit failed(%s, %s)' % (private_project, overwrite_commit))
overwrite_successs.append((private_project, '%s -> %s' %(commit, overwrite_commit)))
+
+ ret = submit_request(project=private_project, branch=branch, commit=merge_commit, tagname=tagname)
+ if not ret:
+ raise SubmitRequestError('submit request failed(%s, %s)' % (private_project, merge_commit))
+ submit_request_successs.append((private_project, merge_commit, tagname))
+
except UpstreamError, exc:
upstream_failures.append((project, revision, exc))
print 'Error:', exc
except SubmitError, exc:
submit_failures.append((project, revision, exc))
print 'Error:', exc
+ except SubmitRequestError, exc:
+ submit_request_failures.append((project, revision, exc))
+ print 'Error:', exc
finally:
if upstream_git_dir and os.path.exists(upstream_git_dir):
shutil.rmtree(upstream_git_dir)
print '\n-----[Submit Failure List]--------------------------------'
print '\n'.join(str(item) for item in submit_failures)
+ if submit_request_successs:
+ print '\n-----[SR(Submit Request) Success List]---------------------------------'
+ print '\n'.join(str(item) for item in submit_request_successs)
+
+ if submit_request_failures:
+ print '\n-----[SR(Submit Request) Failure List]--------------------------------'
+ print '\n'.join(str(item) for item in submit_request_failures)
+
#### Send mail to maintainers
if True:
### Init MailSender ####
my_mail.add_message('\n-----[Submit Failure List]--------------------------------')
[my_mail.add_message(str(item)) for item in submit_failures]
+ if submit_request_successs:
+ my_mail.add_message('\n-----[SR(Submit Request) Success List]--------------------------------')
+ [my_mail.add_message(str(item)) for item in submit_request_successs]
+
+
+ if submit_request_failures:
+ my_mail.add_message('\n-----[SR(Submit Request) Failure List]--------------------------------')
+ [my_mail.add_message(str(item)) for item in submit_request_failures]
+
if new_private_projects or overwrite_alreadys or overwrite_successs or \
- upstream_failures or overwrite_failures or merge_failures or submit_failures or merge_successs:
+ upstream_failures or overwrite_failures or merge_failures or submit_failures or merge_successs or \
+ submit_request_successs or submit_request_failures:
# Send mail to maintainers
my_mail.send_mail()