-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #335 from DataRecce/feature/drc-477-add-a-runner-t…
…ype-in-the-recce-telemetry [Chore] Track running environment and repository
- Loading branch information
Showing
4 changed files
with
67 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
from git import Repo | ||
import os | ||
|
||
from git import Repo, InvalidGitRepositoryError | ||
|
||
|
||
def current_branch(): | ||
|
@@ -12,3 +14,27 @@ def current_branch(): | |
return None | ||
except Exception: | ||
return None | ||
|
||
|
||
def hosting_repo(): | ||
try: | ||
repo = Repo(search_parent_directories=True) | ||
origin_url = repo.remote().url | ||
remote_repo = None | ||
|
||
if origin_url.startswith('git@'): | ||
# Handle [email protected]:user/repo.git | ||
remote_repo = origin_url.split(':')[1].replace('.git', '') | ||
|
||
elif origin_url.startswith('https://') or origin_url.startswith('http://'): | ||
# Handle https://github.com/user/repo.git or http://github.com/user/repo.git | ||
remote_repo = '/'.join(origin_url.split('/')[-2:]).replace('.git', '') | ||
|
||
return remote_repo | ||
except ValueError: | ||
repo = Repo(search_parent_directories=True) | ||
toplevel_dir = repo.git.rev_parse("--show-toplevel") | ||
|
||
return os.path.basename(toplevel_dir) | ||
except InvalidGitRepositoryError: | ||
return None |