#99 - Extract ticket references from Git commits.

This commit is contained in:
Mark Paluch
2020-11-09 16:07:09 +01:00
parent b01be2b5ca
commit c0b10e547d
15 changed files with 944 additions and 24 deletions

View File

@@ -23,17 +23,24 @@ import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.internal.storage.file.FileRepository;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.revwalk.RevCommit;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.release.AbstractIntegrationTests;
import org.springframework.data.release.model.Iteration;
import org.springframework.data.release.model.ReleaseTrains;
import org.springframework.data.release.model.TestReleaseTrains;
import org.springframework.data.release.model.TrainIteration;
/**
* @author Oliver Gierke
* @author Mark Paluch
*/
@Disabled
class GitOperationsIntegrationTests extends AbstractIntegrationTests {
@@ -75,4 +82,49 @@ class GitOperationsIntegrationTests extends AbstractIntegrationTests {
void obtainsVersionTagsForRepoThatAlsoHasOtherTags() {
gitOperations.getTags(MONGO_DB);
}
@Test
void shouldDeterminePreviousIterationFromGA() throws Exception {
TrainIteration hopperRc1 = gitOperations.getPreviousIteration(ReleaseTrains.HOPPER.getIteration(Iteration.GA));
assertThat(hopperRc1.getTrain()).isEqualTo(ReleaseTrains.HOPPER);
assertThat(hopperRc1.getIteration()).isEqualTo(Iteration.RC1);
TrainIteration hopperM1 = gitOperations.getPreviousIteration(ReleaseTrains.HOPPER.getIteration(Iteration.RC1));
assertThat(hopperM1.getTrain()).isEqualTo(ReleaseTrains.HOPPER);
assertThat(hopperM1.getIteration()).isEqualTo(Iteration.M1);
TrainIteration hopperSR9 = gitOperations.getPreviousIteration(ReleaseTrains.HOPPER.getIteration(Iteration.SR10));
assertThat(hopperSR9.getTrain()).isEqualTo(ReleaseTrains.HOPPER);
assertThat(hopperSR9.getIteration()).isEqualTo(Iteration.SR9);
}
@Test
void verify() throws Exception {
// gitOperations.update(ReleaseTrains.HOPPER);
try (Git git = new Git(new FileRepository("/Users/mpaluch/git/data/spring-data-elasticsearch/.git"))) {
ObjectId resolve = git.getRepository().parseCommit(git.getRepository().resolve("3.0.0.RELEASE"));
Iterable<RevCommit> master = git.log().addRange(resolve, git.getRepository().resolve("master")).call();
for (RevCommit revCommit : master) {
ParsedCommitMessage message = ParsedCommitMessage.parse(revCommit.getFullMessage());
if (message.getTicketReference() == null || message.getSummary() == null) {
System.out.println(revCommit.getFullMessage());
System.out.println();
}
}
} catch (Exception o_O) {
throw new RuntimeException(o_O);
}
}
}

View File

@@ -0,0 +1,102 @@
/*
* Copyright 2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.release.git;
import static org.assertj.core.api.Assertions.*;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
/**
* Unit tests for {@link ParsedCommitMessage}.
*
* @author Mark Paluch
*/
class ParsedCommitMessageUnitTests {
@Test
void shouldParsePlainCommit() {
ParsedCommitMessage commit = ParsedCommitMessage.parse("hello world");
assertThat(commit.getSummary()).isEqualTo("hello world");
assertThat(commit.getBody()).isNull();
}
@ParameterizedTest
@ValueSource(strings = { "DATAFOO-123 - Hello World.", "DATAFOO-123 Hello World.", "[DATAFOO-123] - Hello World.",
"DATAFOO - 123 - Hello World." })
void shouldParseOneLinerCommitWithJiraTicket(String commitMessage) {
ParsedCommitMessage commit = ParsedCommitMessage.parse(commitMessage);
assertThat(commit.getSummary()).endsWith("Hello World.");
assertThat(commit.getTicketReference().getId()).isEqualTo("DATAFOO-123");
}
@Test
void considersMultipleTicketsAsRelatedTickets() {
ParsedCommitMessage commit = ParsedCommitMessage
.parse("Polishing\n\nAdd tests for write and delete.\n\nCloses gh-503\nCloses gh-511");
assertThat(commit.getTicketReference().getId()).isEqualTo("#503");
assertThat(commit.getRelatedTickets()).hasSize(1);
assertThat(commit.getRelatedTickets().get(0).getId()).isEqualTo("#511");
}
@ParameterizedTest
@ValueSource(strings = { "close", "closes", "closed", "fix", "fixes", "fixed", "resolve", "resolves", "resolved" })
void considersResolvesSyntax(String prefix) {
ParsedCommitMessage commit = ParsedCommitMessage.parse("Polishing\n\n" + prefix + " gh-586.");
assertThat(commit.getTicketReference().getId()).isEqualTo("#586");
}
@ParameterizedTest
@ValueSource(strings = { "Incorporate review feedback\n\nSee gh-574." })
void shouldParseCommitWithSeeTicket(String commitMessage) {
ParsedCommitMessage commit = ParsedCommitMessage.parse(commitMessage);
assertThat(commit.getSummary()).isEqualTo("Incorporate review feedback");
assertThat(commit.getTicketReference().getId()).isEqualTo("#574");
}
@Test
void shouldParseCommitWithRelatedTickets() {
ParsedCommitMessage commit = ParsedCommitMessage
.parse("DATAFOO-123 - Hello World.\n Related tickets: DATACMNS-1438, DATACMNS-1461, DATACMNS-1609.");
assertThat(commit.getTicketReference().getId()).isEqualTo("DATAFOO-123");
assertThat(commit.getRelatedTickets()).hasSize(3);
}
@ParameterizedTest
@ValueSource(strings = { "DATAFOO-456 - Hello World.\n Original pull request: #415.",
"DATAFOO-456 - Hello World.\n Original pr: #415." })
void shouldParseCommitWithPullRequest(String commitMessage) {
ParsedCommitMessage commit = ParsedCommitMessage.parse(commitMessage);
assertThat(commit.getTicketReference().getId()).isEqualTo("DATAFOO-456");
assertThat(commit.getPullRequestReference()).isNotNull();
assertThat(commit.getPullRequestReference().getId()).isEqualTo("#415");
}
}

View File

@@ -0,0 +1,57 @@
/*
* Copyright 2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.release.git;
import static org.assertj.core.api.Assertions.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
import org.springframework.data.release.model.Iteration;
import org.springframework.data.release.model.Projects;
import org.springframework.data.release.model.ReleaseTrains;
/**
* Unit tests for {@link VersionTags}.
*
* @author Mark Paluch
*/
class VersionTagsUnitTests {
@Test
void shouldDetermineTagForIteration() {
VersionTags tags = new VersionTags(Projects.NEO4J,
Stream.of("5.3.0.RELEASE", "5.4.0-M1", "6.0.0-M2").map(Tag::of).collect(Collectors.toList()));
assertThat(tags.filter(ReleaseTrains.NEUMANN).findTag(Iteration.GA))
.hasValueSatisfying(actual -> assertThat(actual.getName()).isEqualTo("5.3.0.RELEASE"));
assertThat(tags.filter(ReleaseTrains.OCKHAM).findTag(Iteration.M2))
.hasValueSatisfying(actual -> assertThat(actual.getName()).isEqualTo("6.0.0-M2"));
}
@Test
void shouldDetermineTagForMajorVersionBumpDuringDevelopment() {
VersionTags tags = new VersionTags(Projects.NEO4J,
Stream.of("5.3.0.RELEASE", "5.4.0-M1", "6.0.0-M2").map(Tag::of).collect(Collectors.toList()));
assertThat(tags.filter(ReleaseTrains.OCKHAM).findTag(Iteration.M1))
.hasValueSatisfying(actual -> assertThat(actual.getName()).isEqualTo("5.4.0-M1"));
}
}

View File

@@ -47,4 +47,23 @@ class TrainsUnitTest {
assertThat(ReleaseTrains.PASCAL.getModule(Projects.BOM).getVersion().toMajorMinorBugfix()).isEqualTo("2021.0.0");
}
@Test
void beforeShouldConsiderNonCalver() {
assertThat(ReleaseTrains.HOPPER.isBefore(ReleaseTrains.GOSLING)).isFalse();
assertThat(ReleaseTrains.HOPPER.isBefore(ReleaseTrains.INGALLS)).isTrue();
}
@Test
void beforeShouldConsiderCalver() {
assertThat(ReleaseTrains.PASCAL.isBefore(ReleaseTrains.OCKHAM)).isFalse();
assertThat(ReleaseTrains.OCKHAM.isBefore(ReleaseTrains.PASCAL)).isTrue();
}
@Test
void beforeShouldConsiderMixedCalver() {
assertThat(ReleaseTrains.PASCAL.isBefore(ReleaseTrains.INGALLS)).isFalse();
assertThat(ReleaseTrains.INGALLS.isBefore(ReleaseTrains.PASCAL)).isTrue();
}
}