-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: support fallback to default profile and region (#11)
* fix: support fallback to default profile and region By moving the remote logic to its own class it allows us to encapsulate the behaviour. And making it easier to extend the behaviour. Support both `codecommit://` and `codecommit::://` notations. Fixes issue #7
- Loading branch information
Joris Conijn
authored
Jan 25, 2022
1 parent
e15ccf9
commit 52389cc
Showing
6 changed files
with
142 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from .commits import Commits | ||
from .client import Client | ||
from .commit import Commit | ||
from .commits import Commits | ||
from .message import Message | ||
from .client import Client | ||
from .remote import Remote |
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import re | ||
from typing import Optional | ||
|
||
|
||
class Remote: | ||
""" | ||
Understands remote CodeCommit URLs | ||
""" | ||
|
||
def __init__(self, url: str): | ||
self.__url: str = url | ||
self.__region: Optional[str] = "" | ||
self.__profile: Optional[str] = "" | ||
self.__name: str = "" | ||
|
||
def __regex(self, pattern: str, index: int = 1) -> Optional[str]: | ||
match = re.search(pattern, self.__url) | ||
return match.group(index) if match else None | ||
|
||
@property | ||
def supported(self) -> bool: | ||
return self.__url.startswith("codecommit:") and self.name != "" | ||
|
||
@property | ||
def url(self) -> str: | ||
return self.__url | ||
|
||
@property | ||
def region(self) -> Optional[str]: | ||
if not self.__region: | ||
self.__region = self.__regex(r"^codecommit::(.*)://") | ||
|
||
return self.__region | ||
|
||
@property | ||
def profile(self) -> Optional[str]: | ||
if self.__profile == "": | ||
self.__profile = self.__regex(r"//(.*)@") | ||
|
||
return self.__profile | ||
|
||
@property | ||
def name(self) -> str: | ||
if not self.__name: | ||
name = self.__regex(r"(\/\/|@)(.*)$", 2) | ||
|
||
if name: | ||
self.__name = name | ||
|
||
return self.__name |
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