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

912: PR title correction logic can get stuck #1050

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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();
}