Skip to content

Instantly share code, notes, and snippets.

@fmbenhassine
Last active May 24, 2018 21:00
Show Gist options
  • Save fmbenhassine/36f6b5f0fe3ca5364aa813b20ddfa74c to your computer and use it in GitHub Desktop.
Save fmbenhassine/36f6b5f0fe3ca5364aa813b20ddfa74c to your computer and use it in GitHub Desktop.
Easy Batch job that generates a release notes from issues of a given project on Github (for Easy Batch project in this example). #EasyBatch
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import org.easybatch.core.job.Job;
import org.easybatch.core.job.JobBuilder;
import org.easybatch.core.job.JobExecutor;
import org.easybatch.core.writer.FileRecordWriter;
import org.easybatch.extensions.gson.GsonRecordMapper;
import org.easybatch.json.JsonRecordReader;
import com.google.gson.Gson;
/**
* Easy Batch job that generates a release notes from issues of a given project on Github (for Easy Batch project in this example).
*/
public class ReleaseNoteJob {
public static void main(String[] args) throws Exception {
String version = args[0];
URL url = new URL("https://api.github.com/repos/EasyBatch/easybatch-framework/issues?milestone=" + version);
URLConnection connection = url.openConnection();
InputStream inputStream = connection.getInputStream();
JobExecutor jobExecutor = new JobExecutor();
Job job = JobBuilder.aNewJob()
.named("generate release notes")
.reader(new JsonRecordReader(inputStream))
.mapper(new GsonRecordMapper<>(new Gson(), Issue.class))
.writer(new FileRecordWriter("target/release-notes.md"))
.build();
jobExecutor.execute(job);
jobExecutor.shutdown();
inputStream.close();
}
class Issue {
private int number;
private String title;
public Issue(int number, String title) {
this.number = number;
this.title = title;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
@Override
public String toString() {
return String.format("* issue #%s : %s", number, title);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment