Abort if existing PR targets newer version

This commit is contained in:
Ryan Hendrickson 2022-09-03 18:55:11 -04:00
parent ec0092589a
commit 0d8c37c2ec
3 changed files with 24 additions and 10 deletions

View File

@ -44,10 +44,12 @@ import qualified Rewrite
import qualified Skiplist
import qualified Time
import Utils
( Options (..),
( Boundary (..),
Options (..),
URL,
UpdateEnv (..),
Version,
VersionMatcher (..),
branchName,
logDir,
parseUpdates,
@ -256,9 +258,11 @@ checkExistingUpdate log updateEnv existingCommitMsg attrPath = do
lift $ log
[interpolate|An auto update branch exists with message `$msg`. New version is $nV.|]
if U.titleTargetsSameVersion updateEnv msg
then throwError "An auto update branch exists targeting the same version"
else lift $ log "The auto update branch does not match the new version."
case U.titleVersion msg of
Just branchV | Version.matchVersion (RangeMatcher (Including nV) Unbounded) branchV ->
throwError "An auto update branch exists with an equal or greater version"
_ ->
lift $ log "The auto update branch does not match or exceed the new version."
-- Note that this check looks for PRs with the same old and new
-- version numbers, so it won't stop us from updating an existing PR

View File

@ -23,7 +23,7 @@ module Utils
runLog,
srcOrMain,
stripQuotes,
titleTargetsSameVersion,
titleVersion,
whenBatch,
regDirMode,
outpathCacheDir,
@ -135,10 +135,10 @@ prTitle updateEnv attrPath =
nV = newVersion updateEnv
in T.strip [interpolate| $attrPath: $oV -> $nV |]
titleTargetsSameVersion :: UpdateEnv -> Text -> Bool
titleTargetsSameVersion updateEnv = T.isSuffixOf [interpolate| -> $nV |]
titleVersion :: Text -> Maybe Version
titleVersion title = if T.null prefix then Nothing else Just suffix
where
nV = newVersion updateEnv
(prefix, suffix) = T.breakOnEnd " -> " title
regDirMode :: FileMode
regDirMode =

View File

@ -10,10 +10,20 @@ main = hspec spec
spec :: Spec
spec = do
let options = Utils.Options False False "" "" False False False False
let updateEnv = Utils.UpdateEnv "foobar" "1.0" "1.1" (Just "https://update-site.com") options
describe "PR title" do
-- This breaks IRC when it tries to link to newly opened pull requests
it "should not include a trailing newline" do
let options = Utils.Options False False "" "" False False False False
let updateEnv = Utils.UpdateEnv "foobar" "1.0" "1.1" (Just "https://update-site.com") options
let title = Utils.prTitle updateEnv "python37Packages.foobar"
title `shouldBe` "python37Packages.foobar: 1.0 -> 1.1"
describe "titleVersion" do
it "should parse prTitle output" do
let title = Utils.prTitle updateEnv "python37Packages.foobar"
let version = Utils.titleVersion title
version `shouldBe` Just "1.1"
it "should fail on unexpected commit messages" do
let version = Utils.titleVersion "not a prTitle-style commit message"
version `shouldBe` Nothing