Skip to content
This repository was archived by the owner on Nov 12, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions teamscale_precommit_client/precommit_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# Filename of the precommit configuration. The client expects this config file at the root of the repository.
PRECOMMIT_CONFIG_FILENAME = '.teamscale-precommit.config'
DEFAULT_PROJECT_SUBPATH = ''
DEFAULT_OVERRIDE_BRANCH = ''
DEFAULT_PATH_PREFIX = ''
DEFAULT_FILE_ENCODING = None # Use system encoding

Expand All @@ -33,7 +34,7 @@ def __init__(self, teamscale_config, repository_path, path_prefix=DEFAULT_PATH_P
analyzed_file=None, verify=True, omit_links_to_findings=False, exclude_findings_in_changed_code=False,
fetch_existing_findings=False, fetch_all_findings=False, fetch_existing_findings_in_changes=False,
fail_on_red_findings=False, log_to_stderr=False, file_encoding=DEFAULT_FILE_ENCODING,
ignore_subrepositories=False):
ignore_subrepositories=False, override_branch=DEFAULT_OVERRIDE_BRANCH):
"""Constructor"""
self.teamscale_client = TeamscaleClient(teamscale_config.url, teamscale_config.username,
teamscale_config.access_token, teamscale_config.project_id, verify)
Expand Down Expand Up @@ -61,6 +62,7 @@ def __init__(self, teamscale_config, repository_path, path_prefix=DEFAULT_PATH_P
self.parent_commit_timestamp = 0
self.file_encoding = file_encoding
self.ignore_subrepositories = ignore_subrepositories
self.override_branch = override_branch

def run(self):
"""Performs the precommit analysis. Depending on the modifications made and the flags provided to the client,
Expand Down Expand Up @@ -97,7 +99,10 @@ def _calculate_modifications(self):

def _retrieve_current_branch(self):
"""Retrieves the current branch from the repository."""
self.current_branch = get_current_branch(self.repository_path)
if self.override_branch:
self.current_branch = self.override_branch
else:
self.current_branch = get_current_branch(self.repository_path)

def _retrieve_parent_commit_timestamp(self):
"""Retrieves the commit timestamp from the repository."""
Expand Down Expand Up @@ -324,6 +329,9 @@ def _parse_args():
'(git submodules) in the current repository when determining which files changed. This '
'affects the files considered for precommit analysis. It does not affect the retrieval '
'of "existing" findings from the Teamscale server.')
parser.add_argument('--override-branch', metavar='override-branch', type=str, default=DEFAULT_OVERRIDE_BRANCH,
help='Override branch name to be used. '
'Allows to use local branches that are not known to Teamscale server.')
return parser.parse_args()


Expand Down Expand Up @@ -352,7 +360,8 @@ def _configure_precommit_client(parsed_args):
fail_on_red_findings=parsed_args.fail_on_red_findings,
log_to_stderr=parsed_args.log_to_stderr,
file_encoding=parsed_args.file_encoding,
ignore_subrepositories=parsed_args.ignore_subrepositories)
ignore_subrepositories=parsed_args.ignore_subrepositories,
override_branch=parsed_args.override_branch)


def run():
Expand Down