misc: use config_writer as a context manager
This commit is contained in:
parent
1e8f06bcd0
commit
08676d5533
|
@ -67,17 +67,15 @@ def get_redmine_api():
|
|||
return redmine
|
||||
|
||||
|
||||
def set_redmine(section, option, value):
|
||||
repo = get_repo()
|
||||
config_writer = repo.config_writer()
|
||||
if not config_writer.has_section(section):
|
||||
config_writer.add_section(section)
|
||||
config_writer.set(section, option, value)
|
||||
config_writer.write()
|
||||
def set_redmine(repo, section, option, value):
|
||||
with repo.config_writer() as config_writer:
|
||||
if not config_writer.has_section(section):
|
||||
config_writer.add_section(section)
|
||||
config_writer.set(section, option, value)
|
||||
|
||||
|
||||
def set_branch_option(branch, option, value):
|
||||
set_redmine('branch "%s"' % branch.name, option, value)
|
||||
def set_branch_option(repo, branch, option, value):
|
||||
set_redmine(repo, 'branch "%s"' % branch.name, option, value)
|
||||
|
||||
|
||||
def get_issue(issue_number=None):
|
||||
|
@ -214,8 +212,8 @@ def take(issue_number, reference):
|
|||
default=True, abort=True)
|
||||
branch_name = click.prompt('Branch name', default=default_branch_name)
|
||||
branch = repo.create_head(branch_name, commit=reference or 'origin/master')
|
||||
set_branch_option(branch, 'merge', 'refs/heads/master')
|
||||
set_branch_option(branch, 'remote', '.')
|
||||
set_branch_option(repo, branch, 'merge', 'refs/heads/main')
|
||||
set_branch_option(repo, branch, 'remote', '.')
|
||||
if repo.head.reference == branch:
|
||||
click.echo('Already on branch %s' % branch_name)
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue