authentication

variable name changes for readability
removed unused code
This commit is contained in:
mike cullerton 2022-02-02 14:11:41 -05:00
parent a45c5959ef
commit 21b5d034e2
2 changed files with 20 additions and 23 deletions

View File

@ -81,7 +81,7 @@ TARGET_BRANCH = environ.get('TARGET_BRANCH', None)
# Git settings, used by git_service
# The above Github settings--used in file_service, will likely be deprecated
# You can override these settings in instance/config
GIT_REMOTE = environ.get('GIT_REMOTE', None)
GIT_REMOTE_PATH = environ.get('GIT_REMOTE_PATH', None)
GIT_BRANCH = environ.get('GIT_BRANCH', None)
GIT_MERGE_BRANCH = environ.get('GIT_MERGE_BRANCH', None) # Developers can set this to 'all' in instance.config

View File

@ -11,21 +11,21 @@ from datetime import datetime
class GitService(object):
@staticmethod
def setup_repo(remote, directory, branch):
def setup_repo(remote_path, directory, branch):
# we use github
# Note that the 'password' is a token generated by github, not the site password
username = app.config["GIT_USER_NAME"]
# Note that this 'password' is a token generated by github, not the site password
password = app.config["GIT_USER_PASS"]
remote_url = f"https://{username}:{password}@github.com/{remote}.git"
remote_url = f"https://{username}:{password}@github.com/{remote_path}.git"
repo = Repo.clone_from(remote_url, directory)
repo.git.checkout(branch)
return repo
def __get_repo(self):
remote = app.config['GIT_REMOTE']
remote_path = app.config['GIT_REMOTE_PATH']
git_branch = app.config['GIT_BRANCH']
directory = app.config['SYNC_FILE_ROOT']
# repo = None
try:
repo = Repo(directory)
@ -38,11 +38,11 @@ class GitService(object):
message=f'The directory {directory} is not empty, and is not a valid git repository. Please fix this before continuing.')
else:
# The directory is empty, so we setup the repo
repo = self.setup_repo(remote, directory, git_branch)
repo = self.setup_repo(remote_path, directory, git_branch)
except NoSuchPathError:
# The directory does not exist, so setup
repo = self.setup_repo(remote, directory, git_branch)
repo = self.setup_repo(remote_path, directory, git_branch)
except Exception as e:
print(e)
@ -54,12 +54,12 @@ class GitService(object):
return repo
def _get_repo(self):
# This returns a Repo object
# This returns a gitpython Repo object
return self.__get_repo()
def get_repo(self):
# This returns an instance of crc.models.git_models.GitRepo,
# built from a Repo object
# This returns an instance of crc.models.git_models.GitRepo, built from a Repo object
# Called by the api.git_repo methods
repo = self._get_repo()
repo_model = GitRepo().from_repo(repo)
return repo_model
@ -67,7 +67,7 @@ class GitService(object):
def push_to_remote(self, comment=None):
if comment is None:
comment = f"Git commit: {datetime.now()}"
repo = self.__get_repo()
repo = self._get_repo()
# get list of changed files
changes = [item.a_path for item in repo.index.diff(None)]
# get list of untracked files
@ -84,19 +84,16 @@ class GitService(object):
def merge_with_branch(self, branch):
# https://stackoverflow.com/questions/36799362/how-do-you-merge-the-master-branch-into-a-feature-branch-with-gitpython#36802900
repo = self._get_repo()
current = repo.active_branch
# current = repo.active_branch
merge_branch = repo.branches[branch]
base = repo.merge_base(current, merge_branch)
base = repo.merge_base(repo.active_branch, merge_branch)
repo.index.merge_tree(merge_branch, base=base)
repo.index.commit('Merge main into feature',
parent_commits=(current.commit, merge_branch.commit))
current.checkout(force=True)
repo.index.commit(f'Merge {branch} into working branch', parent_commits=(repo.active_branch.commit, merge_branch.commit))
repo.active_branch.checkout(force=True)
print('merge_with_branch')
def pull_from_remote(self):
branch = app.config['GIT_BRANCH']
repo = self.__get_repo()
# repo.git.checkout(branch)
repo = self._get_repo()
if not repo.is_dirty():
try:
repo.remotes.origin.pull()
@ -116,9 +113,9 @@ class GitService(object):
untracked_files = repo.untracked_files
return [changes, untracked_files]
@staticmethod
def init_repo(directory):
return Repo.init(directory)
# @staticmethod
# def init_repo(directory):
# return Repo.init(directory)
# @staticmethod
# def compare_with_branch(repo, branch):