-
-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: check for existing updates with same src url #316
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -201,23 +201,34 @@ authFromToken = GH.OAuth . T.encodeUtf8 | |
authFrom :: UpdateEnv -> GH.Auth | ||
authFrom = authFromToken . U.githubToken . options | ||
|
||
checkExistingUpdatePR :: MonadIO m => UpdateEnv -> Text -> ExceptT Text m () | ||
checkExistingUpdatePR env attrPath = do | ||
checkExistingUpdatePR :: MonadIO m => UpdateEnv -> Text -> Text -> ExceptT Text m () | ||
checkExistingUpdatePR env attrPath srcUrl = do | ||
searchResult <- | ||
ExceptT $ | ||
liftIO $ | ||
GH.github (authFrom env) (GH.searchIssuesR search) | ||
& fmap (first (T.pack . show)) | ||
if T.length (openPRReport searchResult) == 0 | ||
then return () | ||
else | ||
throwE | ||
( "There might already be an open PR for this update:\n" | ||
<> openPRReport searchResult | ||
) | ||
when (T.length (openPRReport searchResult) /= 0) | ||
(throwE | ||
( "There might already be an open PR for this update:\n" | ||
<> openPRReport searchResult)) | ||
|
||
srcUrlSearchResult <- | ||
ExceptT $ | ||
liftIO $ | ||
GH.github (authFrom env) (GH.searchIssuesR srcUrlSearch) | ||
& fmap (first (T.pack . show)) | ||
|
||
when (srcUrl /= T.empty && T.length (openPRReport srcUrlSearchResult) /= 0) | ||
(throwE | ||
( "There might already be an open PR for this update:\n" | ||
<> openPRReport searchResult)) | ||
|
||
return () | ||
where | ||
title = U.prTitle env attrPath | ||
search = [interpolate|repo:nixos/nixpkgs $title |] | ||
srcUrlSearch = [interpolate|new src url: $srcUrl |] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs a |
||
openPRReport searchResult = | ||
GH.searchResultResults searchResult | ||
& V.filter (GH.issueClosedAt >>> isNothing) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -247,8 +247,9 @@ checkExistingUpdate :: | |
UpdateEnv -> | ||
Maybe Text -> | ||
Text -> | ||
Text -> | ||
ExceptT Text IO () | ||
checkExistingUpdate log updateEnv existingCommitMsg attrPath = do | ||
checkExistingUpdate log updateEnv existingCommitMsg srcUrl attrPath = do | ||
case existingCommitMsg of | ||
Nothing -> lift $ log "No auto update branch exists" | ||
Just msg -> do | ||
|
@@ -263,7 +264,7 @@ checkExistingUpdate log updateEnv existingCommitMsg attrPath = do | |
-- 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 | ||
-- if this run updates the package to a newer version. | ||
GH.checkExistingUpdatePR updateEnv attrPath | ||
GH.checkExistingUpdatePR updateEnv attrPath srcUrl | ||
|
||
updateAttrPath :: | ||
(Text -> IO ()) -> | ||
|
@@ -277,6 +278,7 @@ updateAttrPath log mergeBase updateEnv@UpdateEnv {..} attrPath = do | |
|
||
successOrFailure <- runExceptT $ do | ||
hasUpdateScript <- Nix.hasUpdateScript attrPath | ||
oldSrcUrl <- Nix.getSrcUrl attrPath <|> pure "" | ||
|
||
existingCommitMsg <- fmap getAlt . execWriterT $ | ||
whenBatch updateEnv do | ||
|
@@ -286,7 +288,7 @@ updateAttrPath log mergeBase updateEnv@UpdateEnv {..} attrPath = do | |
mbLastCommitMsg <- lift $ Git.findAutoUpdateBranchMessage packageName | ||
tell $ Alt mbLastCommitMsg | ||
unless hasUpdateScript do | ||
lift $ checkExistingUpdate log updateEnv mbLastCommitMsg attrPath | ||
lift $ checkExistingUpdate log updateEnv mbLastCommitMsg attrPath oldSrcUrl | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't look right to me—checking for open PRs that target the old src seems useless at best. I figure we want to do this new check after the rewrites have run in both the |
||
|
||
unless hasUpdateScript do | ||
Nix.assertNewerVersion updateEnv | ||
|
@@ -310,7 +312,6 @@ updateAttrPath log mergeBase updateEnv@UpdateEnv {..} attrPath = do | |
-- Get the original values for diffing purposes | ||
derivationContents <- liftIO $ T.readFile $ T.unpack derivationFile | ||
oldHash <- Nix.getOldHash attrPath <|> pure "" | ||
oldSrcUrl <- Nix.getSrcUrl attrPath <|> pure "" | ||
oldRev <- Nix.getAttr Nix.Raw "rev" attrPath <|> pure "" | ||
oldVerMay <- rightMay `fmapRT` (lift $ runExceptT $ Nix.getAttr Nix.Raw "version" attrPath) | ||
|
||
|
@@ -379,17 +380,18 @@ updateAttrPath log mergeBase updateEnv@UpdateEnv {..} attrPath = do | |
assertNotUpdatedOn updateEnv' derivationFile "master" | ||
assertNotUpdatedOn updateEnv' derivationFile "staging" | ||
assertNotUpdatedOn updateEnv' derivationFile "staging-next" | ||
|
||
whenBatch updateEnv do | ||
when pr do | ||
when hasUpdateScript do | ||
checkExistingUpdate log updateEnv' existingCommitMsg attrPath | ||
checkExistingUpdate log updateEnv' existingCommitMsg attrPath newSrcUrl | ||
|
||
Nix.build attrPath | ||
|
||
-- | ||
-- Publish the result | ||
lift . log $ "Successfully finished processing" | ||
result <- Nix.resultLink | ||
result <- Nix.resultLink | ||
let opReport = | ||
if isJust skipOutpathBase | ||
then "Outpath calculations were skipped for this package; total number of rebuilds unknown." | ||
|
@@ -455,6 +457,7 @@ publishPackage log updateEnv oldSrcUrl newSrcUrl attrPath result opReport prBase | |
metaDescription | ||
metaHomepage | ||
metaChangelog | ||
newSrcUrl | ||
rewriteMsgs | ||
releaseUrl | ||
compareUrl | ||
|
@@ -494,6 +497,7 @@ prMessage :: | |
Text -> | ||
Text -> | ||
Text -> | ||
Text -> | ||
[Text] -> | ||
Text -> | ||
Text -> | ||
|
@@ -507,7 +511,7 @@ prMessage :: | |
Text -> | ||
Text -> | ||
Text | ||
prMessage updateEnv isBroken metaDescription metaHomepage metaChangelog rewriteMsgs releaseUrl compareUrl resultCheckReport commitRev attrPath maintainers resultPath opReport cveRep cachixTestInstructions nixpkgsReviewMsg = | ||
prMessage updateEnv isBroken metaDescription metaHomepage metaChangelog newSrcUrl rewriteMsgs releaseUrl compareUrl resultCheckReport commitRev attrPath maintainers resultPath opReport cveRep cachixTestInstructions nixpkgsReviewMsg = | ||
-- Some components of the PR description are pre-generated prior to calling | ||
-- because they require IO, but in general try to put as much as possible for | ||
-- the formatting into the pure function so that we can control the body | ||
|
@@ -538,6 +542,8 @@ prMessage updateEnv isBroken metaDescription metaHomepage metaChangelog rewriteM | |
if compareUrl == T.empty | ||
then "" | ||
else "- [Compare changes on GitHub](" <> compareUrl <> ")" | ||
-- Needed for search of existing PRs | ||
newSrcUrlLine = "- new src url: " <> newSrcUrl | ||
nixpkgsReviewSection = | ||
if nixpkgsReviewMsg == T.empty | ||
then "NixPkgs review skipped" | ||
|
@@ -571,6 +577,8 @@ prMessage updateEnv isBroken metaDescription metaHomepage metaChangelog rewriteM | |
|
||
###### To inspect upstream changes | ||
|
||
$newSrcUrlLine | ||
|
||
$releaseUrlMessage | ||
|
||
$compareUrlMessage | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.