def matcher =  params.sha1 =~ /^refs\/remotes\/origin\/pr\/(?<pr_id>\d*)\/head$/
println("Begin github commenting")
if (matcher.matches()) {
	def pr_id = matcher.group("pr_id")
	def comment_url = "https://api.github.com/repos/theorchard/database/issues/${pr_id}/comments"
	def comment_text = "${params.ENV} deployment result ${build.result}"
	println("Posting comment to '${comment_url}'")
	println("Comment text is '${comment_text}'")
	withCredentials([string(credentialsId: 'orchardci', variable: 'GITHUB_TOKEN')]) {
		sh "curl -s -H \"Authorization: token ${GITHUB_TOKEN}\" -X POST -d '{\"body\": \"${comment_text}\"}' \"${comment_url}\""
	}
	println("Commenting complete")
} else {
	println("sha1 doesn't match for commenting. Skipping.")
}
