From d3690e0f697258123b0f8b3bf805555d60f11aed Mon Sep 17 00:00:00 2001 From: Ryan Mulligan Date: Tue, 14 Apr 2020 21:54:59 -0700 Subject: [PATCH] switch to using GitHub library for PRs unfortunately, this breaks PRs for single updates so removing that feature advertisement for now. --- README.md | 1 - app/Main.hs | 2 +- src/GH.hs | 19 +++++++------------ src/Update.hs | 3 ++- 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 44d4a09..71dc8ba 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,6 @@ nixpkgs-update supports interactive, single package updates via the # Flags -* `--pr`—uses Hub to submit a PR to GitHub. * `--cve`—adds CVE vulnerability reporting to the PR message. On first invocation with this option, a CVE database is built. Subsequent invocations will be much faster. diff --git a/app/Main.hs b/app/Main.hs index 878dc26..05ee7e1 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -140,7 +140,7 @@ main = do setupNixpkgs token P.setEnv "PAGER" "" True P.setEnv "GITHUB_TOKEN" (T.unpack token) True - result <- updatePackage (Options pr False token cve cachix nixpkgsReview False) update + result <- updatePackage (Options False False token cve cachix nixpkgsReview False) update case result of Left e -> T.putStrLn e Right () -> T.putStrLn "Done." diff --git a/src/GH.hs b/src/GH.hs index d747839..6812730 100644 --- a/src/GH.hs +++ b/src/GH.hs @@ -19,7 +19,6 @@ where import Control.Applicative (some) import qualified Data.Text as T -import qualified Data.Text.IO as T import qualified Data.Text.Encoding as T import qualified Data.Vector as V import GitHub @@ -29,8 +28,6 @@ import qualified Text.Regex.Applicative.Text as RE import Text.Regex.Applicative.Text ((=~)) import Utils (UpdateEnv (..), Version) import qualified Utils as U -import System.IO.Temp (withSystemTempFile) -import System.IO (hFlush) default (T.Text) @@ -45,15 +42,13 @@ releaseUrl env url = do urlParts <- parseURL url gReleaseUrl (authFrom env) urlParts -pr :: MonadIO m => Text -> Text -> m () -pr base msg = do - liftIO $ withSystemTempFile - (T.unpack $ base <> "-prmsg") - (\fp handle -> do - T.hPutStr handle msg - hFlush handle - runProcess_ $ - proc "hub" ["pull-request", "-b", T.unpack base, "-F", fp]) +pr :: MonadIO m => UpdateEnv -> Text -> Text -> Text -> Text -> ExceptT Text m Text +pr env title body prHead base = do + ExceptT $ + bimap (T.pack . show) (getUrl . pullRequestUrl) + <$> (liftIO $ (github (authFrom env) + (createPullRequestR (N "nixos") (N "nixpkgs") + (CreatePullRequest title body prHead base)))) data URLParts = URLParts diff --git a/src/Update.hs b/src/Update.hs index f400768..5b7dfe6 100644 --- a/src/Update.hs +++ b/src/Update.hs @@ -347,7 +347,8 @@ publishPackage log updateEnv oldSrcUrl newSrcUrl attrPath result opDiff msgs = d if (isNothing opDiff || numPackageRebuilds (fromJust opDiff) < 100) then "master" else "staging" - lift $ GH.pr base prMsg + pullRequestUrl <- GH.pr updateEnv (prTitle updateEnv attrPath) prMsg ("r-ryantm:" <> (branchName updateEnv)) base + liftIO $ log pullRequestUrl else liftIO $ T.putStrLn prMsg commitMessage :: UpdateEnv -> Text -> Text