Skip to content

Commit

Permalink
add check for already open duplicate PRs
Browse files Browse the repository at this point in the history
  • Loading branch information
ryantm committed May 3, 2019
1 parent 5073029 commit ba2fef5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/GH.hs
@@ -1,4 +1,5 @@
{-# LANGUAGE ExtendedDefaultRules #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# OPTIONS_GHC -fno-warn-type-defaults #-}
Expand All @@ -10,6 +11,7 @@ module GH
, closedAutoUpdateRefs
, openPullRequests
, openAutoUpdatePR
, checkExistingUpdatePR
) where

import OurPrelude
Expand All @@ -22,6 +24,7 @@ import GitHub
import GitHub.Data.Name (Name(..), untagName)
import GitHub.Endpoints.GitData.References (references')
import GitHub.Endpoints.Repos.Releases (releaseByTagName)
import GitHub.Endpoints.Search (searchIssues')
import Shelly hiding (tag)
import qualified Text.Regex.Applicative.Text as RE
import Text.Regex.Applicative.Text ((=~))
Expand Down Expand Up @@ -129,6 +132,7 @@ closedAutoUpdateRefs o =
aur :: Vector Text <- ExceptT $ autoUpdateRefs o
ExceptT (Right <$> V.filterM (refShouldBeDeleted o) aur)

-- This is too slow
openPullRequests :: Options -> IO (Either Text (Vector SimplePullRequest))
openPullRequests o =
executeRequest
Expand All @@ -137,10 +141,32 @@ openPullRequests o =
fmap (first (T.pack . show))

openAutoUpdatePR :: UpdateEnv -> Vector SimplePullRequest -> Bool
openAutoUpdatePR updateEnv openPRs = openPRs & (V.find isThisPkg >>> isJust)
openAutoUpdatePR updateEnv oprs = oprs & (V.find isThisPkg >>> isJust)
where
isThisPkg simplePullRequest =
let title = simplePullRequestTitle simplePullRequest
titleHasName = (packageName updateEnv <> ":") `T.isPrefixOf` title
titleHasNewVersion = newVersion updateEnv `T.isSuffixOf` title
in titleHasName && titleHasNewVersion

checkExistingUpdatePR :: MonadIO m => UpdateEnv -> ExceptT Text m ()
checkExistingUpdatePR ue = do
searchResult <-
ExceptT $
liftIO $
searchIssues'
(Just (OAuth (T.encodeUtf8 (githubToken (options ue)))))
search &
fmap (first (T.pack . show))
when
(anyOpen searchResult)
(throwE "There is already an open PR for this update")
where
pn = packageName ue
ov = oldVersion ue
nv = newVersion ue
search = [interpolate|repo:nixos/nixpkgs $pn $ov -> $nv |]
anyOpen searchResult =
any
(\issue -> isNothing (issueClosedAt issue))
(searchResultResults searchResult)
1 change: 1 addition & 0 deletions src/Update.hs
Expand Up @@ -112,6 +112,7 @@ updatePackage log updateEnv mergeBaseOutpathsContext =
Nix.assertNewerVersion updateEnv
Git.fetchIfStale <|> liftIO (T.putStrLn "Failed to fetch.")
Git.checkAutoUpdateBranchDoesntExist (packageName updateEnv)
GH.checkExistingUpdatePR updateEnv
Git.cleanAndResetTo "master"
attrPath <- Nix.lookupAttrPath updateEnv
Blacklist.attrPath attrPath
Expand Down

0 comments on commit ba2fef5

Please sign in to comment.