Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to use the git global user.name for maintainer-name #968

Merged
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 25 additions & 18 deletions ros2pkg/ros2pkg/verb/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def add_arguments(self, parser, cli_name):
'--maintainer-email',
help='email address of the maintainer of this package'),
parser.add_argument(
'--maintainer-name', default=getpass.getuser(),
'--maintainer-name',
help='name of the maintainer of this package'),
parser.add_argument(
'--node-name',
Expand All @@ -89,6 +89,21 @@ def add_arguments(self, parser, cli_name):
help='name of the empty library')

def main(self, *, args):

def get_git_config(key: str) -> str | None:
# retrieve a value from git config
git = shutil.which('git')
if git is not None:
result = subprocess.run(
[git, 'config', key],
stdout=subprocess.PIPE,
text=True
)
value = result.stdout.strip()
if value:
return value
return None

available_licenses = {}
for shortname, entry in ament_copyright.get_licenses().items():
available_licenses[entry.spdx] = entry.license_files
Expand All @@ -97,23 +112,15 @@ def main(self, *, args):
print('Supported licenses:\n%s' % ('\n'.join(available_licenses)))
sys.exit(0)

maintainer = Person(args.maintainer_name)

if args.maintainer_email:
maintainer.email = args.maintainer_email
else:
# try getting the email from the global git config
git = shutil.which('git')
if git is not None:
p = subprocess.Popen(
[git, 'config', 'user.email'],
stdout=subprocess.PIPE)
resp = p.communicate()
email = resp[0].decode().rstrip()
if email:
maintainer.email = email
if not maintainer.email:
maintainer.email = maintainer.name + '@todo.todo'
maintainer_name: str = (
args.maintainer_name
or get_git_config('user.name')
or getpass.getuser())
maintainer = Person(maintainer_name)
maintainer.email = (
args.maintainer_email
or get_git_config('user.email')
or f"{maintainer.name.replace(' ', '')}@todo.todo")

node_name = None
library_name = None
Expand Down