Skip to content

Commit

Permalink
[changelog] let contributors be formatted. Resolves #306
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Jul 24, 2021
1 parent f99514e commit 2f724e1
Show file tree
Hide file tree
Showing 26 changed files with 713 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package org.jreleaser.engine.changelog;

import org.jreleaser.engine.release.Releasers;
import org.jreleaser.model.JReleaserContext;
import org.jreleaser.model.JReleaserException;
import org.jreleaser.sdk.git.ChangelogProvider;
Expand All @@ -32,7 +33,7 @@
public class Changelog {
public static String createChangelog(JReleaserContext context) {
try {
return ChangelogProvider.getChangelog(context).trim();
return ChangelogProvider.getChangelog(context, Releasers.releaserFor(context)).trim();
} catch (IOException e) {
throw new JReleaserException("Unexpected error when creating changelog.", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class Changelog implements Domain, EnabledAware {
private final Set<Replacer> replacers = new LinkedHashSet<>();
private final Set<Labeler> labelers = new LinkedHashSet<>();
private final Hide hide = new Hide();
private final Contributors contributors = new Contributors();

private Boolean enabled;
private boolean links;
Expand All @@ -71,6 +72,7 @@ void setAll(Changelog changelog) {
setReplacers(changelog.replacers);
setLabelers(changelog.labelers);
setHide(changelog.hide);
setContributors(changelog.contributors);
}

public boolean resolveFormatted(Project project) {
Expand Down Expand Up @@ -232,6 +234,14 @@ public void setHide(Hide hide) {
this.hide.setAll(hide);
}

public Contributors getContributors() {
return contributors;
}

public void setContributors(Contributors contributors) {
this.contributors.setAll(contributors);
}

@Deprecated
public void setHideUncategorized(boolean hideUncategorized) {
System.out.println("changelog.hideUncategorized has been deprecated since 0.6.0 and will be removed in the future. Use changelog.hide.uncategorized instead");
Expand All @@ -254,6 +264,7 @@ public Map<String, Object> asMap(boolean full) {
map.put("includeLabels", includeLabels);
map.put("excludeLabels", excludeLabels);
map.put("hide", hide.asMap(full));
map.put("contributors", contributors.asMap(full));

Map<String, Map<String, Object>> m = new LinkedHashMap<>();
int i = 0;
Expand Down Expand Up @@ -417,6 +428,44 @@ public Map<String, Object> asMap(boolean full) {
}
}

public static class Contributors implements Domain {
private Boolean enabled;
private String format;

void setAll(Contributors contributor) {
this.enabled = contributor.enabled;
this.format = contributor.format;
}

public boolean isEnabled() {
return enabled != null && enabled;
}

public void setEnabled(Boolean enabled) {
this.enabled = enabled;
}

public boolean isEnabledSet() {
return enabled != null;
}

public String getFormat() {
return format;
}

public void setFormat(String format) {
this.format = format;
}

@Override
public Map<String, Object> asMap(boolean full) {
Map<String, Object> map = new LinkedHashMap<>();
map.put("enabled", enabled);
map.put("format", format);
return map;
}
}

public static class Hide implements Domain {
private final Set<String> categories = new LinkedHashSet<>();
private final Set<String> contributors = new LinkedHashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.jreleaser.model.releaser.spi;

import java.io.IOException;
import java.util.Optional;

/**
* @author Andres Almiray
Expand All @@ -27,4 +28,6 @@ public interface Releaser {
void release() throws ReleaseException;

Repository maybeCreateRepository(String owner, String repo, String password) throws IOException;

Optional<User> findUser(String email, String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public String toString() {
"kind='" + kind + '\'' +
", owner='" + owner + '\'' +
", name='" + name + '\'' +
", url=" + url +
", httpUrl=" + httpUrl +
", url='" + url + '\'' +
", httpUrl'=" + httpUrl + '\'' +
"]";
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2020-2021 The JReleaser 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
*
* https://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.jreleaser.model.releaser.spi;

import java.util.Objects;

/**
* @author Andres Almiray
* @since 0.1.0
*/
public class User {
private final String username;
private final String email;
private final String url;

public User(String username, String email, String url) {
this.username = username;
this.email = email;
this.url = url;
}

public String getUsername() {
return username;
}

public String getEmail() {
return email;
}

public String getUrl() {
return url;
}

public String asLink(String input) {
return "[" + input + "](" + url + ")";
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
User user = (User) o;
return username.equals(user.username) &&
email.equals(user.email) &&
url.equals(user.url);
}

@Override
public int hashCode() {
return Objects.hash(username, email, url);
}

@Override
public String toString() {
return "User[" +
"username='" + username + '\'' +
", email='" + email + '\'' +
", url='" + url + '\'' +
"]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -274,5 +274,9 @@ private static void validateChangelog(JReleaserContext context, GitService servi
i++;
}
}

if (!changelog.getContributors().isEnabledSet()) {
changelog.getContributors().setEnabled(true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,16 @@ interface Changelog {

Hide getHide()

Contributors getContributors()

void hide(Action<? super Hide> action)

void contributors(Action<? super Contributors> action)

void hide(@DelegatesTo(strategy = Closure.DELEGATE_FIRST, value = Hide) Closure<Void> action)

void contributors(@DelegatesTo(strategy = Closure.DELEGATE_FIRST, value = Contributors) Closure<Void> action)

interface Category {
Property<String> getTitle()

Expand All @@ -97,6 +103,12 @@ interface Changelog {
Property<String> getReplace()
}

interface Contributors {
Property<Boolean> getEnabled()

Property<String> getFormat()
}

interface Hide {
Property<Boolean> getUncategorized()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class ChangelogImpl implements Changelog {
final SetProperty<String> includeLabels
final SetProperty<String> excludeLabels
final HideImpl hide
final ContributorsImpl contributors

private final List<CategoryImpl> categories = []
private final Set<LabelerImpl> labelers = []
Expand All @@ -73,6 +74,7 @@ class ChangelogImpl implements Changelog {
includeLabels = objects.setProperty(String).convention(Providers.notDefined())
excludeLabels = objects.setProperty(String).convention(Providers.notDefined())
hide = objects.newInstance(HideImpl, objects)
contributors = objects.newInstance(ContributorsImpl, objects)
}

@Override
Expand All @@ -98,6 +100,7 @@ class ChangelogImpl implements Changelog {
!categories.isEmpty() ||
!labelers.isEmpty() ||
!replacers.isEmpty() ||
contributors.isSet()||
hide.isSet()
}

Expand Down Expand Up @@ -146,6 +149,11 @@ class ChangelogImpl implements Changelog {
action.execute(hide)
}

@Override
void contributors(Action<? super Contributors> action) {
action.execute(contributors)
}

@Override
void category(@DelegatesTo(strategy = Closure.DELEGATE_FIRST, value = Category) Closure<Void> action) {
CategoryImpl category = objects.newInstance(CategoryImpl, objects)
Expand All @@ -172,6 +180,11 @@ class ChangelogImpl implements Changelog {
ConfigureUtil.configure(action, hide)
}

@Override
void contributors(@DelegatesTo(strategy = Closure.DELEGATE_FIRST, value = Contributors) Closure<Void> action) {
ConfigureUtil.configure(action, contributors)
}

org.jreleaser.model.Changelog toModel() {
org.jreleaser.model.Changelog changelog = new org.jreleaser.model.Changelog()
if (enabled.present) {
Expand Down Expand Up @@ -201,6 +214,7 @@ class ChangelogImpl implements Changelog {
replacer.toModel()
} as Set<org.jreleaser.model.Changelog.Replacer>)
changelog.hide = hide.toModel()
changelog.contributors = contributors.toModel()
changelog
}

Expand Down Expand Up @@ -264,6 +278,31 @@ class ChangelogImpl implements Changelog {
}
}

@CompileStatic
static class ContributorsImpl implements Contributors {
final Property<Boolean> enabled
final Property<String> format

@Inject
ContributorsImpl(ObjectFactory objects) {
enabled = objects.property(Boolean).convention(Providers.notDefined())
format = objects.property(String).convention(Providers.notDefined())
}

@Internal
boolean isSet() {
enabled.present ||
format.present
}

org.jreleaser.model.Changelog.Contributors toModel() {
org.jreleaser.model.Changelog.Contributors contributors = new org.jreleaser.model.Changelog.Contributors()
if (enabled.present) contributors.enabled = enabled.get()
if (format.present) contributors.format = format.get()
contributors
}
}

@CompileStatic
static class HideImpl implements Hide {
final Property<Boolean> uncategorized
Expand Down

0 comments on commit 2f724e1

Please sign in to comment.