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 Skiplist
import qualified Time import qualified Time
import Utils import Utils
( Options (..), ( Boundary (..),
Options (..),
URL, URL,
UpdateEnv (..), UpdateEnv (..),
Version, Version,
VersionMatcher (..),
branchName, branchName,
logDir, logDir,
parseUpdates, parseUpdates,
@ -256,9 +258,11 @@ checkExistingUpdate log updateEnv existingCommitMsg attrPath = do
lift $ log lift $ log
[interpolate|An auto update branch exists with message `$msg`. New version is $nV.|] [interpolate|An auto update branch exists with message `$msg`. New version is $nV.|]
if U.titleTargetsSameVersion updateEnv msg case U.titleVersion msg of
then throwError "An auto update branch exists targeting the same version" Just branchV | Version.matchVersion (RangeMatcher (Including nV) Unbounded) branchV ->
else lift $ log "The auto update branch does not match the new version." 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 -- 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 -- version numbers, so it won't stop us from updating an existing PR

View File

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

View File

@ -10,10 +10,20 @@ main = hspec spec
spec :: Spec spec :: Spec
spec = do 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 describe "PR title" do
-- This breaks IRC when it tries to link to newly opened pull requests -- This breaks IRC when it tries to link to newly opened pull requests
it "should not include a trailing newline" do 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" let title = Utils.prTitle updateEnv "python37Packages.foobar"
title `shouldBe` "python37Packages.foobar: 1.0 -> 1.1" 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