Skip to content
This repository has been archived by the owner on Jan 18, 2021. It is now read-only.

More concise release notes #108

Merged
merged 6 commits into from
May 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ targetCompatibility = 1.6

repositories { jcenter() }

version = '0.8.3'
version = '0.8.4'

println " Version: $version"
group = 'gradle.plugin.org.mockito'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@
import org.gradle.api.logging.Logging;
import org.gradle.api.tasks.*;
import org.mockito.release.internal.gradle.util.FileUtil;
import org.mockito.release.notes.Notes;
import org.mockito.release.notes.NotesBuilder;
import org.mockito.release.notes.format.ReleaseNotesFormatters;
import org.mockito.release.notes.generator.ReleaseNotesGenerator;
import org.mockito.release.notes.generator.ReleaseNotesGenerators;
import org.mockito.release.notes.model.ReleaseNotesData;

import java.io.File;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;

import static java.util.Arrays.asList;

/**
* Generates incremental, detailed release notes text.
* that can be appended to the release notes file.
Expand All @@ -21,6 +27,7 @@ public abstract class IncrementalReleaseNotes extends DefaultTask {

private static final Logger LOG = Logging.getLogger(IncrementalReleaseNotes.class);

private String previousVersion;
private File releaseNotesFile;
private String gitHubReadOnlyAuthToken;
private String gitHubRepository;
Expand Down Expand Up @@ -109,6 +116,21 @@ public void setPublicationRepository(String publicationRepository) {
this.publicationRepository = publicationRepository;
}

/**
* Previous released version we generate the release notes from.
*/
@Input
public String getPreviousVersion() {
return previousVersion;
}

/**
* See {@link #getPreviousVersion()}
*/
public void setPreviousVersion(String previousVersion) {
this.previousVersion = previousVersion;
}

