diff options
| author | Menny Even Danan <menny@evendanan.net> | 2020-03-02 15:03:03 +0000 |
|---|---|---|
| committer | Menny Even Danan <menny@evendanan.net> | 2020-03-10 15:12:01 +0000 |
| commit | 75a0d3e3a6ba8bb187e2957c4f9e34c5b4f6ed5b (patch) | |
| tree | 4157a08b179fb4c1febc6d3d4c8b6cada633d3ea /buildSrc/src/main/java/github/Deployment.java | |
| parent | 2e9762f38bb0f779d75990b0e18687d64b5137a1 (diff) | |
| download | AnySoftKeyboard-75a0d3e3a6ba8bb187e2957c4f9e34c5b4f6ed5b.tar.gz AnySoftKeyboard-75a0d3e3a6ba8bb187e2957c4f9e34c5b4f6ed5b.tar.bz2 | |
Deploy-Request Gradle task and definition of promoting steps
Diffstat (limited to 'buildSrc/src/main/java/github/Deployment.java')
| -rw-r--r-- | buildSrc/src/main/java/github/Deployment.java | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/buildSrc/src/main/java/github/Deployment.java b/buildSrc/src/main/java/github/Deployment.java new file mode 100644 index 000000000..985e6ed01 --- /dev/null +++ b/buildSrc/src/main/java/github/Deployment.java @@ -0,0 +1,103 @@ +package github; + +import com.google.gson.Gson; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; +import java.util.List; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; + +public class Deployment { + + private final Gson mGson; + + private final String username; + private final String password; + + public Deployment(String username, String password) { + this.username = username; + this.password = password; + mGson = GsonCreator.create(); + } + + public Response requestDeployment(Request request) throws Exception { + final String requestJson = mGson.toJson(request); + System.out.println("Request: " + requestJson); + + try (CloseableHttpClient client = HttpClientCreator.create(username, password)) { + HttpPost httpPost = + new HttpPost( + "https://api.github.com/repos/AnySoftKeyboard/AnySoftKeyboard/deployments"); + httpPost.setHeader("Accept", "application/json"); + httpPost.setHeader("Content-type", "application/json"); + httpPost.setEntity(new StringEntity(requestJson, StandardCharsets.UTF_8)); + try (CloseableHttpResponse httpResponse = client.execute(httpPost)) { + System.out.println("Response status: " + httpResponse.getStatusLine()); + return mGson.fromJson( + new InputStreamReader(httpResponse.getEntity().getContent()), + Response.class); + } + } + } + + public static class Request { + public final String ref; + public final String task; + public final boolean auto_merge; + public final String environment; + public final String description; + public final List<String> required_contexts; + public final RequestPayloadField payload; + + public Request( + String ref, + String task, + boolean auto_merge, + String environment, + String description, + List<String> required_contexts, + RequestPayloadField payload) { + this.ref = ref; + this.task = task; + this.auto_merge = auto_merge; + this.environment = environment; + this.description = description; + this.required_contexts = required_contexts; + this.payload = payload; + } + } + + public static class RequestPayloadField { + public final List<String> environments_to_kill; + + public RequestPayloadField(List<String> environmentsToKill) { + environments_to_kill = environmentsToKill; + } + } + + public static class Response { + public final String id; + public final String sha; + public final String ref; + public final String task; + public final RequestPayloadField payload; + public final String environment; + + public Response( + String id, + String sha, + String ref, + String task, + RequestPayloadField payload, + String environment) { + this.id = id; + this.sha = sha; + this.ref = ref; + this.task = task; + this.payload = payload; + this.environment = environment; + } + } +} |
