-
Notifications
You must be signed in to change notification settings - Fork 0
Add parameters for generating more flexible changesets using the add goal #97
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -2,6 +2,7 @@ | |||||||
|
||||||||
import org.slf4j.Logger; | ||||||||
|
||||||||
import java.io.File; | ||||||||
import java.io.IOException; | ||||||||
import java.nio.file.FileAlreadyExistsException; | ||||||||
import java.nio.file.Files; | ||||||||
|
@@ -31,10 +32,14 @@ public ChangesetWriter(Path baseDir) { | |||||||
} | ||||||||
|
||||||||
public void writeChangeset(Changeset changeset) throws FileAlreadyExistsException { | ||||||||
writeChangeset(changeset.packageName(), changeset.level(), changeset.message()); | ||||||||
writeChangeset(changeset.packageName(), changeset.level(), changeset.message(), changeset.file()); | ||||||||
} | ||||||||
|
||||||||
Path writeChangeset(String packageName, Level changeLevel, String message) throws FileAlreadyExistsException { | ||||||||
return writeChangeset(packageName, changeLevel, message, null); | ||||||||
} | ||||||||
|
||||||||
Path writeChangeset(String packageName, Level changeLevel, String message, File file) throws FileAlreadyExistsException { | ||||||||
final String fileContent; | ||||||||
if(message == null) { | ||||||||
fileContent = """ | ||||||||
|
@@ -62,6 +67,26 @@ Path writeChangeset(String packageName, Level changeLevel, String message) throw | |||||||
} | ||||||||
} | ||||||||
|
||||||||
|
||||||||
Path changesetFile; | ||||||||
if (file != null) { | ||||||||
// TODO Add tests | ||||||||
changesetFile = file.toPath(); | ||||||||
} else { | ||||||||
changesetFile = generateChangesetFilename(changesetsDir); | ||||||||
} | ||||||||
|
||||||||
try { | ||||||||
LOG.info("Writing changeset to {}", changesetFile); | ||||||||
Files.writeString(changesetFile, fileContent, StandardOpenOption.CREATE_NEW); | ||||||||
} catch (IOException e) { | ||||||||
LOG.error("Failed to create new changeset", e); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider propagating the IOException (or wrapping it in a RuntimeException) to ensure that failures in writing the changeset file are not silently ignored.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||
} | ||||||||
|
||||||||
return changesetFile; | ||||||||
} | ||||||||
|
||||||||
private Path generateChangesetFilename(Path changesetsDir) throws FileAlreadyExistsException { | ||||||||
String newFileName = this.nameGenerator.humanId() + ".md"; | ||||||||
Path changesetFile = changesetsDir.resolve(newFileName); | ||||||||
|
||||||||
|
@@ -80,14 +105,6 @@ Path writeChangeset(String packageName, Level changeLevel, String message) throw | |||||||
throw new FileAlreadyExistsException(string, null, "Failed to generate a unique name after %s attempts".formatted(attempt)); | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
try { | ||||||||
LOG.info("Writing changeset to {}", changesetFile); | ||||||||
Files.writeString(changesetFile, fileContent, StandardOpenOption.CREATE_NEW); | ||||||||
} catch (IOException e) { | ||||||||
LOG.error("Failed to create new changeset", e); | ||||||||
} | ||||||||
|
||||||||
return changesetFile; | ||||||||
} | ||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,8 @@ | ||
invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:add -DchangesetContent='thecontent' | ||
# changesetFilename is used to get predictable names for the changesets, so testing is easier | ||
|
||
invoker.goals.1=${project.groupId}:${project.artifactId}:${project.version}:add -DchangesetContent='Patch change' -DchangesetLevel=Patch -DchangesetFilename=patch.md | ||
invoker.goals.2=${project.groupId}:${project.artifactId}:${project.version}:add -DchangesetContent='Minor change' -DchangesetLevel=MINOR -DchangesetFilename=minor.md | ||
invoker.goals.3=${project.groupId}:${project.artifactId}:${project.version}:add -DchangesetContent='Major change' -DchangesetLevel=major -DchangesetFilename=major.md | ||
|
||
# TODO Enable this goal to test the dependency change, once that PR is merged | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resolve this TODO when #95 is merged |
||
# invoker.goals.4=${project.groupId}:${project.artifactId}:${project.version}:add -DchangesetContent='Dependency change' -DchangesetLevel=Dependency -DchangesetFilename=dependency.md |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,32 @@ | ||
// Verify that exactly one markdown file was added to the .changeset folder and has the expected content | ||
def firstChangeset = new File(basedir, ".changeset") | ||
def changesetFiles = new File(basedir, ".changeset") | ||
.listFiles() | ||
.findAll { it.name ==~ /.*\.md/ } | ||
.first() | ||
assert changesetFiles.size() == 3 | ||
|
||
assert firstChangeset.text.equals("---\n" + | ||
|
||
assert new File(basedir, ".changeset/patch.md").text.equals("---\n" + | ||
"\"add-blank-changelog\": patch\n" + | ||
"---\n" + | ||
"\n" + | ||
"thecontent"); | ||
"Patch change"); | ||
|
||
assert new File(basedir, ".changeset/minor.md").text.equals("---\n" + | ||
"\"add-blank-changelog\": minor\n" + | ||
"---\n" + | ||
"\n" + | ||
"Minor change"); | ||
|
||
assert new File(basedir, ".changeset/major.md").text.equals("---\n" + | ||
"\"add-blank-changelog\": major\n" + | ||
"---\n" + | ||
"\n" + | ||
"Major change"); | ||
|
||
// See invoker.properties for the dependency change details | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resolve this when #95 is merged |
||
/* | ||
assert new File(basedir, ".changeset/dependency.md").text.equals("---\n" + | ||
"\"add-blank-changelog\": dependency\n" + | ||
"---\n" + | ||
"\n" + | ||
"Dependency change"); | ||
*/ |
Uh oh!
There was an error while loading. Please reload this page.