Skip to content

Commit

Permalink
Merge pull request #539 from dgraeber/feature/git-logging
Browse files Browse the repository at this point in the history
adding git error messaging
  • Loading branch information
dgraeber authored Apr 1, 2024
2 parents f0363ca + 8f216df commit bea957d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a Ch
- adding verbose messaging to session manager and hints to reconcile session issues
- adding info for destroy and list deployments when no deployments found
- refactored git support logic to separate python file
- added verbose messaging related to git issues

### Fixes
- Add schema validation step checking that either `value` or `value_from` is present for each parameter
Expand Down
20 changes: 14 additions & 6 deletions seedfarmer/messages.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
from typing import Optional

checklist = """ Be sure to check:
1. The session that you are executing the CLI from matches the ACCOUNT and REGION
where your toolchain is configured
2. The session has permissions to access the proper toolchain role
"""


def no_deployment_found(deployment_name: Optional[str] = None) -> str:
msg = "We found no deployments with your active session."
if deployment_name:
msg = f"We found no deployments named {deployment_name} with your active session."

checklist = """ Be sure to check:
1. The session that you are executing the CLI from matches the ACCOUNT and REGION
where your toolchain is configured
2. The session has permissions to access the proper toolchain role
"""

return msg + checklist


def git_error_support() -> str:
return """
1. Make sure your path to the repo is correct and valid (check your module manifests!)
2. The credentials used to call SeedFarmer have access to the repo
3. The credentials used to call SeedFarmer have not expired
"""
23 changes: 17 additions & 6 deletions seedfarmer/mgmt/git_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import git
from git import Repo

import seedfarmer.messages as messages
from seedfarmer import config
from seedfarmer.errors import InvalidConfigurationError

_logger: logging.Logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -70,16 +72,25 @@ def clone_module_repo(git_path: str) -> Tuple[str, str, Optional[str]]:
if ref is not None:
_logger.debug("Creating local repo and setting remote: %s into %s: ref=%s ", git_path, working_dir, ref)
repo = Repo.init(working_dir)
git.Remote.create(repo, "origin", git_path, allow_unsafe_protocols)
repo.remotes["origin"].pull(ref, allow_unsafe_protocols=allow_unsafe_protocols)
try:
git.Remote.create(repo, "origin", git_path, allow_unsafe_protocols)
repo.remotes["origin"].pull(ref, allow_unsafe_protocols=allow_unsafe_protocols)
except git.GitError as ge:
raise InvalidConfigurationError(f"\n Cannot Clone Repo: {ge} {messages.git_error_support()}")
else:
_logger.debug("Cloning %s into %s: ref=%s depth=%s", git_path, working_dir, ref, depth)
repo = Repo.clone_from(
git_path, working_dir, branch=ref, depth=depth, allow_unsafe_protocols=allow_unsafe_protocols
)
try:
repo = Repo.clone_from(
git_path, working_dir, branch=ref, depth=depth, allow_unsafe_protocols=allow_unsafe_protocols
)
except git.GitError as ge:
raise InvalidConfigurationError(f"\n Cannot Clone Repo: {ge} {messages.git_error_support()}")
else:
_logger.debug("Pulling existing repo %s at %s: ref=%s", git_path, working_dir, ref)
repo = Repo(working_dir)
repo.remotes["origin"].pull(ref, allow_unsafe_protocols=allow_unsafe_protocols)
try:
repo.remotes["origin"].pull(ref, allow_unsafe_protocols=allow_unsafe_protocols)
except git.GitError as ge:
raise InvalidConfigurationError(f"\n Cannot Clone Repo: {ge} {messages.git_error_support()}")
commit_hash = get_commit_hash(repo)
return (working_dir, module_directory, commit_hash)

0 comments on commit bea957d

Please sign in to comment.