private void assertConfigured() {
//TODO SF unit test coverage
if (releaseNotesFile == null || !releaseNotesFile.isFile()) {
Expand All @@ -124,35 +146,25 @@ private void assertConfigured() {
}
}

/**
* Returns previous version based on the release notes file.
* It parses the first line of the release notes file to identify previously released version.
*/
private String getPreviousVersion() {
//TODO this is really awkward method.
// We should not be reading previous version from release notes file
// We should either not read it at all (e.g. write the impl so that it does not require the previous version)
// or store previous release version in the 'version.properties' file.
assertConfigured();
String firstLine = FileUtil.firstLine(releaseNotesFile);
return Notes.previousVersion(firstLine).getPreviousVersion();
}

/**
* Generates new incremental content of the release notes.
*/
protected String getNewContent() {
assertConfigured();
LOG.lifecycle(" Building new release notes based on {}", releaseNotesFile);
NotesBuilder builder = Notes.gitHubNotesBuilder(
this.getProject().getProjectDir(), this.getProject().getBuildDir(),
gitHubRepository, gitHubReadOnlyAuthToken);
String prev = "v" + getPreviousVersion();
String current = "HEAD";
LOG.lifecycle(" Generating release note for revisions: {} -> {}", prev, current);
String v = this.getProject().getVersion().toString();
String newContent = builder.buildNotes(v, prev, current, gitHubLabelMapping, publicationRepository);
return newContent;

ReleaseNotesGenerator generator = ReleaseNotesGenerators.releaseNotesGenerator(getProject().getRootDir(), gitHubRepository, gitHubReadOnlyAuthToken);
String version = getProject().getVersion().toString();
String tagPrefix = "v";
Collection<ReleaseNotesData> data = generator.generateReleaseNotesData(
version, asList(previousVersion), tagPrefix, Collections.<String>emptyList(), false);
String vcsCommitTemplate = "https://github.com/" + gitHubRepository + "/compare/"
+ tagPrefix + previousVersion + "..." + tagPrefix + version;
String notes = ReleaseNotesFormatters.detailedFormatter(
"", gitHubLabelMapping, vcsCommitTemplate, publicationRepository)
.formatReleaseNotes(data);

return notes + "\n\n";
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.mockito.release.gradle.ReleaseConfiguration;
import org.mockito.release.internal.gradle.util.FileUtil;
import org.mockito.release.internal.gradle.util.TaskMaker;
import org.mockito.release.notes.Notes;
import org.mockito.release.notes.contributors.Contributors;
import org.mockito.release.version.VersionInfo;

import java.io.File;

Expand Down Expand Up @@ -45,7 +44,9 @@ public void execute(final ContributorsFetcherTask task) {

deferredConfiguration(project, new Runnable() {
public void run() {
String fromRevision = fromRevision(project, conf);
//TODO more and more tasks and plugins depend on VersionInfo.
//we should consider making it a part of release configuration in similar way we do 'releasing.notableRepo'
String fromRevision = "v" + project.getExtensions().getByType(VersionInfo.class).getPreviousVersion();
File contributorsFile = lastContributorsFile(project, fromRevision, toRevision);

task.setReadOnlyAuthToken(conf.getGitHub().getReadOnlyAuthToken());
Expand Down Expand Up @@ -79,11 +80,6 @@ public void run() {
});
}

private String fromRevision(Project project, ReleaseConfiguration conf) {
String firstLine = FileUtil.firstLine(project.file(conf.getReleaseNotes().getFile()));
return "v" + Notes.previousVersion(firstLine).getPreviousVersion();
}

private File lastContributorsFile(Project project, String fromRevision, String toRevision) {
String contributorsFileName = Contributors.getLastContributorsFileName(
project.getBuildDir().getAbsolutePath(), fromRevision, toRevision);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public void run() {
task.setReleaseNotesFile(project.file(conf.getReleaseNotes().getFile())); //TODO add sensible default
task.setGitHubReadOnlyAuthToken(conf.getGitHub().getReadOnlyAuthToken());
task.setGitHubRepository(conf.getGitHub().getRepository());
task.setPreviousVersion(project.getExtensions().getByType(VersionInfo.class).getPreviousVersion());
}
});
}
Expand Down
74 changes: 0 additions & 74 deletions src/main/groovy/org/mockito/release/notes/GitNotesBuilder.java

This file was deleted.

30 changes: 0 additions & 30 deletions src/main/groovy/org/mockito/release/notes/Notes.java

This file was deleted.

20 changes: 0 additions & 20 deletions src/main/groovy/org/mockito/release/notes/NotesBuilder.java

This file was deleted.

6 changes: 0 additions & 6 deletions src/main/groovy/org/mockito/release/notes/TODO.txt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ class DetailedFormatter implements MultiReleaseNotesFormatter {
private final String introductionText;
private final Map<String, String> labelMapping;
private final String vcsCommitsLinkTemplate;
private final String publicationRepository;

DetailedFormatter(String introductionText, Map<String, String> labelMapping, String vcsCommitsLinkTemplate) {
DetailedFormatter(String introductionText, Map<String, String> labelMapping, String vcsCommitsLinkTemplate,
String publicationRepository) {
this.introductionText = introductionText;
this.labelMapping = labelMapping;
this.vcsCommitsLinkTemplate = vcsCommitsLinkTemplate;
this.publicationRepository = publicationRepository;
}

@Override
Expand All @@ -35,7 +38,7 @@ public String formatReleaseNotes(Collection<ReleaseNotesData> data) {
for (ReleaseNotesData d : data) {
sb.append("**").append(d.getVersion()).append("** - ");
String vcsCommitsLink = MessageFormat.format(vcsCommitsLinkTemplate, d.getPreviousVersionVcsTag(), d.getVcsTag());
sb.append(releaseSummary(d.getDate(), d.getContributions(), vcsCommitsLink));
sb.append(releaseSummary(d.getDate(), d.getContributions(), vcsCommitsLink, publicationRepository));

if (!d.getContributions().getContributions().isEmpty()) {
//no point printing any improvements information if there are no code changes
Expand All @@ -48,9 +51,9 @@ public String formatReleaseNotes(Collection<ReleaseNotesData> data) {
return sb.toString().trim();
}

static String releaseSummary(Date date, ContributionSet contributions, String vcsCommitsLink) {
static String releaseSummary(Date date, ContributionSet contributions, String vcsCommitsLink, String publicationRepository) {
return authorsSummary(contributions, vcsCommitsLink) +
" - *" + DateFormat.formatDate(date) + "*\n" +
" - *" + DateFormat.formatDate(date) + "*" + " - published to " + publicationRepository + "\n" +
authorsSummaryAppendix(contributions);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,20 @@ public static MultiReleaseNotesFormatter notableFormatter(String introductionTex

/**
* Returns the detailed formatter intended to use for all releases
*
* @param introductionText text to be placed on the top of the release notes content
* @param introductionText text to be placed on the top of the release notes content
* @param labelMapping Mapping of label to descriptive label summary.
* Labels of the improvements (see {@link org.mockito.release.notes.model.Improvement#getLabels()}
* are often short and not very descriptive.
* In final release notes we want descriptive sections of improvements.
* Mappings also allow controlling priority in presenting improvements -
* the formatter can use the order of label mappings. For example, 'noteworthy' labelled improvements on top.
* @param vcsCommitsLinkTemplate template to generate link to vcs view of the commits.
* For example: https://github.com/mockito/mockito/compare/{0}...{1}".
* When template is formatted, 1st arg will be "fromRevision", 2nd will be "toRevision".
* For example: https://github.com/mockito/mockito/compare/{0}...{1}".
* @param publicationRepository where the binaries were published to, will be printed as-is in the release notes
*/
public static MultiReleaseNotesFormatter detailedFormatter(String introductionText,
Map<String, String> labelMapping,
String vcsCommitsLinkTemplate) {
return new DetailedFormatter(introductionText, labelMapping, vcsCommitsLinkTemplate);
String vcsCommitsLinkTemplate, String publicationRepository) {
return new DetailedFormatter(introductionText, labelMapping, vcsCommitsLinkTemplate, publicationRepository);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ public class ReleaseNotesGenerators {

//TODO move entire "org.mockito.release.notes" -> "org.mockito.release.internal.notes"

public static ReleaseNotesGenerator releaseNotesGenerator(File workDir, String repository, String readOnlyAuthToken) {
/**
* @param workDir the working directory where 'git' operations will be executed
* @param gitHubRepository GitHub gitHubRepository in format USER|COMPANY/REPO_NAME, for example: mockito/mockito
* @param readOnlyAuthToken read only auth token used to communicate with GitHub
*/
public static ReleaseNotesGenerator releaseNotesGenerator(File workDir, String gitHubRepository, String readOnlyAuthToken) {
ProcessRunner processRunner = Exec.getProcessRunner(workDir);
ContributionsProvider contributionsProvider = Vcs.getContributionsProvider(processRunner);
ImprovementsProvider improvementsProvider = Improvements.getGitHubProvider(repository, readOnlyAuthToken);
ImprovementsProvider improvementsProvider = Improvements.getGitHubProvider(gitHubRepository, readOnlyAuthToken);
ReleasedVersionsProvider releasedVersionsProvider = Vcs.getReleaseDateProvider(processRunner);
GitHubContributorsProvider contributorsProvider = Contributors.getGitHubContributorsProvider(repository, readOnlyAuthToken);
GitHubContributorsProvider contributorsProvider = Contributors.getGitHubContributorsProvider(gitHubRepository, readOnlyAuthToken);
return new DefaultReleaseNotesGenerator(contributionsProvider, improvementsProvider, releasedVersionsProvider,
contributorsProvider);
}
Expand Down
Loading