Public Access
Post-merge / detect-type (push) Failing after 9s
Post-merge / validate-commit-msg (push) Has been skipped
Post-merge / release (push) Has been skipped
Post-merge / sync-wiki (push) Has been skipped
Post-merge / vikunja (push) Has been skipped
Post-merge / configure-repo (push) Has been skipped
Post-merge / badges (push) Failing after 25s
Port core modules (config, exceptions, i18n, api_clients, gitea_cli), 14 CI scripts, 6 dev tools, 5 molecule tools, CLI entry point, workflows, Makefile, tests (784 tests, 100% coverage), and documentation from GRM. The devx package is published to the Gitea PyPI registry and consumed by GRM, infra, and other oblachno-oss projects as a pip dependency. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
77 lines
3.2 KiB
Python
77 lines
3.2 KiB
Python
from __future__ import annotations
|
|
|
|
import subprocess
|
|
from pathlib import Path
|
|
from unittest.mock import patch
|
|
|
|
import pytest
|
|
from click import ClickException
|
|
from click.testing import CliRunner
|
|
|
|
import devx.ci.detect_release_commit as detect_release_commit
|
|
|
|
|
|
class TestGetCommitMessage:
|
|
def test_success(self) -> None:
|
|
mock_result = subprocess.CompletedProcess(args=[], returncode=0, stdout="feat: add feature\n", stderr="")
|
|
with patch("subprocess.run", return_value=mock_result):
|
|
assert detect_release_commit.get_commit_message() == "feat: add feature"
|
|
|
|
def test_failure(self) -> None:
|
|
mock_result = subprocess.CompletedProcess(args=[], returncode=1, stdout="", stderr="git error")
|
|
with patch("subprocess.run", return_value=mock_result):
|
|
with pytest.raises(ClickException, match="git log failed"):
|
|
detect_release_commit.get_commit_message()
|
|
|
|
|
|
class TestIsReleaseCommit:
|
|
def test_release_commit(self) -> None:
|
|
assert detect_release_commit.is_release_commit("release: v1.0.0 [skip ci]") is True
|
|
|
|
def test_release_commit_no_skip(self) -> None:
|
|
assert detect_release_commit.is_release_commit("release: v0.1.0") is True
|
|
|
|
def test_regular_commit(self) -> None:
|
|
assert detect_release_commit.is_release_commit("feat: add feature") is False
|
|
|
|
def test_empty(self) -> None:
|
|
assert detect_release_commit.is_release_commit("") is False
|
|
|
|
|
|
class TestWriteGithubOutput:
|
|
def test_write(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
|
gh_file = tmp_path / "output.txt"
|
|
monkeypatch.setenv("GITHUB_OUTPUT", str(gh_file))
|
|
detect_release_commit.write_github_output("is-release", "true")
|
|
with open(gh_file) as f:
|
|
assert f.read() == "is-release=true\n"
|
|
|
|
def test_no_env(self, monkeypatch: pytest.MonkeyPatch) -> None:
|
|
monkeypatch.delenv("GITHUB_OUTPUT", raising=False)
|
|
with pytest.raises(ClickException, match="GITHUB_OUTPUT"):
|
|
detect_release_commit.write_github_output("is-release", "true")
|
|
|
|
|
|
class TestMain:
|
|
def test_release_commit(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
|
gh_file = tmp_path / "output.txt"
|
|
monkeypatch.setenv("GITHUB_OUTPUT", str(gh_file))
|
|
with patch.object(detect_release_commit, "get_commit_message", return_value="release: v1.0.0 [skip ci]"):
|
|
runner = CliRunner()
|
|
result = runner.invoke(detect_release_commit.main, [])
|
|
assert result.exit_code == 0
|
|
assert "Release commit" in result.output
|
|
with open(gh_file) as f:
|
|
assert "is-release=true" in f.read()
|
|
|
|
def test_regular_commit(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
|
gh_file = tmp_path / "output.txt"
|
|
monkeypatch.setenv("GITHUB_OUTPUT", str(gh_file))
|
|
with patch.object(detect_release_commit, "get_commit_message", return_value="feat: add feature"):
|
|
runner = CliRunner()
|
|
result = runner.invoke(detect_release_commit.main, [])
|
|
assert result.exit_code == 0
|
|
assert "Regular merge commit" in result.output
|
|
with open(gh_file) as f:
|
|
assert "is-release=false" in f.read()
|