Created
May 21, 2020 19:04
-
-
Save rhass/ab6e567dd81433dfe17c8370e9f523c5 to your computer and use it in GitHub Desktop.
This file contains 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
public class GithubNotification { | |
import groovy.json.JsonOutput | |
String repoName | |
String repoOwner | |
String oauthToken | |
String headSha | |
public class Statuses { | |
String context | |
String description | |
def set(String state = "pending", String targetUrl = "") { | |
post = Connection | |
post.newInstance() | |
post.setRequestMethod("POST") | |
post.setRequestProperty("Content-Type", "application/json") | |
private Map<String, String> message = [ | |
target_url: targetUrl, | |
context: context, | |
head_sha: headSha, | |
description: description, | |
] | |
post.getOutputStream().write(JsonOutput.toJson(message.getBytes("UTF-8"))); | |
} | |
def get() { | |
get = Connection | |
get.newInstance() | |
get.setRequestMethod("GET") | |
return get.getOutputStream() | |
} | |
} | |
private class Connection { | |
def conn = new URL("https://github.com/repos/${repoOwner}/${repoName}/statuses/${headSha}").openConnection() | |
conn.setRequestProperty("Authorization", "token ${oauthToken}") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment