From a8e6e3f94504bca1bf41943c7e35fcc270c7b788 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 9 Jan 2024 11:43:55 +0000 Subject: [PATCH] Add option to disable the generation of links to each issue Closes gh-97 --- README.adoc | 13 +++++++++++ .../ApplicationProperties.java | 17 +++++++++++--- .../ChangelogGenerator.java | 8 +++++-- .../ChangelogGeneratorTests.java | 23 +++++++++++++++---- .../output-without-issue-links | 15 ++++++++++++ 5 files changed, 67 insertions(+), 9 deletions(-) create mode 100644 src/test/resources/io/spring/githubchangeloggenerator/output-without-issue-links diff --git a/README.adoc b/README.adoc index 4bb1143..a5916f9 100644 --- a/README.adoc +++ b/README.adoc @@ -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]. diff --git a/src/main/java/io/spring/githubchangeloggenerator/ApplicationProperties.java b/src/main/java/io/spring/githubchangeloggenerator/ApplicationProperties.java index 27d1c93..7f70b6a 100644 --- a/src/main/java/io/spring/githubchangeloggenerator/ApplicationProperties.java +++ b/src/main/java/io/spring/githubchangeloggenerator/ApplicationProperties.java @@ -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. @@ -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; @@ -187,10 +187,17 @@ public static class Issues { */ private final Set ports; - public Issues(IssueSort sort, IssuesExclude exclude, Set ports) { + /** + * Whether to generate a link to each issue in the changelog. + */ + private final boolean generateLinks; + + public Issues(IssueSort sort, IssuesExclude exclude, Set 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() { @@ -205,6 +212,10 @@ public Set getPorts() { return this.ports; } + public boolean isGenerateLinks() { + return this.generateLinks; + } + } /** diff --git a/src/main/java/io/spring/githubchangeloggenerator/ChangelogGenerator.java b/src/main/java/io/spring/githubchangeloggenerator/ChangelogGenerator.java index e822fcf..2c0812f 100644 --- a/src/main/java/io/spring/githubchangeloggenerator/ChangelogGenerator.java +++ b/src/main/java/io/spring/githubchangeloggenerator/ChangelogGenerator.java @@ -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. @@ -78,6 +78,8 @@ public class ChangelogGenerator { private final List externalLinks; + private final boolean generateLinks; + public ChangelogGenerator(GitHubService service, ApplicationProperties properties) { this.service = service; this.repository = properties.getRepository(); @@ -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(); } /** @@ -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) { diff --git a/src/test/java/io/spring/githubchangeloggenerator/ChangelogGeneratorTests.java b/src/test/java/io/spring/githubchangeloggenerator/ChangelogGeneratorTests.java index 4b1f260..078f12c 100644 --- a/src/test/java/io/spring/githubchangeloggenerator/ChangelogGeneratorTests.java +++ b/src/test/java/io/spring/githubchangeloggenerator/ChangelogGeneratorTests.java @@ -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. @@ -299,7 +299,7 @@ void generateWhenSectionSortedByTitle() throws Exception { Set 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 issues = new ArrayList<>(); issues.add(newIssue("Enhancement c", "1", "enhancement-1-url", Type.ENHANCEMENT)); @@ -315,7 +315,7 @@ void generateWhenAllIssuesSortedByTitle() throws Exception { Set 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 issues = new ArrayList<>(); issues.add(newIssue("Enhancement c", "1", "enhancement-1-url", Type.ENHANCEMENT)); @@ -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 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 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 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); } diff --git a/src/test/resources/io/spring/githubchangeloggenerator/output-without-issue-links b/src/test/resources/io/spring/githubchangeloggenerator/output-without-issue-links new file mode 100644 index 0000000..9f35142 --- /dev/null +++ b/src/test/resources/io/spring/githubchangeloggenerator/output-without-issue-links @@ -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