Skip to content
Prev Previous commit
Next Next commit
Fixed more lint errors
  • Loading branch information
markphillips100 committed Jun 14, 2025
commit 3d247dfbd3489cc9430802e943daf7cf5513a981
4 changes: 2 additions & 2 deletions src/clients/azdo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import logging
from configuration.gitops_config import GitOpsConfig


class AzdoClient:

def __init__(self, gitops_config: GitOpsConfig):
# https://dev.azure.com/csedevops/GitOps
self.org_url = gitops_config.azdo_org_url # utils.getenv("AZDO_ORG_URL")
self.org_url = gitops_config.azdo_org_url
# token is supposed to be stored in a secret without any transformations
token = base64.b64encode(f':{utils.getenv("PAT")}'.encode("ascii")).decode("ascii")

Expand Down
2 changes: 1 addition & 1 deletion src/clients/github_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class GitHubClient:

def __init__(self, gitops_config: GitOpsConfig):
self.org_url = gitops_config.github_org_url # utils.getenv("GITHUB_ORG_URL") # https://api.github.com/repos/kaizentm
self.org_url = gitops_config.github_org_url
# token is supposed to be stored in a secret without any transformations
self.token = utils.getenv("PAT")
self.headers = {'Authorization': f'token {self.token}'}
Expand Down
4 changes: 2 additions & 2 deletions src/configuration/gitops_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ def __init__(self,
cicd_orchestrator_type,
gitops_operator_type,
gitops_app_url,
azdo_gitops_repo_name=None,
azdo_pr_repo_name=None,
azdo_gitops_repo_name=None,
azdo_pr_repo_name=None,
azdo_org_url=None,
github_gitops_repo_name=None,
github_gitops_manifests_repo_name=None,
Expand Down
1 change: 0 additions & 1 deletion src/configuration/gitops_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,3 @@ def drain_commit_status_queue(self):

except Exception as e:
logging.error(f'Unexpected exception in the message queue draining thread: {e}')

5 changes: 3 additions & 2 deletions src/operators/argo_gitops_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from operators.git_commit_status import GitCommitStatus
from configuration.gitops_config import GitOpsConfig


class ArgoGitopsOperator(GitopsOperatorInterface):

def __init__(self, gitops_config: GitOpsConfig):
Expand Down Expand Up @@ -48,7 +49,7 @@ def is_finished(self, phase_data):
logging.debug(f'is_finished called. phase_data: {json.dumps(phase_data, indent=2)}')
phase_status, _, health_status = self._get_statuses(phase_data)
logging.debug(f'is_finished: phase_status: {phase_status}, health_status: {health_status}')

is_finished = \
phase_status != 'Inconclusive' \
and phase_status != 'Running' \
Expand Down Expand Up @@ -80,7 +81,7 @@ def is_supported_operator(self, phase_data) -> bool:

def is_supported_message(self, phase_data) -> bool:
if ((not self.is_supported_operator(phase_data)) or
phase_data['commitid'] == "<no value>" or
phase_data['commitid'] == "<no value>" or
phase_data['resources'] == None):
return False
return True
Expand Down
6 changes: 3 additions & 3 deletions src/operators/flux_gitops_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,11 @@ def get_commit_id(self, phase_data) -> str:
revision = phase_data['metadata']['source.toolkit.fluxcd.io/revision']

return parse_commit_id(revision)

def is_supported_operator(self, phase_data) -> bool:
return (self.gitops_config.name == 'singleInstance' or
(self.gitops_config.name != 'singleInstance' and
'gitops_connector_config_name' in phase_data['metadata'] and
(self.gitops_config.name != 'singleInstance' and
'gitops_connector_config_name' in phase_data['metadata'] and
phase_data['metadata']['gitops_connector_config_name'] == self.gitops_config.name))

def is_supported_message(self, phase_data) -> bool:
Expand Down
4 changes: 2 additions & 2 deletions src/operators/gitops_operator.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

import utils
from abc import ABC, abstractmethod
from configuration.gitops_config import GitOpsConfig


class GitopsOperatorInterface(ABC):

def __init__(self, gitops_config: GitOpsConfig):
self.gitops_config = gitops_config
self.callback_url = gitops_config.gitops_app_url # utils.getenv("GITOPS_APP_URL")
self.callback_url = gitops_config.gitops_app_url

@abstractmethod
def extract_commit_statuses(self, phase_data):
Expand Down
3 changes: 1 addition & 2 deletions src/operators/gitops_operator_factory.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

import utils
from operators.argo_gitops_operator import ArgoGitopsOperator
from operators.flux_gitops_operator import FluxGitopsOperator
from operators.gitops_operator import GitopsOperatorInterface
Expand All @@ -16,7 +15,7 @@ class GitopsOperatorFactory:

@staticmethod
def new_gitops_operator(gitops_config: GitOpsConfig) -> GitopsOperatorInterface:
gitops_operator_type = gitops_config.gitops_operator_type # utils.getenv("GITOPS_OPERATOR_TYPE", FLUX_TYPE)
gitops_operator_type = gitops_config.gitops_operator_type

if gitops_operator_type == FLUX_TYPE:
return FluxGitopsOperator(gitops_config)
Expand Down
4 changes: 2 additions & 2 deletions src/orchestrators/azdo_cicd_orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def _update_pr_task(self, is_successful, pr_num, is_alive=True):
def _get_pr_task_data(self, pr_num, is_alive=True):
logging.debug(f'_get_pr_task_data called. pr_num: {pr_num}, is_alive: {is_alive}')
return self.git_repository.get_pr_metadata(pr_num)

# Given a PR task, check if it's parent plan has already completed.
# Note: Completed does not necessarily mean it succeeded.
def _plan_already_completed(self, pr_task):
Expand Down Expand Up @@ -120,7 +120,7 @@ def _build_job_already_completed(self, pr_task, plan_info):
logging.debug(f'Check if job {job_id} already completed: state = {job_state}')
job_state_completed = job_state == 'completed'
return job_state_completed

def notify_abandoned_pr_tasks(self):
logging.debug('notify_abandoned_pr_tasks called')
update_count = 0
Expand Down
2 changes: 1 addition & 1 deletion src/orchestrators/cicd_orchestrator_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class CicdOrchestratorFactory:

@staticmethod
def new_cicd_orchestrator(git_repository: GitRepositoryInterface, gitops_config: GitOpsConfig) -> CicdOrchestratorInterface:
cicd_orchestrator_type = gitops_config.cicd_orchestrator_type # utils.getenv("CICD_ORCHESTRATOR_TYPE", AZDO_TYPE)
cicd_orchestrator_type = gitops_config.cicd_orchestrator_type

if cicd_orchestrator_type == AZDO_TYPE:
return AzdoCicdOrchestrator(git_repository, gitops_config)
Expand Down
3 changes: 1 addition & 2 deletions src/orchestrators/github_cicd_orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Licensed under the MIT License.

import logging
import utils
import requests
from orchestrators.cicd_orchestrator import CicdOrchestratorInterface
from repositories.git_repository import GitRepositoryInterface
Expand All @@ -14,7 +13,7 @@ class GitHubCicdOrchestrator(CicdOrchestratorInterface):

def __init__(self, git_repository: GitRepositoryInterface, gitops_config: GitOpsConfig):
super().__init__(git_repository)
self.gitops_repo_name = gitops_config.github_gitops_repo_name # utils.getenv("GITHUB_GITOPS_REPO_NAME") # cloud-native-ops
self.gitops_repo_name = gitops_config.github_gitops_repo_name
self.github_client = GitHubClient(gitops_config)
self.headers = self.github_client.get_rest_api_headers()
self.rest_api_url = self.github_client.get_rest_api_url()
Expand Down
6 changes: 2 additions & 4 deletions src/repositories/azdo_git_repository.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

import os
import logging
import json
import requests
import utils
from clients.azdo_client import AzdoClient
from repositories.git_repository import GitRepositoryInterface
from configuration.gitops_config import GitOpsConfig
Expand All @@ -16,8 +14,8 @@
class AzdoGitRepository(GitRepositoryInterface):

def __init__(self, gitops_config: GitOpsConfig):
self.gitops_repo_name = gitops_config.azdo_gitops_repo_name # utils.getenv("AZDO_GITOPS_REPO_NAME")
self.pr_repo_name = gitops_config.azdo_pr_repo_name # os.getenv("AZDO_PR_REPO_NAME", self.gitops_repo_name)
self.gitops_repo_name = gitops_config.azdo_gitops_repo_name
self.pr_repo_name = gitops_config.azdo_pr_repo_name
self.azdo_client = AzdoClient(gitops_config)
self.repository_api = f'{self.azdo_client.get_rest_api_url()}/_apis/git/repositories/{self.gitops_repo_name}'
self.pr_repository_api = f'{self.azdo_client.get_rest_api_url()}/_apis/git/repositories/{self.pr_repo_name}'
Expand Down
5 changes: 2 additions & 3 deletions src/repositories/git_repository_factory.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

import os
from repositories.git_repository import GitRepositoryInterface
from repositories.azdo_git_repository import AzdoGitRepository
from repositories.github_git_repository import GitHubGitRepository
Expand All @@ -15,8 +14,8 @@
class GitRepositoryFactory:

@staticmethod
def new_git_repository(gitops_config:GitOpsConfig) -> GitRepositoryInterface:
git_repository_type = gitops_config.git_repository_type # os.getenv("GIT_REPOSITORY_TYPE", AZDO_TYPE)
def new_git_repository(gitops_config: GitOpsConfig) -> GitRepositoryInterface:
git_repository_type = gitops_config.git_repository_type

if git_repository_type == AZDO_TYPE:
return AzdoGitRepository(gitops_config)
Expand Down
4 changes: 2 additions & 2 deletions src/repositories/github_git_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
# Licensed under the MIT License.

import requests
import utils
import logging
from clients.github_client import GitHubClient
from repositories.git_repository import GitRepositoryInterface
from configuration.gitops_config import GitOpsConfig


class GitHubGitRepository(GitRepositoryInterface):

MAX_DESCR_LENGTH = 140

def __init__(self, gitops_config: GitOpsConfig):
self.gitops_repo_name = gitops_config.github_gitops_manifests_repo_name # utils.getenv("GITHUB_GITOPS_MANIFEST_REPO_NAME") # gitops-manifests
self.gitops_repo_name = gitops_config.github_gitops_manifests_repo_name
self.github_client = GitHubClient(gitops_config)
self.headers = self.github_client.get_rest_api_headers()
self.rest_api_url = self.github_client.get_rest_api_url()
Expand Down