Skip to content

Commit

Permalink
feat: automatically calculate GitHub dependency name when not provided (
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Oct 2, 2024
1 parent 2dae973 commit c07eb07
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/ape_pm/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,16 @@ class GithubDependency(DependencyAPI):

@model_validator(mode="before")
@classmethod
def branch_to_ref(cls, model):
def _validate_model(cls, model):
# branch -> ref
if "branch" in model and "ref" not in model:
# Handle branch as an alias.
model["ref"] = model.pop("branch")

if "name" not in model and "github" in model:
# Calculate a default name.
model["name"] = model["github"].split("/")[-1].lower()

return model

@model_validator(mode="after")
Expand Down
9 changes: 9 additions & 0 deletions tests/functional/test_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,15 @@ def test_ref_or_version_is_required(self):
with pytest.raises(ValidationError, match=expected):
_ = GithubDependency(name="foo", github="asdf")

def test_name_from_github(self):
"""
When not given a name, it is derived from the github suffix.
"""
dependency = GithubDependency( # type: ignore
github="ApeWorX/ApeNotAThing", version="3.0.0"
)
assert dependency.name == "apenotathing"

def test_fetch_given_version(self, mock_client):
dependency = GithubDependency(
github="ApeWorX/ApeNotAThing", version="3.0.0", name="apetestdep"
Expand Down

0 comments on commit c07eb07

Please sign in to comment.