Skip to content
Permalink
Browse files
912: PR title correction logic can get stuck
Reviewed-by: rwestberg
  • Loading branch information
magicus committed Mar 12, 2021
1 parent edb217f commit e664a653ca8a5bf2d92080c65e5177fddc2e4dad
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 15 deletions.
@@ -172,7 +172,7 @@ private static String fetchCommand(PullRequest pr) {
static String composeConversation(PullRequest pr) {
var filteredBody = filterCommentsAndCommands(pr.body());
if (filteredBody.isEmpty()) {
filteredBody = pr.title().strip();
filteredBody = pr.title();
}

return filteredBody;
@@ -174,7 +174,7 @@ private boolean updateTitle() {
if (title.isEmpty()) {
// If the title is in the form of "[project-]<bugid>" only
// we add the title from JBS
var newPrTitle = id + ": " + issue.get().title();
var newPrTitle = id + ": " + issueTitle;
pr.setTitle(newPrTitle);
return true;
} else {
@@ -184,9 +184,9 @@ private boolean updateTitle() {
title = title.substring(0, title.length() - 1);
}
if (issueTitle.startsWith(title) && issueTitle.length() > title.length()) {
var newPrTitle = id + ": " + issue.get().title();
var newPrTitle = id + ": " + issueTitle;
pr.setTitle(newPrTitle);
var remainingTitle = issue.get().title().substring(title.length());
var remainingTitle = issueTitle.substring(title.length());
if (pr.body().startsWith(ELLIPSIS + remainingTitle + "\n\n")) {
// Remove remaning title, plus decorations
var newPrBody = pr.body().substring(remainingTitle.length() + 3);
@@ -909,6 +909,7 @@ void issueTitleCutOff(TestInfo testInfo) throws IOException {
var masterHash = localRepo.resolve("master").orElseThrow();
localRepo.push(masterHash, author.url(), "master", true);

// Verify that a cut-off title is corrected
var issue1 = issues.createIssue("My first issue with a very long title that is going to be cut off by the Git Forge provider", List.of("Hello"), Map.of());

// Make a change with a corresponding PR
@@ -932,6 +933,21 @@ void issueTitleCutOff(TestInfo testInfo) throws IOException {
assertEquals("1: My first issue with a very long title that is going to be cut off by the Git Forge provider", prCutOff.title());
// And the body should not contain the issue title
assertTrue(prCutOff.body().startsWith("It also has a second line!"));

// Verify that trailing space in issue is ignored
var issue2 = issues.createIssue("My second issue ending in space ", List.of("Hello"), Map.of());

// Make a change with a corresponding PR
var editHash2 = CheckableRepository.appendAndCommit(localRepo);
localRepo.push(editHash2, author.url(), "edit", true);

var prCutOff2 = credentials.createPullRequest(author, "master", "edit", issue2.id() + ": My second issue ending in space", List.of(), false);

// Check the status
TestBotRunner.runPeriodicItems(checkBot);

// The PR title should contain the issue title without trailing space
assertEquals("TEST-2: My second issue ending in space", prCutOff2.title());
}
}

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -306,7 +306,7 @@ public String targetRef() {

@Override
public String title() {
return json.get("title").asString();
return json.get("title").asString().strip();
}

@Override
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -329,7 +329,7 @@ public String targetRef() {

@Override
public String title() {
return json.get("title").asString();
return json.get("title").asString().strip();
}

@Override
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -49,7 +49,7 @@ public interface Issue {
HostUser author();

/**
* Title of the request.
* Title of the request. The implementation should make sure it is stripped.
* @return
*/
String title();
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -72,7 +72,7 @@ public HostUser author() {

@Override
public String title() {
return json.get("fields").get("summary").asString();
return json.get("fields").get("summary").asString().strip();
}

@Override
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -77,12 +77,13 @@ public HostUser author() {

@Override
public String title() {
return data.title;
return data.title.strip();
}

@Override
public void setTitle(String title) {
data.title = title;
// the strip simulates gitlab behavior
data.title = title.strip();
data.lastUpdate = ZonedDateTime.now();
}

1 comment on commit e664a65

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on e664a65 Mar 12, 2021

Choose a reason for hiding this comment

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

Please sign in to comment.