Skip to content

Instantly share code, notes, and snippets.

@rhass
Created May 21, 2020 19:04
Show Gist options
  • Save rhass/ab6e567dd81433dfe17c8370e9f523c5 to your computer and use it in GitHub Desktop.
Save rhass/ab6e567dd81433dfe17c8370e9f523c5 to your computer and use it in GitHub Desktop.
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