class RevisionError(Exception): pass
class UpstreamError(Exception): pass
class OverwriteError(Exception): pass
+class MergeError(Exception): pass
+class SubmitError(Exception): pass
class MailSender(object):
email_title = ''
os.getenv('NOREPLY_EMAIL_SENDER'), \
self.email_to)
+def submit_gerrit_change(gerritobj, gitprj, project, branch, commit):
+ result = True
+ gerritobj.review(commit=commit, project=project, message='Submitted by system administrator', verified=1, codereview=2, submit=True)
+ gerrit_query = 'project:%s branch:%s commit:%s status:merged' % (project, branch, commit)
+ ret = gerritobj.query(gerrit_query)
+ if not ret:
+ print 'Warning: Submit failed, try direct push...'
+ ret = gitprj.push('-q', 'origin', '%s:refs/heads/%s' % (commit, branch))
+ if ret == None:
+ result = False
+ return result
+
def conv_rev2commit(gitprj, git_dir, revision):
commit = ''
try:
Update sync for git sync.
"""
+ for item in ('target', 'branch', 'notify', 'fork', 'source_branch'):
+ if item not in target:
+ print 'Error: target doesn\'t contain %s' % item
+ return -1
+
target_project = target.get('target') or []
- target_fork_prefix = target.get('fork') or []
branch = target.get('branch') or [] # tizen_4.0_mcd_z4
- source_branch = target.get('source_branch') or [] # public_tizen
email_to_members = target.get('notify') or []
+ GIT_PREFIX = target.get('fork') or []
+ UPSTREAM_BRANCH = "public_" + target.get('source_branch') or []
- GIT_PREFIX = target_fork_prefix
- UPSTREAM_BRANCH = "public_" + source_branch
- overwrite_branches = [branch]
request_projects = []
new_private_projects = []
overwrite_alreadys = []
overwrite_successs = []
upstream_failures = []
overwrite_failures = []
+ merge_failures = []
+ merge_successs = []
+ submit_failures = []
private_projects = private_gerrit.ls_projects()
revision = item['cid']
submitter = item['submitter']
git_tag = item['git_tag']
+ deleted = item['deleted']
- if project.startswith(HIGHLIGHT):
+ if project.startswith(HIGHLIGHT) or deleted:
continue
else:
project = project[1:]
if ret == None:
raise UpstreamError('git push failed(%s)' % (private_project))
- print '\n* Overwrite Branches:', overwrite_branches
- if not overwrite_branches:
- print 'not found overwrite branch information of %s, skip overwrite..' % (private_project)
- continue
-
print '\n* Update private git repo %s' % (private_project)
if not git.clone_gitproject(private_project, os.path.join(tmpdir, private_project)):
raise OverwriteError('private git update failed(%s)' % (private_project))
if retcode != 0:
raise RevisionError('error')
- for branch in overwrite_branches:
+ if True: ## Merge
+ if branch in private_gitprj.branch_contains(commit):
+ print 'already merge %s branch..' % (branch)
+ continue
+
+ print '\n* Merge %s %s %s' % (commit, branch, private_project)
+ #retcode = private_gitprj.checkout('origin/%s' % branch, '--')[0]
+ private_gitprj.checkout('origin/%s' % branch)
+ #if retcode != 0:
+ # raise MergeError('not found %s branch(%s)' % (branch, private_project))
+
+ retcode = private_gitprj._exec_git('merge', ['--no-ff', commit])[0]
+ if retcode != 0:
+ raise MergeError('merge %s branch failed(%s, %s)' % (branch, private_project, commit))
+
+ retcode, merge_commit = private_gitprj._exec_git('log', ['-n1', '--pretty=%H', 'HEAD', '--'])
+ if retcode != 0:
+ raise MergeError('not found merge commit(%s, %s)' % (branch, private_project))
+
+ #print '\n* Commit --amend --no-edit.. '
+ ret = private_gitprj._exec_git('commit', ['--amend', '--no-edit'])
+ if ret == None:
+ raise OverwriteError('git commit --amend --no-edit failed(%s)' % (private_project))
+
+ ret, outs = private_gitprj._exec_git('log', ['-n1', '--pretty=%H'])
+ if ret == None:
+ raise OverwriteError('git log -n1 --pretty=%H failed(%s)' % (private_project))
+ #change overwrite_commit
+ merge_commit = outs.strip()
+
+ print '\n* Push %s %s %s' % (merge_commit, branch, private_project)
+ ret = private_gitprj._exec_git('push',['-q', 'origin', '%s:refs/for/%s' % (merge_commit, branch)])
+ if ret == None:
+ raise MergeError('git push failed(%s, %s)' % (private_project, merge_commit))
+
+ print '\n* Submit', merge_commit
+ ret = submit_gerrit_change(gerritobj=private_gerrit, gitprj=private_gitprj, \
+ project=private_project, \
+ branch=branch, commit=merge_commit)
+ if not ret:
+ raise SubmitError('submit failed(%s, %s)' % (private_project, merge_commit))
+ merge_successs.append((private_project, '%s -> %s' %(commit, merge_commit)))
+ else: ## Overwrite branch
print '\n* Overwrite %s %s %s' % (commit, branch, private_project)
ret, overwrite_commit = private_gitprj.create_overwrite_commit(branch, commit)
if not ret:
if ret == None:
raise OverwriteError('git push failed(%s)' % (private_project))
print '\n* Submit', overwrite_commit
- private_gerrit.review(commit = overwrite_commit, project =private_project, \
- message = 'Submitted by system administrator', verified = 1, \
- codereview = 2, submit = True)
+ ret = submit_gerrit_change(gerritobj=private_gerrit, gitprj=private_gitprj, \
+ project=private_project, \
+ branch=branch, commit=overwrite_commit)
+ if not ret:
+ raise SubmitError('submit failed(%s, %s)' % (private_project, overwrite_commit))
+
overwrite_successs.append((private_project, '%s -> %s' %(commit, overwrite_commit)))
except UpstreamError, exc:
upstream_failures.append((project, revision, exc))
except OverwriteError, exc:
overwrite_failures.append((project, revision, exc))
print 'Error:', exc
+ except MergeError, exc:
+ merge_failures.append((project, revision, exc))
+ print 'Error:', exc
+ except SubmitError, exc:
+ submit_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-----[Overwrite into %s Branch Failure List]----------'%(branch)
print '\n'.join(str(item) for item in overwrite_failures)
+ if merge_failures:
+ print '\n-----[Merge Failure List]---------------------------------'
+ print '\n'.join(str(item) for item in merge_failures)
+
+ if merge_successs:
+ print '\n-----[Merge Success List]---------------------------------'
+ print '\n'.join(str(item) for item in merge_successs)
+
+ if submit_failures:
+ print '\n-----[Submit Failure List]--------------------------------'
+ print '\n'.join(str(item) for item in submit_failures)
+
#### Send mail to maintainers
if True:
### Init MailSender ####
my_mail = MailSender()
my_mail.add_title('[Auto Git-Sync] Target Project:%s Branch:%s' %(target_project, branch))
- my_mail.add_message('Hello\n A Build System infrom you about Auto Git-Sync results\n\n')
- my_mail.add_message('Public Source Snapshot: %s Upstream Branch: %s\nTarget Project: %s\nTarget Branch: %s' \
+ my_mail.add_message('Hello\n A Build System inform you about Auto Git-Sync results\n\n')
+ my_mail.add_message('Public Source Snapshot: %s \nUpstream Branch: %s\nTarget Project: %s\nTarget Branch: %s' \
%(request_snapshot, UPSTREAM_BRANCH, target_project, branch))
print 'members:',email_to_members
[my_mail.add_message(str(item)) for item in new_private_projects]
if overwrite_alreadys:
- my_mail.add_message('\n----[ Already Overwrite into %s Branch List]-----------'%(branch))
+ my_mail.add_message('\n----[Already Overwrite into %s Branch List]-----------'%(branch))
[my_mail.add_message(str(item)) for item in overwrite_alreadys]
if overwrite_successs:
my_mail.add_message('\n-----[Overwrite into %s Branch Failure List]----------'%(branch))
[my_mail.add_message(str(item)) for item in overwrite_failures]
- # Send mail to maintainers
- my_mail.send_mail()
+ if merge_failures:
+ my_mail.add_message('\n-----[Merge Failure List]---------------------------------')
+ [my_mail.add_message(str(item)) for item in merge_failures]
+
+ if merge_successs:
+ my_mail.add_message('\n-----[Merge Success List]---------------------------------')
+ [my_mail.add_message(str(item)) for item in merge_successs]
+
+ if submit_failures:
+ my_mail.add_message('\n-----[Submit Failure List]--------------------------------')
+ [my_mail.add_message(str(item)) for item in submit_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:
+ # Send mail to maintainers
+ my_mail.send_mail()
def main():
"""
tmpdir = tempfile.mkdtemp(prefix=os.getenv('WORKSPACE')+'/')
update_sync_for_git_sync(tmpdir, private_gerrit, target, content['requests'][0], content['snapshot'])
else:
- print '%s project : git-sync option is not enabled..' %(target.get('target'))
+ print 'obs_dest_prj: %s project : git-sync option is not enabled..' %(target.get('target'))
if __name__ == '__main__':
sys.exit(main())