Commit 23d70cd4 authored by harshavardhan.c's avatar harshavardhan.c

enh: updated code for prepartion of helm-chart preparation.

parent 2c37df7c
DB_URI=sqlite:///./ilens_versions.db
CONFIG_MAP_VARIABLES=MONGO_URI
HELM_REPO = https://gitlab-pm.knowledgelens.com/faizan.azim/utest
GIT_USERNAME = faizan.azim
GIT_TOKEN = MFz2FuGSasbQtBkpdfr6
HELM_REPO = https://gitlab-pm.knowledgelens.com/KnowledgeLens/Products/iLens-2.0/core/devops/helm-charts
GIT_USERNAME = harshavardhan.c
GIT_TOKEN = FEMA6PnP63fJCs6DrtZJ
GLOBAL_VARIABLES_FILE=ilens-global-configmap.yml
This diff is collapsed.
import os
import git
import gitlab
from scripts.logging import logging
default_link = "https://gitlab-pm.knowledgelens.com/"
HELM_PATH = "/ilens-core/ilens-modules"
HELM_STORE_PATH = "./helm-charts"
class GitHandler:
def __init__(self, access_token, user_name):
self.access_token = access_token
self.user_name = user_name
def clone_repository(self, repo_link, module_output_path, clone_branch):
try:
if repo_link.split("https://")[-1].startswith("gitlab-pm"):
repo_link = repo_link.replace("https://", f"https://{self.user_name}:{self.access_token}@")
repo = git.Repo.clone_from(repo_link, module_output_path,
branch=clone_branch)
return True
except Exception as e:
logging.exception(f"Exception occurred while cloning the git repo - {repo_link} - {e.args}")
return False
def clone_repository_with_defined_file(self, repo_link: str, file_output_path, clone_branch, clone_file_path):
try:
base_url = os.environ.get("GIT_BASE_URL", default=default_link)
repo_link_split = repo_link.split(base_url)
if not repo_link_split:
return False
gl = gitlab.Gitlab(url=base_url, private_token=self.access_token)
search_str = repo_link_split[-1].replace(".git", "")
pl = gl.projects.list(search=search_str)
if not pl:
return False
pl = pl[0]
with open(file_output_path, 'wb') as f:
pl.files.raw(file_path=clone_file_path, ref=clone_branch, streamed=True, action=f.write)
return True
except Exception as e:
logging.exception(f"Exception occurred while cloning the git repo - {repo_link} - {e.args}")
return False
def get_git_url_by_module_name(self, module_name):
try:
base_url = os.environ.get("GIT_BASE_URL", default=default_link)
gl = gitlab.Gitlab(url=base_url, private_token=self.access_token)
pl = gl.projects.list(search=module_name, group="/KnowledgeLens/Products/iLens-2.0")
return pl[0].web_url if pl else ''
except Exception as e:
logging.exception(f"Exception occurred while fetching repo details - {e.args}")
return False
def pull_global_config(self, repo_link: str, branch: str, file_name: str):
base_url = os.environ.get("GIT_BASE_URL", default=default_link)
repo_link_split = repo_link.split(base_url)
if not repo_link_split:
return False
gl = gitlab.Gitlab(url=base_url, private_token=self.access_token)
search_str = repo_link_split[-1].replace(".git", "")
if pl := gl.projects.list(search=search_str):
pl = pl[0]
else:
return False
with open(file_name, 'wb') as f:
pl.files.raw(file_path=f'{HELM_PATH[1:]}/{file_name}', ref=branch, streamed=True, action=f.write)
return True
def remove_all_files_from_repo(self, repo_link: str, branch: str, exclude_file: list):
base_url = os.environ.get("GIT_BASE_URL", default=default_link)
repo_link_split = repo_link.split(base_url)
if not repo_link_split:
return False
gl = gitlab.Gitlab(url=base_url, private_token=self.access_token)
search_str = repo_link_split[-1].replace(".git", "")
if pl := gl.projects.list(search=search_str):
pl = pl[0]
else:
return False
items = pl.repository_tree(path=HELM_PATH, ref=branch)
print(items)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment