Skip to content

add an option to create annotated tags #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
May 11, 2021
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ spotlessChangelog { // all defaults
// keep changelog formatted
changelogFile 'CHANGELOG.md'
enforceCheck true
annotateTags false
// calculate next version (breaking.added.fixed)
ifFoundBumpBreaking ['**BREAKING**']
ifFoundBumpAdded ['### Added']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ public void addAndCommit() throws GitAPIException {
.call();
}

/** Tags and pushes the tag and the branch. */
public void tagBranchPush() throws GitAPIException {
Ref tagRef = git.tag().setName(tagName()).setAnnotated(false).call();
/** Tags and pushes the tag and the branch.
* @param annotated false for lightweight tags, true for annotated tags */
public void tagBranchPush(final boolean annotated) throws GitAPIException {
Ref tagRef = git.tag().setName(tagName()).setAnnotated(annotated).call();
push(tagRef, RemoteRefUpdate.Status.OK);
push(cfg.branch, RemoteRefUpdate.Status.OK);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class ChangelogExtension {
NextVersionCfg nextVersionCfg;
GitCfg gitCfg;
boolean enforceCheck;
boolean annotateTags = false;

public ChangelogExtension(Project project) {
this.project = Objects.requireNonNull(project);
Expand Down Expand Up @@ -109,6 +110,11 @@ public void enforceCheck(boolean enforceCheck) {
this.enforceCheck = enforceCheck;
}

/** Determines whether tags are lightweight (false) or annotated (true). Default is false. */
public void annotateTags(boolean annotateTags) {
this.annotateTags = annotateTags;
}

/**
* Sets a custom {@link NextVersionFunction} by calling the public no-arg constructor of the given class.
* Default value is {@link com.diffplug.spotless.changelog.NextVersionFunction.Semver Semver}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public void push() throws IOException, GitAPIException {
assertNotSnapshot();
GitActions git = extension.gitCfg.withChangelog(extension.changelogFile, extension.model());
git.addAndCommit();
git.tagBranchPush();
git.tagBranchPush(extension.annotateTags);
}
}
}