Ejemplo n.º 1
0
def test_basic_style_fix():
    """Bug fix commit is correctly identified."""
    subject = "Fixed a bug"
    commit = Commit(commit_hash="aaaaaaa", subject=subject, author_date="1574340645", committer_date="1574340645")
    style = BasicStyle()
    commit_dict = style.parse_commit(commit)
    assert not commit_dict["is_major"]
    assert not commit_dict["is_minor"]
    assert commit_dict["is_patch"]
def test_angular_style_fix():
    subject = "fix: this is a bug fix"
    commit = Commit(hash="aaaaaaa",
                    subject=subject,
                    author_date="1574340645",
                    committer_date="1574340645")
    style = AngularStyle()
    commit_dict = style.parse_commit(commit)
    assert not commit_dict["is_major"]
    assert not commit_dict["is_minor"]
    assert commit_dict["is_patch"]
Ejemplo n.º 3
0
def test_basic_style_breaking_change():
    """Breaking change (singular) is correctly identified."""
    subject = "Added a new breaking feature"
    body = ["BREAKING CHANGE: there is a breaking feature in this code"]
    commit = Commit(
        commit_hash="aaaaaaa", subject=subject, body=body, author_date="1574340645", committer_date="1574340645"
    )
    style = BasicStyle()
    commit_dict = style.parse_commit(commit)
    assert commit_dict["is_major"]
    assert not commit_dict["is_minor"]
    assert not commit_dict["is_patch"]
Ejemplo n.º 4
0
def test_angular_style_feat():
    """Feature commit is correctly identified."""
    subject = "feat: this is a new feature"
    commit = Commit(commit_hash="aaaaaaa",
                    subject=subject,
                    author_date="1574340645",
                    committer_date="1574340645")
    style = AngularStyle()
    commit_dict = style.parse_commit(commit)
    assert not commit_dict["is_major"]
    assert commit_dict["is_minor"]
    assert not commit_dict["is_patch"]
def test_angular_style_breaking_change():
    subject = "feat: this is a new breaking feature"
    body = ["BREAKING CHANGE: there is a breaking feature in this code"]
    commit = Commit(hash="aaaaaaa",
                    subject=subject,
                    body=body,
                    author_date="1574340645",
                    committer_date="1574340645")
    style = AngularStyle()
    commit_dict = style.parse_commit(commit)
    assert commit_dict["is_major"]
    assert not commit_dict["is_minor"]
    assert not commit_dict["is_patch"]
def test_conventional_style_feat_with_scope():
    """Feature commit is correctly identified."""
    subject = "feat(scope): this is a new feature"
    commit = Commit(commit_hash="aaaaaaa",
                    subject=subject,
                    author_date="1574340645",
                    committer_date="1574340645")
    style = ConventionalCommitStyle()
    commit_dict = style.parse_commit(commit)
    assert commit_dict["type"] == "Features"
    assert commit_dict["scope"] == "scope"
    assert not commit_dict["is_major"]
    assert commit_dict["is_minor"]
    assert not commit_dict["is_patch"]
def test_conventional_style_fix():
    """Bug fix commit is correctly identified."""
    subject = "fix: this is a bug fix"
    commit = Commit(commit_hash="aaaaaaa",
                    subject=subject,
                    author_date="1574340645",
                    committer_date="1574340645")
    style = ConventionalCommitStyle()
    commit_dict = style.parse_commit(commit)
    assert commit_dict["type"] == "Bug Fixes"
    assert commit_dict["scope"] is None
    assert not commit_dict["is_major"]
    assert not commit_dict["is_minor"]
    assert commit_dict["is_patch"]
def test_conventional_style_breaking_change():
    """Breaking change (singular) is correctly identified."""
    subject = "feat: this is a new breaking feature"
    body = ["BREAKING CHANGE: there is a breaking feature in this code"]
    commit = Commit(commit_hash="aaaaaaa",
                    subject=subject,
                    body=body,
                    author_date="1574340645",
                    committer_date="1574340645")
    style = ConventionalCommitStyle()
    commit_dict = style.parse_commit(commit)
    assert commit_dict["type"] == "Features"
    assert commit_dict["scope"] is None
    assert commit_dict["is_major"]
    assert not commit_dict["is_minor"]
    assert not commit_dict["is_patch"]
def test_conventional_style_subject_breaking_change_with_scope(
):  # noqa: WPS118
    """Breaking change in the subject (!) with scope are correctly identified."""
    subject = "feat(scope)!: this is a new breaking feature"
    body = ["There is a breaking feature in this code"]
    commit = Commit(commit_hash="aaaaaaa",
                    subject=subject,
                    body=body,
                    author_date="1574340645",
                    committer_date="1574340645")
    style = ConventionalCommitStyle()
    commit_dict = style.parse_commit(commit)
    assert commit_dict["type"] == "Features"
    assert commit_dict["scope"] == "scope"
    assert commit_dict["is_major"]
    assert not commit_dict["is_minor"]
    assert not commit_dict["is_patch"]
Ejemplo n.º 10
0
    def parse_commits(self) -> List[Commit]:
        """Parse the output of 'git log' into a list of commits.

        Returns:
            The list of commits.
        """
        lines = self.raw_log.split("\n")
        size = len(lines) - 1  # don't count last blank line
        commits = []
        pos = 0
        while pos < size:
            commit = Commit(
                commit_hash=lines[pos],
                author_name=lines[pos + 1],
                author_email=lines[pos + 2],
                author_date=lines[pos + 3],
                committer_name=lines[pos + 4],
                committer_email=lines[pos + 5],
                committer_date=lines[pos + 6],
                refs=lines[pos + 7],
                subject=lines[pos + 8],
                body=[lines[pos + 9]],
            )

            # append body lines
            nbl_index = 10
            while lines[pos + nbl_index] != self.MARKER:
                commit.body.append(lines[pos + nbl_index])
                nbl_index += 1
            pos += nbl_index + 1

            # expand commit object with provider parsing
            if self.provider:
                commit.update_with_provider(self.provider)

            elif self.remote_url:
                # set the commit url based on remote_url (could be wrong)
                commit.url = self.remote_url + "/commit/" + commit.hash

            # expand commit object with style parsing
            if self.style:
                commit.update_with_style(self.style)

            commits.append(commit)

        return commits