-
Notifications
You must be signed in to change notification settings - Fork 104
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
Merge a clean revert without waiting for checks #1498
Merge a clean revert without waiting for checks #1498
Conversation
final RegExp commitRegExp = RegExp(_regExpCommitMessage); | ||
final RegExpMatch? match = commitRegExp.firstMatch(queryResult.message); | ||
String? revertCommitSha; | ||
if (match != null) { | ||
revertCommitSha = match.namedGroup('revertCommitSha'); | ||
} |
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.
Github doesn't treat revert PR/commit separately, and there is not a simple mapping between the revert and the to-be-reverted commit.
Checked recent reverts, and all are with the default commit message which includes the to-be-reverted commit sha
info. (this is what is proposed here).
Another more stable way is use git diff between the current revert commit and the second TOT commit: if diff is zero, then we can conclude the current revert is based on the TOT commit. Filed SpinlockLabs/github.dart#283 to request support on git diff comparison.
Please advise if any better ways.
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.
With flutter/flutter@86cb259 as an example,
Cocoon could grab
- The proposed revert PR diff: https://github.com/flutter/flutter/commit/86cb2598a3b683ebb7bdb9ed4ba6bb0b57424d05.patch
- The tip of tree commit diff: https://github.com/flutter/flutter/commit/9412edf1ca69121fe733160e22bc48131e7a3fcd.patch
It can then split the lines of each, and for each line that starts with +
or -
add it to a map. When going through the second diff, it can reverse the operator and remove it from the map. If the map has any keys remaining, it's not a pure revert and should be skipped.
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.
https://docs.github.com/en/rest/reference/commits#compare-two-commits does exactly the same thing. It sounds a re-implementation of this API. Submitted SpinlockLabs/github.dart#285 to support the files
field so that we can use this API.
This is the diff result of a revert commit: flutter/flutter@9d2bf91 and the second tot commit: 86d229dc399136aa7a0b3935f723ffa1289217f8
https://api.github.com/repos/flutter/flutter/compare/86d229dc399136aa7a0b3935f723ffa1289217f8...9d2bf9140499984aff7d78145029cfc2a39a762d, where the empty files
field validates this is a clean revert.
c3a495d
to
f710c3b
Compare
@@ -90,6 +91,23 @@ class CheckForWaitingPullRequests extends ApiRequestHandler<Body> { | |||
} | |||
} | |||
|
|||
/// Check if the `commitSha` is a clean revert of TOT commit. |
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.
/// Check if the `commitSha` is a clean revert of TOT commit. | |
/// Check if the `commitSha` is a clean revert of Tip Of Tree commit (TOT). |
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.
Done
@@ -67,7 +67,8 @@ class CheckForWaitingPullRequests extends ApiRequestHandler<Body> { | |||
); | |||
final List<_AutoMergeQueryResult> queryResults = await _parseQueryData(data, slug.name); | |||
for (_AutoMergeQueryResult queryResult in queryResults) { | |||
if (mergeCount < _kMergeCountPerCycle && queryResult.shouldMerge) { | |||
// If the PR is a revert of the tot commit, merge without waiting for checks passing. | |||
if (mergeCount < _kMergeCountPerCycle && queryResult.shouldMerge || await isTOTRevert(queryResult.sha, slug)) { |
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.
Could we simplify this? Maybe exit early by checking _kMergeCountPerCycle < mergeCount
and add a helper function
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.
Added a helper function to make it clear.
final RepositoryCommit secondTotCommit = await github.repositories.getCommit(slug, 'HEAD~'); | ||
log.info('Current commit is: $commitSha'); | ||
log.info('Second TOT commit is: ${secondTotCommit.sha}'); | ||
final GitHubComparison gitHubComparison = |
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.
nit: gitHub -> github
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.
Done
@@ -19,7 +19,7 @@ dependencies: | |||
file: ^6.1.2 | |||
fixnum: ^1.0.0 | |||
gcloud: ^0.8.4 | |||
github: ^8.2.4 | |||
github: ^8.3.0 |
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.
Nice! Thanks for upstreaming this logic
@@ -362,6 +387,34 @@ void main() { | |||
]); | |||
}); | |||
|
|||
test('Merge a clean revert PR with in progress tests', () async { |
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.
Can we add a test for a non-clean revert?
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.
Please see githubComparison = GitHubComparison('abc', 'def', 0, 0, 0, <CommitFile>[CommitFile(name: 'test')]);
in other tests, which is mocking the non-clean revert cases.
f710c3b
to
e1980d4
Compare
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.
flutter/flutter#94592