Last active
May 24, 2018 21:00
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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