def _get_commits(self): # Get commit message from file (--commit-msg-file) if self.commit_msg_file: with open(self.commit_msg_file, "r", encoding="utf-8") as commit_file: commit_title = commit_file.readline() commit_body = commit_file.read() return [git.GitCommit(rev="", title=commit_title, body=commit_body)] elif self.commit_msg: return [git.GitCommit(rev="", title="", body=self.commit_msg)] # Get commit messages from git log (--rev-range) return git.get_commits(end=self.rev_range)
def test_git_object_eq(): git_commit = git.GitCommit(rev="sha1-code", title="this is title", body="this is body") git_tag = git.GitTag(rev="sha1-code", name="0.0.1", date="2020-01-21") assert git_commit == git_tag assert git_commit != "sha1-code"
def _get_commits(self): # Get commit message from file (--commit-msg-file) if self.commit_msg_file is not None: # Enter this branch if commit_msg_file is "". with open(self.commit_msg_file, "r", encoding="utf-8") as commit_file: msg = commit_file.read() msg = self._filter_comments(msg) msg = msg.lstrip("\n") commit_title = msg.split("\n")[0] commit_body = "\n".join(msg.split("\n")[1:]) return [git.GitCommit(rev="", title=commit_title, body=commit_body)] elif self.commit_msg is not None: # Enter this branch if commit_msg is "". self.commit_msg = self._filter_comments(self.commit_msg) return [git.GitCommit(rev="", title="", body=self.commit_msg)] # Get commit messages from git log (--rev-range) return git.get_commits(end=self.rev_range)
def gitcommits() -> list: commits = [ git.GitCommit( commit["rev"], commit["title"], commit["body"], commit["author"], commit["author_email"], ) for commit in COMMITS_DATA ] return commits
def _build_fake_git_commits(commit_msgs: List[str]) -> List[git.GitCommit]: return [git.GitCommit("test_rev", commit_msg) for commit_msg in commit_msgs]
def test_git_message_with_empty_body(): commit_title = "Some Title" commit = git.GitCommit("test_rev", "Some Title", body="") assert commit.message == commit_title