RFR: 1495: /backport on PRs instead of commits should inform of proper usage [v2]

Guoxiong Li gli at openjdk.org
Thu Jul 28 13:09:26 UTC 2022

On Wed, 27 Jul 2022 13:35:38 GMT, Erik Joelsson <erikj at openjdk.org> wrote:

>> Guoxiong Li has updated the pull request incrementally with one additional commit since the last revision:
>>   Fix NPE.
> bots/notify/src/main/java/org/openjdk/skara/bots/notify/PullRequestWorkItem.java line 187:
>> 185: 
>> 186:         var issues = parseIssues();
>> 187:         var commit = integratorId != null ? pr.findIntegratedCommitHash(List.of(integratorId)).orElse(null) : null;
> Consider keeping the resultingCommitHash() method with the current signature and have it wrap the new pr.findIntegratedCommitHash(), doing the null checks and conversions there instead. I think that will make the code more readable.


> bots/pr/src/main/java/org/openjdk/skara/bots/pr/BackportCommand.java line 58:
>> 56:     public void handle(PullRequestBot bot, PullRequest pr, CensusInstance censusInstance, Path scratchPath,
>> 57:                 CommandInvocation command, List<Comment> allComments, PrintWriter reply) {
>> 58:         reply.println("The command `backport` can not be used in a pull request that has not yet been integrated.");
> Shouldn't the message here be the one suggested in the Bug?
> "(!) You cannot issue `/backport` on a pull request. Instead, give that command on the actual commit you want to backport."

I want the`/backport` command can be used in the PRs which hava been integrated. So the message `You cannot issue /backport on a pull request` seems not accurate. But the current message seems not accurate too. Looking for a better description and your idea.

>  In what situation would it be wrong to just use one unified list?

The only one situation I concern about is the `help` command. But after second thought, it looks good. So I unified them.

> bots/pr/src/main/java/org/openjdk/skara/bots/pr/PullRequestCommandWorkItem.java line 43:
>> 41:     private static final Pattern commandReplyPattern = Pattern.compile("<!-- Jmerge command reply message \\((\\S+)\\) -->");
>> 42: 
>> 43:     static final Map<String, CommandHandler> commandHandlers = Map.ofEntries(
> Instead of making these package private and adding the convoluted logic in extractCommands, can't we just add BackportCommand to the commandHandlers for PullRequestWorkItem?
> It seems like the original author mixed two ways of separating commands between PRs and commits, both through these handler lists, and through the allowedIn* methods. If we really want to improve all the error messages, then all commands should be added to both lists, or maybe the lists should be unified into one.

I unified these two lists into one and put it in class `CommandExtractor`. All the tests in PR bot passed locally.

> bots/pr/src/main/java/org/openjdk/skara/bots/pr/PullRequestCommandWorkItem.java line 174:
>> 172:             if (isCommit) {
>> 173:                 if (handler.get().allowedInCommit()) {
>> 174:                     var hash = pr.findIntegratedCommitHash();
> It's worth noting that this will trigger a new `comments()` call to the forge instead of reusing the existing list of comments.

Yes, it is a tradeoff between code concision and the running time. If we find the code becomes slower in the future and want to optimize it, this is a good place to optimize. But now we can keep it because we want to refactor the method in this PR.

And the method `pr.findIntegratedCommitHash` always get the newest comments so it may avoid some issues that the `Pushed as ...` comment is added during processing command. But I am not really know whether this situation would happen.

> bots/pr/src/main/java/org/openjdk/skara/bots/pr/PullRequestCommandWorkItem.java line 205:
>> 203:                     printer.print("The command `");
>> 204:                     printer.print(command.name());
>> 205:                     printer.println("` can not be used in pull requests. Please try to use this command on the commit.");
> I don't think we need to suggest using the command on a commit in the general case.
> Suggestion:
>                     printer.println("` cannot be used in pull requests.");


> forge/src/main/java/org/openjdk/skara/forge/PullRequest.java line 189:
>> 187: 
>> 188:     default Optional<Hash> findIntegratedCommitHash(List<String> userIds) {
>> 189:         Pattern pushedPattern = Pattern.compile("Pushed as commit ([a-f0-9]{40})\\.");
> If you are moving this pattern from the bots modules to this class, then I think you should also move the comment logic from IntegrateCommand here so that both the creation and parsing of this kind of comment is handled at the same level. It seems bad to have PullRequest know about what special comments the IntegrateCommand happens to add.

What about adding a parameter like `Pattern commitComment` to the method `findIntegratedCommitHash`?


PR: https://git.openjdk.org/skara/pull/1341

More information about the skara-dev mailing list