Skip to content
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

Merged

Conversation

keyonghan
Copy link
Contributor

@google-cla google-cla bot added the cla: yes label Dec 6, 2021
Comment on lines 73 to 78
final RegExp commitRegExp = RegExp(_regExpCommitMessage);
final RegExpMatch? match = commitRegExp.firstMatch(queryResult.message);
String? revertCommitSha;
if (match != null) {
revertCommitSha = match.namedGroup('revertCommitSha');
}
Copy link
Contributor Author

@keyonghan keyonghan Dec 6, 2021

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.

Copy link
Contributor

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

  1. The proposed revert PR diff: https://github.com/flutter/flutter/commit/86cb2598a3b683ebb7bdb9ed4ba6bb0b57424d05.patch
  2. 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.

Copy link
Contributor Author

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.

@keyonghan keyonghan force-pushed the ignore_checks_for_clean_revert branch 2 times, most recently from c3a495d to f710c3b Compare December 21, 2021 01:01
@keyonghan keyonghan requested a review from yusuf-goog January 4, 2022 20:09
@@ -90,6 +91,23 @@ class CheckForWaitingPullRequests extends ApiRequestHandler<Body> {
}
}

/// Check if the `commitSha` is a clean revert of TOT commit.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// 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).

Copy link
Contributor Author

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)) {
Copy link
Contributor

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

Copy link
Contributor Author

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 =
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: gitHub -> github

Copy link
Contributor Author

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
Copy link
Contributor

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 {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@keyonghan keyonghan force-pushed the ignore_checks_for_clean_revert branch from f710c3b to e1980d4 Compare January 11, 2022 00:15
Copy link
Contributor

@CaseyHillers CaseyHillers left a comment

Choose a reason for hiding this comment

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

flutter-lgtm

@keyonghan keyonghan added the waiting for tree to go green Merge PR when tree becomes green via fluttergithubbot label Jan 11, 2022
@fluttergithubbot fluttergithubbot merged commit 2d9f276 into flutter:main Jan 11, 2022
@keyonghan keyonghan deleted the ignore_checks_for_clean_revert branch March 13, 2024 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for tree to go green Merge PR when tree becomes green via fluttergithubbot
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants