Added a tweet template

fixes #25
This commit is contained in:
Marcin Grzejszczak
2017-06-05 15:49:37 +02:00
parent d85aaddd54
commit fce0ff8e3a
7 changed files with 97 additions and 6 deletions

View File

@@ -107,4 +107,13 @@ public class Releaser {
File blog = this.templateGenerator.blog(projects);
log.info("\nSuccessfully created blog template at location [{}]", blog);
}
public void createTweet(ProjectVersion releaseVersion) {
if (releaseVersion.isSnapshot()) {
log.info("\nWon't create tweet template for a SNAPSHOT version");
return;
}
File blog = this.templateGenerator.tweet();
log.info("\nSuccessfully created tweet template at location [{}]", blog);
}
}

View File

@@ -1,16 +1,16 @@
package org.springframework.cloud.release.internal.template;
import com.github.jknack.handlebars.Handlebars;
import com.github.jknack.handlebars.Template;
import com.github.jknack.handlebars.helper.StringHelpers;
import com.github.jknack.handlebars.io.ClassPathTemplateLoader;
import java.io.File;
import java.io.IOException;
import org.springframework.cloud.release.internal.ReleaserProperties;
import org.springframework.cloud.release.internal.pom.Projects;
import com.github.jknack.handlebars.Handlebars;
import com.github.jknack.handlebars.Template;
import com.github.jknack.handlebars.helper.StringHelpers;
import com.github.jknack.handlebars.io.ClassPathTemplateLoader;
/**
* @author Marcin Grzejszczak
*/
@@ -18,8 +18,10 @@ public class TemplateGenerator {
private static final String EMAIL_TEMPLATE = "email";
private static final String BLOG_TEMPLATE = "blog";
private static final String TWITTER_TEMPLATE = "tweet";
private final File emailOutput = new File("target/email.txt");
private final File blogOutput = new File("target/blog.md");
private final File tweetOutput = new File("target/tweet.txt");
private final ReleaserProperties props;
public TemplateGenerator(ReleaserProperties props) {
@@ -54,6 +56,13 @@ public class TemplateGenerator {
return new BlogTemplateGenerator(template, releaseVersion, blogOutput, projects).blog();
}
public File tweet() {
File output = file(this.tweetOutput);
String releaseVersion = parsedVersion();
Template template = template(TWITTER_TEMPLATE);
return new TwitterTemplateGenerator(template, releaseVersion, output).tweet();
}
private String parsedVersion() {
String version = this.props.getPom().getBranch();
if (version.startsWith("v")) {

View File

@@ -0,0 +1,33 @@
package org.springframework.cloud.release.internal.template;
import com.github.jknack.handlebars.Template;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
/**
* @author Marcin Grzejszczak
*/
class TwitterTemplateGenerator {
private final Template template;
private final String releaseVersion;
private final File output;
TwitterTemplateGenerator(Template template, String releaseVersion, File output) {
this.template = template;
this.releaseVersion = releaseVersion;
this.output = output;
}
File tweet() {
try {
String tweet = this.template.apply(this.releaseVersion);
Files.write(this.output.toPath(), tweet.getBytes());
return this.output;
}
catch (IOException e) {
throw new IllegalStateException(e);
}
}
}

View File

@@ -0,0 +1 @@
The {{ this }} version of @springcloud has been released!

View File

@@ -37,6 +37,26 @@ public class TemplateGeneratorTests {
then(generatedMail).hasContent(expectedEmail());
}
@Test
public void should_generate_tweet_from_template_for_tag_with_v_prefix() {
ReleaserProperties props = new ReleaserProperties();
props.getPom().setBranch("vDalston.RELEASE");
File generatedTweet = new TemplateGenerator(props).tweet();
then(generatedTweet).hasContent(expectedTweet());
}
@Test
public void should_generate_tweet_from_template_for_tag_without_v_prefix() {
ReleaserProperties props = new ReleaserProperties();
props.getPom().setBranch("Dalston.RELEASE");
File generatedTweet = new TemplateGenerator(props).tweet();
then(generatedTweet).hasContent(expectedTweet());
}
@Test
public void should_generate_blog_from_template_for_tag_with_v_prefix_release()
throws IOException {
@@ -244,4 +264,8 @@ public class TemplateGeneratorTests {
+ "link to twitter\n\n"
+ "Cheers,\n";
}
private String expectedTweet() {
return "The Dalston.RELEASE version of @springcloud has been released!";
}
}

View File

@@ -58,10 +58,11 @@ public class SpringReleaser {
"Close the milestone at Github",
args -> args.releaser.closeMilestone(args.versionFromScRelease)),
task("CREATING TEMPLATES",
"Create email / tweet etc. templates",
"Create email / blog / tweet etc. templates",
args -> {
args.releaser.createEmail(args.versionFromScRelease);
args.releaser.createBlog(args.versionFromScRelease, args.projects);
args.releaser.createTweet(args.versionFromScRelease);
})
).collect(Collectors.toList());

View File

@@ -102,6 +102,9 @@ public class AcceptanceTests {
then(blogTemplate()).exists();
then(blogTemplateContents())
.contains("I am pleased to announce that the Release Candidate 1 (RC1)");
then(tweetTemplate()).exists();
then(tweetTemplateContents())
.contains("The Dalston.RC1 version of @springcloud has been released!");
}
@Test
@@ -123,6 +126,9 @@ public class AcceptanceTests {
then(blogTemplate()).exists();
then(blogTemplateContents())
.contains("I am pleased to announce that the Release Candidate 1 (RC1)");
then(tweetTemplate()).exists();
then(tweetTemplateContents())
.contains("The Dalston.RC1 version of @springcloud has been released!");
}
private Iterable<RevCommit> listOfCommits(File project) throws GitAPIException {
@@ -172,10 +178,18 @@ public class AcceptanceTests {
return new File("target/blog.md");
}
private File tweetTemplate() throws URISyntaxException {
return new File("target/tweet.txt");
}
private String blogTemplateContents() throws URISyntaxException, IOException {
return new String(Files.readAllBytes(blogTemplate().toPath()));
}
private String tweetTemplateContents() throws URISyntaxException, IOException {
return new String(Files.readAllBytes(tweetTemplate().toPath()));
}
private SpringReleaser releaser(File projectFile, String branch, String expectedVersion) throws Exception {
ReleaserProperties properties = releaserProperties(projectFile, branch);
Releaser releaser = defaultReleaser(expectedVersion, properties);