Skip to content

Commit

Permalink
feat: release changes for version 0.4.14
Browse files Browse the repository at this point in the history
  • Loading branch information
DeXtroTip committed Jan 3, 2025
1 parent 0824c89 commit 278f2f6
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 18 deletions.
4 changes: 4 additions & 0 deletions galaxy/core/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
class GalaxyError(Exception):
"""Base class for all Galaxy errors."""

@property
def error_type(self) -> str:
return self.__class__.__name__


class GalaxyWarning(GalaxyError):
"""Base class for all Galaxy warnings."""
Expand Down
9 changes: 5 additions & 4 deletions galaxy/core/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ async def main(
if dry_run is False:
integration_config = await magneto_client.get_plugin(str(config.integration.id))

# Get the properties from the integration config. Using `pop` to remove them from the original dict
integration_config_properties = integration_config.pop("properties", None)

logger.debug("Config entity from magneto: %r", integration_config)
if integration_config["dataSource"].lower() != integration_type:
logger.error(
Expand All @@ -54,9 +57,8 @@ async def main(
)
raise Exception("Integration type mismatch between the integration and magneto config")

config_entity_properties = integration_config.get("properties", None)
if config_entity_properties is not None:
for key, value in config_entity_properties.items():
if integration_config_properties is not None:
for key, value in integration_config_properties.items():
# Only set the property if it doesn't already exist or is empty
if not config.integration.properties.get(key) or (
# This OR is to handle the scenario of a nested dict with keys but no values
Expand All @@ -65,7 +67,6 @@ async def main(
):
config.integration.properties[key] = value

logger.debug("Config entity properties: %r", config.integration.properties)
if integration_config is None:
logger.error("Integration not found in magneto")
raise Exception("Integration not found in magneto")
Expand Down
18 changes: 18 additions & 0 deletions galaxy/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class RelyConfig(BaseModel):
token: str = Field(..., alias="token")
url: str = Field(..., alias="url")

def __repr__(self) -> str:
return f"RelyConfig(url={self.url!r})"


class IntegrationConfig(BaseModel):
model_config = ConfigDict(extra="forbid")
Expand All @@ -39,6 +42,18 @@ class IntegrationConfig(BaseModel):
wait_for_tasks_enabled: bool = Field(True, alias="waitForTasksEnabled")
wait_for_tasks_timeout_seconds: int | None = Field(600, alias="waitForTasksTimeout")

def __repr__(self) -> str:
"""Return a string representation of the IntegrationConfig.
Properties are not included as they may contain sensitive information.
"""
return (
f"IntegrationConfig(id={self.id}, type={self.type}, execution_type={self.execution_type}, "
f"scheduled_interval={self.scheduled_interval}, default_model_mappings={self.default_model_mappings}, "
f"dry_run={self.dry_run}, wait_for_tasks_enabled={self.wait_for_tasks_enabled}, "
f"wait_for_tasks_timeout_seconds={self.wait_for_tasks_timeout_seconds})"
)


class Config(BaseModel):
@classmethod
Expand All @@ -52,6 +67,9 @@ def from_yaml(cls, file_path):
rely: RelyConfig
integration: IntegrationConfig

def __repr__(self) -> str:
return f"Config(rely={self.rely!r}, integration={self.integration!r})"


class FileCheck(BaseModel):
path: str
Expand Down
3 changes: 2 additions & 1 deletion galaxy/integrations/gitlab/.rely/automations.json
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,8 @@
"updatedAt": "{{ data.properties.updatedAt if data.properties.updatedAt else none }}",
"closedAt": "{{ data.properties.finishedAt if data.properties.finishedAt else none }}",
"sourceCommit": "{{ data.properties.commit if data.properties.commit else none }}",
"triggeredBy": "{{ actions.fetch_author.output.title if actions.fetch_author else none }}"
"triggeredBy": "{{ actions.fetch_author.output.title if actions.fetch_author else none }}",
"successful": "{{ true if data.properties.status == 'SUCCESS' else false }}"
},
"relations": {
"service": {
Expand Down
4 changes: 2 additions & 2 deletions galaxy/integrations/gitlab/.rely/mappings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ resources:
closedAt: .node.closedAt
url: .node.webUrl
state: .node.state
labels: '[.node.labels.edges[].node.title]'
labels: 'try [.node.labels.edges[].node.title] catch []'
relations:
repository:
value: '"gitlab_repo_" + (.context.repository.id | split("/") | last)'
Expand All @@ -90,7 +90,7 @@ resources:
updatedAt: .node.updatedAt
closedAt: .node.closedAt
state: .node.state
labels: '[.node.labels.edges[].node.title]'
labels: 'try [.node.labels.edges[].node.title] catch []'
sourceBranch: .node.sourceBranch
targetBranch: .node.targetBranch
mergedAt: .node.mergedAt
Expand Down
10 changes: 6 additions & 4 deletions galaxy/integrations/gitlab/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,18 @@ async def get_environments(self, repository: dict) -> list[dict]:
self.session, "POST", self.url_graphql, json=query, retry_policy=self.retry_policy
)

environments = data["data"]["project"]["environments"]
environments = data.get("data", {}).get("project", {}).get("environments")
if not environments:
return all_environments

edges = environments["edges"]
all_environments.extend(environments["edges"])

page_info = environments["pageInfo"]
all_environments.extend(edges)
if not page_info["hasNextPage"]:
break

cursor = page_info["endCursor"]

return all_environments

async def get_deployments(self, repository: dict, environment: str, history_days: int) -> list[dict]:
Expand Down Expand Up @@ -294,7 +296,7 @@ async def get_user_by_username(self, username: str) -> dict:

data = await make_request(self.session, "POST", self.url_graphql, json=query, retry_policy=self.retry_policy)

return data["data"]["user"]
return data.get("data", {}).get("user", {})

async def get_file(self, repository_path: str, file_path: str) -> dict:
query = self.queries.get_file(repository_path, file_path)
Expand Down
6 changes: 3 additions & 3 deletions galaxy/integrations/gitlab/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ async def get_repo_files(self, repo_full_path: str) -> dict:
if file_check["regex"]:
result = re.search(file_check["regex"], file["content"]) if file_check["regex"] else None
repo_file_checks[file_check["destination"]] = (
result.group(1) if result else FileCheckStatus.FILE_FOUND_NO_MATCH
result.group(1) if result else FileCheckStatus.FILE_FOUND_NO_MATCH.value
)
else:
repo_file_checks[file_check["destination"]] = FileCheckStatus.FILE_FOUND
repo_file_checks[file_check["destination"]] = FileCheckStatus.FILE_FOUND.value
else:
repo_file_checks[file_check["destination"]] = FileCheckStatus.FILE_NOT_FOUND
repo_file_checks[file_check["destination"]] = FileCheckStatus.FILE_NOT_FOUND.value

return repo_file_checks

Expand Down
4 changes: 2 additions & 2 deletions galaxy/integrations/snyk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(self, config: Config, logger: Logger):
raise ValueError(f"Invalid Snyk hosting region: {region}")

async def __aenter__(self) -> "SnykClient":
self._session = create_session(timeout=30, headers=self._headers, **self._session_kwargs)
self._session = create_session(timeout=60, headers=self._headers, **self._session_kwargs)
return self

async def __aexit__(self, exc_type: type, exc: Exception, tb: TracebackType) -> None:
Expand Down Expand Up @@ -79,7 +79,7 @@ async def get_projects(self, org_id: str, target_id: str) -> list[dict]:
f"/rest/orgs/{org_id}/projects", params={"target_id": [target_id], "meta.latest_issue_counts": "true"}
)

async def get_issues(self, org_id: str, project_id: str, history_start_date: datetime = None) -> list[dict]:
async def get_issues(self, org_id: str, project_id: str, history_start_date: datetime | None = None) -> list[dict]:
params = {"scan_item.type": "project", "scan_item.id": project_id}
if history_start_date is not None:
params["created_after"] = history_start_date.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3] + "Z"
Expand Down
4 changes: 2 additions & 2 deletions galaxy/integrations/snyk/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def __init__(self, config: Config):
super().__init__(config)
self.client = SnykClient(self.config, self.logger)

self._organizations = []
self._organizations = {}
self._all_projects = []

async def __aenter__(self) -> "Snyk":
Expand Down Expand Up @@ -66,7 +66,7 @@ async def projects(self) -> tuple[Any]:
return mapped_projects

@register(_methods, group=3)
async def issues(self) -> tuple[Any]:
async def issues(self) -> list[Any]:
organization_target_project_triples = [
(
item["relationships"]["organization"]["data"]["id"],
Expand Down

0 comments on commit 278f2f6

Please sign in to comment.