diff --git a/src/alire/alire-publish-submit.adb b/src/alire/alire-publish-submit.adb index c4735899a..4cd25ad6d 100644 --- a/src/alire/alire-publish-submit.adb +++ b/src/alire/alire-publish-submit.adb @@ -72,6 +72,9 @@ package body Alire.Publish.Submit is & "variable."); Put_Info ("You can create access tokens at " & TTY.URL (GitHub.URL_Tokens)); + Put_Info + ("Run " & TTY.Terminal ("alr help publish") + & " for further details."); end if; return (if GH_Token /= "" @@ -117,29 +120,21 @@ package body Alire.Publish.Submit is Put_Success ("No conflicting pull request found"); end Exists; - --------------- - -- Fork_Repo -- - --------------- + ----------------- + -- Ask_To_Fork -- + ----------------- - procedure Fork (Context : in out Data) is + function Ask_To_Fork (Context : in out Data) return Boolean is use all type CLIC.User_Input.Answer_Kind; use all type GitHub.Async_Result; begin - - -- Verify manifest to publish was generated at expected place - - if not Directories.Is_File (Context.Generated_Manifest) then - Raise_Checked_Error ("Cannot continue: manifest missing at " - & TTY.URL (Context.Generated_Manifest)); - end if; - - Context.Token := +Ask_For_Token - ("to fork the community index to your account"); - if GitHub.Repo_Exists then Put_Success ("Community index fork exists in user account"); - return; + return True; else + Context.Token := +Ask_For_Token + ("to fork the community index to your account"); + if CLIC.User_Input.Query ("A fork of the community index will now be created into your " & "GitHub account to be able to submit a pull request. " @@ -147,8 +142,7 @@ package body Alire.Publish.Submit is Valid => (Yes | No => True, others => False), Default => Yes) /= Yes then - Raise_Checked_Error - ("Cannot continue with automatic submission"); + return False; end if; end if; @@ -163,6 +157,20 @@ package body Alire.Publish.Submit is when Completed => Put_Success ("Fork of community index completed"); end case; + + return True; + end Ask_To_Fork; + + --------------- + -- Fork_Repo -- + --------------- + + procedure Fork (Context : in out Data) is + begin + if not Ask_To_Fork (Context) then + Raise_Checked_Error + ("Cannot continue with automatic submission"); + end if; end Fork; ----------- diff --git a/src/alire/alire-publish-submit.ads b/src/alire/alire-publish-submit.ads index d35642490..e0240d335 100644 --- a/src/alire/alire-publish-submit.ads +++ b/src/alire/alire-publish-submit.ads @@ -1,5 +1,9 @@ private package Alire.Publish.Submit is + function Ask_To_Fork (Context : in out Data) return Boolean; + -- Offer to fork the community index on the user behalf, return True if + -- successfully forked. + -- Steps for the assistant, not intended to be called directly. These steps -- are executed right after manifest creation in the order that follows. diff --git a/src/alire/alire-publish.adb b/src/alire/alire-publish.adb index 91ed002a5..9aa86ca29 100644 --- a/src/alire/alire-publish.adb +++ b/src/alire/alire-publish.adb @@ -797,7 +797,6 @@ package body Alire.Publish is ------------------- procedure Verify_Github (Context : in out Data) is - pragma Unreferenced (Context); begin -- Early return if forcing @@ -827,41 +826,23 @@ package body Alire.Publish is -- User must exist if not GitHub.User_Exists (Login) then - Raise_Checked_Error + Recoverable_Error ("Your GitHub login does not seem to exist: " & TTY.Emph (Login)); end if; -- It has to have its own fork of the repo - if not GitHub.Repo_Exists (Login, Index.Community_Repo_Name) then - Raise_Checked_Error - ("You must fork the community index to your GitHub account" - & ASCII.LF & "Please visit " - & TTY.URL (Tail (Index.Community_Repo, '+')) - & " and fork the repository."); - else + if GitHub.Repo_Exists (Login, Index.Community_Repo_Name) then Put_Success ("User has forked the community repository"); - end if; - - -- The repo must contain the base branch, or otherwise GitHub - -- redirects to the main repository page with an error banner on top. - - if not GitHub.Branch_Exists (User => Login, - Repo => Index.Community_Repo_Name, - Branch => Index.Community_Branch) - then - Raise_Checked_Error - ("Your index fork is missing the current base branch (" - & TTY.Emph (Index.Community_Branch) & ")" - & " for pull requests to the community repository" & ASCII.LF - & "Please synchronize this branch and try again" & ASCII.LF - & "Your fork URL is: " - & TTY.URL (Index.Community_Host - & "/" & Login & "/" & Index.Community_Repo_Name)); else - Put_Success ("User's fork contains base branch: " - & TTY.Emph (Index.Community_Branch)); + if not Submit.Ask_To_Fork (Context) then + Recoverable_Error + ("You must fork the community index to your GitHub account" + & ASCII.LF & "Please visit " + & TTY.URL (Tail (Index.Community_Repo, '+')) + & " if you want to fork manually."); + end if; end if; end; end Verify_Github;