Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add jfrog builds and tests #187

Merged
merged 10 commits into from
Sep 19, 2024
2 changes: 2 additions & 0 deletions pyartifactory/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from pyartifactory.models.auth import AccessTokenModel
from pyartifactory.objects.artifact import ArtifactoryArtifact
from pyartifactory.objects.artifactory import Artifactory
from pyartifactory.objects.build import ArtifactoryBuild
from pyartifactory.objects.group import ArtifactoryGroup
from pyartifactory.objects.permission import ArtifactoryPermission
from pyartifactory.objects.repository import ArtifactoryRepository
Expand All @@ -24,6 +25,7 @@
"ArtifactoryRepository",
"ArtifactorySecurity",
"ArtifactoryUser",
"ArtifactoryBuild",
]

with contextlib.suppress(PackageNotFoundError):
Expand Down
15 changes: 15 additions & 0 deletions pyartifactory/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,18 @@ class PropertyNotFoundError(ArtifactoryError):

class InvalidTokenDataError(ArtifactoryError):
"""The token contains invalid data."""


class BuildNotFoundError(ArtifactoryError):
"""Requested build were not found"""


class ArtifactoryBuildError(ArtifactoryError):
anancarv marked this conversation as resolved.
Show resolved Hide resolved
"""Artifactory Build Error."""

status: int
message: str

def __init__(self, status: int, message: str):
self.status = status
self.message = message
32 changes: 32 additions & 0 deletions pyartifactory/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,23 @@
ArtifactStatsResponse,
)
from .auth import AccessTokenModel, ApiKeyModel, AuthModel, PasswordModel
from .build import (
BuildAgent,
BuildArtifact,
BuildCreateRequest,
BuildDeleteRequest,
BuildDiffResponse,
BuildDiffResponseDetail,
BuildInfo,
BuildInfoDetail,
BuildListResponse,
BuildModules,
BuildPromotionRequest,
BuildPromotionResult,
BuildRun,
Run,
SimpleBuild,
)
from .group import Group, SimpleGroup
from .permission import Permission, PermissionV2, SimplePermission
from .repository import (
Expand Down Expand Up @@ -70,4 +87,19 @@
"AnyRepositoryResponse",
"AnyRepository",
"AnyPermission",
"SimpleBuild",
"BuildListResponse",
"Run",
"BuildRun",
"BuildArtifact",
"BuildModules",
"BuildAgent",
"BuildInfoDetail",
"BuildInfo",
"BuildPromotionResult",
"BuildPromotionRequest",
"BuildDeleteRequest",
"BuildDiffResponseDetail",
"BuildDiffResponse",
"BuildCreateRequest",
]
145 changes: 145 additions & 0 deletions pyartifactory/models/build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
"""
Definition of all build models.
"""
from __future__ import annotations

from typing import Dict, List, Optional

from pydantic import BaseModel, Field


class SimpleBuild(BaseModel):
"""Models an artifactory single build."""

uri: str
lastStarted: str


class BuildListResponse(BaseModel):
"""Models all artifactory builds."""

uri: str = ""
builds: Optional[List[SimpleBuild]] = None


class Run(BaseModel):
"""Models an artifactory single build run."""

uri: str
buildsNumbers: str
anancarv marked this conversation as resolved.
Show resolved Hide resolved


class BuildRun(BaseModel):
"""Models artifactory build runs."""

uri: str
buildsNumber: Optional[List[Run]] = None


class BuildArtifact(BaseModel):
"""Models artifactory build artifact."""

type: str
sha1: str
sha256: str
md5: str
name: str
path: str


class BuildModules(BaseModel):
"""Models artifactory's build modules."""

properties: Dict[str, str]
type: str
id: str
artifacts: List[BuildArtifact]


class BuildAgent(BaseModel):
name: str = ""
version: str = ""


class BuildInfoDetail(BaseModel):
"""Models artifactory buildInfo dict."""

properties: Optional[Dict[str, str]] = None
version: str = ""
name: str = ""
number: str = ""
buildAgent: BuildAgent = BuildAgent()
agent: BuildAgent = BuildAgent()
started: str = ""
durationMillis: int = 0
artifactoryPrincipal: str = ""
vcs: Optional[List[Dict[str, str]]] = None
modules: List[BuildModules] = []


class BuildInfo(BaseModel):
"""Models artifactory build."""

uri: str = ""
buildInfo: BuildInfoDetail = BuildInfoDetail()


class BuildPromotionResult(BaseModel):
messages: List[Dict[str, str]] = []


class BuildPromotionRequest(BaseModel):
status: str = ""
comment: str = ""
ciUser: str = ""
timestamp: str = ""
dryRun: bool = False
sourceRepo: str
targetRepo: str
copyArtifact: bool = Field(False, alias="copy")
artifacts: bool = True
dependencies: bool = False
scopes: List[str] = []
properties: Dict[str, List[str]] = {}
failFast: bool = True


class BuildDeleteRequest(BaseModel):
project: str = ""
buildName: str
buildNumbers: List[str]
deleteArtifacts: bool = False
deleteAll: bool = False


class BuildDiffResponseDetail(BaseModel):
updated: List[str] = []
unchanged: List[str] = []
removed: List[str] = []
new: List[str] = []


class BuildDiffResponse(BaseModel):
artifacts: BuildDiffResponseDetail = BuildDiffResponseDetail()
dependencies: BuildDiffResponseDetail = BuildDiffResponseDetail()
properties: BuildDiffResponseDetail = BuildDiffResponseDetail()


class BuildErrorDetail(BaseModel):
status: int = 0
message: str = ""


class BuildError(BaseModel):
anancarv marked this conversation as resolved.
Show resolved Hide resolved
errors: List[BuildErrorDetail]


class BuildCreateRequest(BaseModel):
name: str
number: str
agent: BuildAgent = BuildAgent()
buildAgent: BuildAgent = BuildAgent()
started: str = ""
properties: Dict[str, str] = {}
artifactoryPrincipal: str = ""
vcs: List[Dict[str, str]] = []
anancarv marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 2 additions & 0 deletions pyartifactory/objects/artifactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from pyartifactory.models.auth import AuthModel
from pyartifactory.objects.artifact import ArtifactoryArtifact
from pyartifactory.objects.build import ArtifactoryBuild
from pyartifactory.objects.group import ArtifactoryGroup
from pyartifactory.objects.permission import ArtifactoryPermission
from pyartifactory.objects.repository import ArtifactoryRepository
Expand Down Expand Up @@ -39,3 +40,4 @@ def __init__(
self.repositories = ArtifactoryRepository(self.artifactory)
self.artifacts = ArtifactoryArtifact(self.artifactory)
self.permissions = ArtifactoryPermission(self.artifactory)
self.builds = ArtifactoryBuild(self.artifactory)
Loading
Loading