def set_committer_author(repo, committer, author): # If either committer or author is supplied they will be cross used if committer is None and author is not None: print("Supplied author will also be used as the committer.") committer = author if author is None and committer is not None: print("Supplied committer will also be used as the author.") author = committer # If no committer/author has been supplied but user configuration already # exists in git config we can exit and use the existing config as-is. if committer is None and author is None: if git_user_config_is_set(repo): return # Set defaults if no committer/author has been supplied if committer is None and author is None: committer = DEFAULT_COMMITTER author = DEFAULT_AUTHOR # Set git environment. This will not persist after the action completes. committer_name, committer_email = cmn.parse_display_name_email(committer) author_name, author_email = cmn.parse_display_name_email(author) repo.git.update_environment( GIT_COMMITTER_NAME=committer_name, GIT_COMMITTER_EMAIL=committer_email, GIT_AUTHOR_NAME=author_name, GIT_AUTHOR_EMAIL=author_email, ) print( f"Configured git committer as '{committer_name} <{committer_email}>'") print(f"Configured git author as '{author_name} <{author_email}>'")
def test_parse_display_name_email_success(): name, email = cmn.parse_display_name_email("abc def <*****@*****.**>") assert name == "abc def" assert email == "*****@*****.**" name, email = cmn.parse_display_name_email( "github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>" ) assert name == "github-actions[bot]" assert email == "41898282+github-actions[bot]@users.noreply.github.com"
def test_parse_display_name_email_failure(): display_name_email = "*****@*****.**" with pytest.raises(ValueError) as e_info: cmn.parse_display_name_email(display_name_email) assert ( e_info.value.args[0] == f"The format of '{display_name_email}' is not a valid email address with display name" ) display_name_email = " < >" with pytest.raises(ValueError) as e_info: cmn.parse_display_name_email(display_name_email) assert ( e_info.value.args[0] == f"The format of '{display_name_email}' is not a valid email address with display name" )