def edit_mr(data, source_project, target_project, commits):
editor = os.environ.get('EDITOR', 'nano')
title = data.get('title')
assignee = data.get('assignee')
description = data.get('description')
content = (
'Title:\n'
'{title}\n'
'Assignee:\n'
'{assignee}\n'
'Description:\n'
'\n'
'# You are creating a merge request:\n'
'#\t{outline}\n'
'#\n'
'# Next commits will be included in the merge request:\n'
'#\n'
'{commits}\n'
'#\n'
'# Empty title will cancel the merge request.'
).format(
title='{}\n'.format(title) if title else '',
assignee='{}\n'.format(assignee) if assignee else '',
description='{}\n'.format(description) if description else '',
outline=get_mr_outline(data, source_project, target_project),
commits=format_mr_commits(commits, prefix='#\t'),
)
with tempfile.NamedTemporaryFile() as tf:
tf.write(content.encode('utf-8'))
tf.flush()
res = subprocess.run([editor, tf.name])
tf.seek(0)
new_data = data.copy()
new_data.update(parse_mr_file(tf))
return new_data
评论列表
文章目录