Skip to content

Conversation

@rudymatela
Copy link

@rudymatela rudymatela commented Jul 22, 2022

Fixes: #131

This reapplies the changes of #131 starting from a version where tests assure that Hoff is not stuck in an infinite comment loop. The summary of #131 still holds:

The changes in this PR do not change Hoff behaviour, the high level functionality should be the same.

Instead of maintaining a global candidate, we infer it from the state always. This is in preparation for merge trains (#77), where we will have multiple builds running in parallel and thus multiple candidates.

  • The ProjectState datatype is now simpler and easier to maintain (before we could risk it being inconsistent);
  • Some code paths are now simpler, as we don't have to do the work maintaining the global candidate;
  • There is a new explicit integration status Promoted to signify that the PR branch is now part of master, before this was signified by being Integrated ... BuildSucceeded but not being the global candidate.

A linear search on the number of open PRs is imposed. I believe this is not a problem because:

  • the number of PRs should be at most a few dozen, examples:
    • there are only 5 open PRs on channable/hoff currently;
    • a dozen open PRs seems to be a reasonable average (:wink:);
    • a busy project (:wink:) should have between 100 and 200 open PRs in which a linear search is still reasonable;
    • ... and we could still have way more than that without suffering significant performance impact (1000 or 10000 open PRs).
  • we already perform linear search for other operations, the candidate was just a special case in where we don't. If we were to actually get rid of linear search altogether, we perhaps should have a more generic solution that covers all cases. (If linear search were to be a problem, we would already be suffering from it.)
  • with Merge train #77, we are bound to perform a linear search on the candidate PRs anyway.

TODO

@rudymatela rudymatela self-assigned this Jul 22, 2022
@rudymatela rudymatela added bug Something isn't working enhancement New feature or request labels Jul 22, 2022
Base automatically changed from fix/comment-loop to master July 22, 2022 13:27
@rudymatela rudymatela force-pushed the merge-train/re-infer-candidate-from-state branch from 6d97c67 to a21b16e Compare July 22, 2022 14:01
@rudymatela
Copy link
Author

@alex-mckenna Since I am sort of restoring my previous changes now, I took the traversePullRequests function and your implementation of handleBuildStatusChanged from your (now-orphan) commit. This won't be merged soon, as I still need to fix the bug I caused.

... now the tests should catch the bug where Hoff is stuck in an infinite loop.

Revert "Revert "Merge #131: Merge train: infer candidate from state""

This reverts commit 0ef0478.
... in order to prepare for a future change.
@rudymatela rudymatela force-pushed the merge-train/re-infer-candidate-from-state branch from 66bf88c to 023df3b Compare July 22, 2022 15:04
@rudymatela rudymatela changed the base branch from master to test/pending-status-comment July 22, 2022 15:15
Base automatically changed from test/pending-status-comment to master July 26, 2022 06:57
This eliminates the need for the getIntegrationCandidate function
and simplifies test fixtures.
from the 'Project' module in favour of just using 'integratedPullRequests'.

The getIntegrationCandidates function was added to tests/Spec
as it has nice uses there.
... in order to detect that PRs are merged in the order of merge comments and
not by PR id.
@rudymatela rudymatela requested a review from fatho July 26, 2022 11:09
@rudymatela
Copy link
Author

@fatho You have previously reviewed #131, which was the PR that had the bug and was reverted. This PR re-adds the same functionality, so part of the code is the same as in the previous PR. I think it makes sense for you to review again in this case.

The end result is quite different in some parts, and the code of this new version is IMHO more elegant than the one of #131.

@rudymatela rudymatela marked this pull request as ready for review July 26, 2022 11:12
Copy link
Member

@fatho fatho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for adding the tests!

src/Logic.hs Outdated
BuildPending _ -> pure state
BuildSucceeded -> pushCandidate (pullRequestId, pullRequest) sha state
-- If the build failed, give feedback on the PR
BuildFailed _ -> pure $ Pr.setNeedsFeedback pullRequestId True state
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, so instead of always setting this to true when there's activity on a failed PR, we now only do this when the state initially changes?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Before, for a BuildFailed candidate:

  1. set PR build to failed when event is received
  2. go through the event loop
  3. in proceedCandidate, "discover" and set that the PR needs feedback
  4. go through the event loop again
  5. post comment (for the PR that needs feedback)

Now:

  1. set PR build to failed and that it needs feedback
  2. go through the event loop
  3. post comment (for the PR that needs feedback)

pr { Pr.integrationStatus = Integrated buildSha newStatus
, Pr.needsFeedback = case newStatus of
BuildPending (Just _) -> True
BuildFailed _ -> True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... (cont'd from previous comment), which would be here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, exactly. And we only need to post comments when we get the BuildPending status with a URL and when the build fails.

@rudymatela
Copy link
Author

@fatho Thanks for the review. I will merge this into master now and tag it so that I can have this ready for deploy at an appropriate time this week.

@OpsBotPrime merge

@OpsBotPrime
Copy link

Pull request approved for merge by @rudymatela, rebasing now.

Approved-by: rudymatela
Auto-deploy: false
@OpsBotPrime
Copy link

Rebased as 1bd9c99, waiting for CI …

@OpsBotPrime OpsBotPrime merged commit 1bd9c99 into master Jul 27, 2022
@OpsBotPrime OpsBotPrime deleted the merge-train/re-infer-candidate-from-state branch July 27, 2022 11:15
@rudymatela rudymatela mentioned this pull request Jul 28, 2022
43 tasks
@rudymatela rudymatela added the train Involves Merge Trains label Aug 18, 2022
@rudymatela rudymatela mentioned this pull request Aug 25, 2022
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request train Involves Merge Trains

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants