@@ -196,6 +196,7 @@ def __init__(self, parser: argparse.ArgumentParser):
196196 self .tokens : dict = {}
197197 self .setup_method : str = ""
198198 self .deposit_platform : DepositPlatform = DepositPlatform ()
199+ self .git_branch : str = ""
199200 self .git_remote : str = ""
200201 self .git_remote_url = ""
201202 self .git_hoster : GitHoster = GitHoster .Empty
@@ -344,7 +345,8 @@ def test_initialization(self) -> None:
344345 self .no_git_setup ()
345346 sys .exit ()
346347
347- # Look at git remotes
348+ # Look at git branch & remotes
349+ self .git_branch = git_info .get_current_branch ()
348350 remotes = git_info .get_remotes ()
349351 if remotes :
350352 self .git_remote = remotes [0 ]
@@ -544,7 +546,7 @@ def create_zenodo_token(self) -> None:
544546 else :
545547 sc .echo (f"The token could not be validated by { self .deposit_platform .name } . "
546548 "Make sure to enter the complete token.\n "
547- "(If this error persists, you should try switching to the manual setup mode.)" ,
549+ "(If this error persists, you should restart and switch to the manual setup mode.)" ,
548550 formatting = sc .Formats .WARNING )
549551
550552 def create_dataverse_token (self ):
@@ -556,8 +558,20 @@ def create_dataverse_token(self):
556558 if self .setup_method == "m" :
557559 sc .press_enter_to_continue ()
558560 else :
559- # TODO try to validate the token
560- self .deposit_platform .token = sc .answer ("Enter the token here: " )
561+ while True :
562+ token = sc .answer ("Enter the token here: " )
563+ token_valid_url = f"{ self .deposit_platform .url } /api/users/token"
564+ token_valid_response = requests .get (token_valid_url , headers = {"X-Dataverse-key" : token })
565+ if token_valid_response .ok :
566+ sc .echo (f"The token was validated by { self .deposit_platform .name } ." ,
567+ formatting = sc .Formats .OKGREEN )
568+ self .deposit_platform .token = token
569+ break
570+ else :
571+ sc .echo (f"The token could not be validated by { self .deposit_platform .name } . "
572+ "Make sure to enter the complete token.\n "
573+ "(If this error persists, you should restart and switch to the manual setup mode.)" ,
574+ formatting = sc .Formats .WARNING )
561575
562576 def create_rodare_token (self ):
563577 token_url = urljoin (self .deposit_platform .url , "account/settings/applications/tokens/new/" )
@@ -807,7 +821,8 @@ def choose_push_branch(self) -> None:
807821 push_choice = sc .choose (
808822 "When should the automated HERMES process start?" ,
809823 [
810- "When I push a branch" ,
824+ "When I push on custom branch" ,
825+ f"When I push on current branch ({ self .git_branch } )" ,
811826 "When I push a specific tag (not implemented)" ,
812827 ]
813828 )
@@ -818,6 +833,12 @@ def choose_push_branch(self) -> None:
818833 formatting = sc .Formats .OKGREEN )
819834 sc .echo ()
820835 elif push_choice == 1 :
836+ self .ci_parameters ["push_branch" ] = self .git_branch
837+ bold_branch = sc .Formats .BOLD .wrap_around (self .git_branch )
838+ sc .echo (f"The HERMES pipeline will be activated when you push on { bold_branch } " ,
839+ formatting = sc .Formats .OKGREEN )
840+ sc .echo ()
841+ elif push_choice == 2 :
821842 sc .echo ("Setting up triggering by tags is currently not implemented." , formatting = sc .Formats .WARNING )
822843 sc .echo (f"You can visit { TUTORIAL_URL } to set it up manually later-on." , formatting = sc .Formats .WARNING )
823844
0 commit comments