Skip to content

Commit

Permalink
Add option to disable the generation of links to each issue
Browse files Browse the repository at this point in the history
Closes gh-97
  • Loading branch information
wilkinsona committed Jan 9, 2024
1 parent 2288e49 commit a8e6e3f
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 9 deletions.
13 changes: 13 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,19 @@ changelog:



=== Disabling Generation of Links to Each Issue
By default, each entry in the changelog will include a link back to the issue or PR on GitHub.
The generation of these links can be disabled:

[source,yaml]
----
changelog:
issues:
generate_links: false
----



=== License
This project is Open Source software released under the
https://www.apache.org/licenses/LICENSE-2.0.html[Apache 2.0 license].
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2022 the original author or authors.
* Copyright 2018-2024 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.
Expand Down Expand Up @@ -82,7 +82,7 @@ public ApplicationProperties(Repository repository, @DefaultValue("title") Miles
this.repository = repository;
this.milestoneReference = milestoneReference;
this.sections = (sections != null) ? sections : Collections.emptyList();
this.issues = (issues != null) ? issues : new Issues(null, null, null);
this.issues = (issues != null) ? issues : new Issues(null, null, null, true);
this.contributors = (contributors != null) ? contributors : new Contributors(null, null);
this.externalLinks = (externalLinks != null) ? externalLinks : Collections.emptyList();
this.addSections = addSections;
Expand Down Expand Up @@ -187,10 +187,17 @@ public static class Issues {
*/
private final Set<PortedIssue> ports;

public Issues(IssueSort sort, IssuesExclude exclude, Set<PortedIssue> ports) {
/**
* Whether to generate a link to each issue in the changelog.
*/
private final boolean generateLinks;

public Issues(IssueSort sort, IssuesExclude exclude, Set<PortedIssue> ports,
@DefaultValue("true") boolean generateLinks) {
this.sort = sort;
this.exclude = (exclude != null) ? exclude : new IssuesExclude(null);
this.ports = (ports != null) ? ports : Collections.emptySet();
this.generateLinks = generateLinks;
}

public IssueSort getSort() {
Expand All @@ -205,6 +212,10 @@ public Set<PortedIssue> getPorts() {
return this.ports;
}

public boolean isGenerateLinks() {
return this.generateLinks;
}

}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2023 the original author or authors.
* Copyright 2018-2024 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.
Expand Down Expand Up @@ -78,6 +78,8 @@ public class ChangelogGenerator {

private final List<ExternalLink> externalLinks;

private final boolean generateLinks;

public ChangelogGenerator(GitHubService service, ApplicationProperties properties) {
this.service = service;
this.repository = properties.getRepository();
Expand All @@ -89,6 +91,7 @@ public ChangelogGenerator(GitHubService service, ApplicationProperties propertie
this.sections = new ChangelogSections(properties);
this.portedIssues = properties.getIssues().getPorts();
this.externalLinks = properties.getExternalLinks();
this.generateLinks = properties.getIssues().isGenerateLinks();
}

/**
Expand Down Expand Up @@ -164,7 +167,8 @@ private String getFormattedIssue(Issue issue) {
for (Escape escape : escapes) {
title = escape.apply(title);
}
return String.format("- %s %s%n", title, getLinkToIssue(issue));
return (this.generateLinks) ? String.format("- %s %s%n", title, getLinkToIssue(issue))
: String.format("- %s%n", title);
}

private String getLinkToIssue(Issue issue) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2022 the original author or authors.
* Copyright 2018-2024 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.
Expand Down Expand Up @@ -299,7 +299,7 @@ void generateWhenSectionSortedByTitle() throws Exception {
Set<String> labels = Collections.singleton("type: enhancement");
sections.add(new Section("Enhancements", null, IssueSort.TITLE, labels));
ApplicationProperties properties = new ApplicationProperties(REPO, MilestoneReference.ID, sections,
new Issues(null, null, null), null, null, false);
new Issues(null, null, null, true), null, null, false);
this.generator = new ChangelogGenerator(this.service, properties);
List<Issue> issues = new ArrayList<>();
issues.add(newIssue("Enhancement c", "1", "enhancement-1-url", Type.ENHANCEMENT));
Expand All @@ -315,7 +315,7 @@ void generateWhenAllIssuesSortedByTitle() throws Exception {
Set<String> labels = Collections.singleton("type: enhancement");
sections.add(new Section("Enhancements", null, null, labels));
ApplicationProperties properties = new ApplicationProperties(REPO, MilestoneReference.ID, sections,
new Issues(IssueSort.TITLE, null, null), null, null, false);
new Issues(IssueSort.TITLE, null, null, true), null, null, false);
this.generator = new ChangelogGenerator(this.service, properties);
List<Issue> issues = new ArrayList<>();
issues.add(newIssue("Enhancement c", "1", "enhancement-1-url", Type.ENHANCEMENT));
Expand Down Expand Up @@ -359,13 +359,28 @@ void generateWhenMultipleExternalLink() throws Exception {
assertChangelog("23").hasContent(from("output-with-multiple-external-link"));
}

@Test
void generateWhenIssueLinksDisabled() throws Exception {
User contributor1 = createUser("contributor1");
List<Issue> issues = new ArrayList<>();
issues.add(newIssue("Bug 1", "1", "bug-1-url", Type.BUG));
issues.add(newIssue("Bug 2", "2", "bug-2-url", Type.BUG, "wontfix"));
issues.add(newPullRequest("PR 3", "3", Type.ENHANCEMENT, "pr-3-url", contributor1));
issues.add(newPullRequest("PR 4", "4", Type.ENHANCEMENT, "pr-4-url", contributor1));
given(this.service.getIssuesForMilestone(23, REPO)).willReturn(issues);
ApplicationProperties properties = new ApplicationProperties(REPO, MilestoneReference.ID, null,
new Issues(null, null, null, false), null, null, false);
this.generator = new ChangelogGenerator(this.service, properties);
assertChangelog("23").hasContent(from("output-without-issue-links"));
}

private void setupGenerator(MilestoneReference id) {
Set<String> labels = new HashSet<>(Arrays.asList("duplicate", "wontfix"));
PortedIssue forwardPort = new PortedIssue("status: forward-port", "Forward port of issue #(\\d+)");
PortedIssue cherryPick = new PortedIssue("status: back-port", "Back port of issue #(\\d+)");
Set<PortedIssue> portedIssues = new HashSet<>(Arrays.asList(forwardPort, cherryPick));
ApplicationProperties properties = new ApplicationProperties(REPO, id, null,
new Issues(null, new IssuesExclude(labels), portedIssues), null, null, false);
new Issues(null, new IssuesExclude(labels), portedIssues, true), null, null, false);
this.generator = new ChangelogGenerator(this.service, properties);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## :star: New Features

- PR 3
- PR 4

## :lady_beetle: Bug Fixes

- Bug 1
- Bug 2

## :heart: Contributors

Thank you to all the contributors who worked on this release:

@contributor1

0 comments on commit a8e6e3f

Please sign in to comment.