-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add early support for Sentry Releases
See #47
- Loading branch information
Showing
9 changed files
with
227 additions
and
19 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"checkpoints": { | ||
"PROD": { "url": "https://prout-bot.herokuapp.com/", "overdue": "10M" } | ||
} | ||
}, | ||
"sentry": ["prout"] | ||
} |
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package lib.sentry | ||
|
||
import com.madgag.okhttpscala._ | ||
import com.netaporter.uri.Uri | ||
import com.typesafe.scalalogging.LazyLogging | ||
import lib.sentry.model.CreateRelease | ||
import okhttp3.Request.Builder | ||
import okhttp3._ | ||
import play.api.libs.json.Json.{stringify, toJson} | ||
|
||
import scala.concurrent.ExecutionContext.Implicits.global | ||
import scala.concurrent.Future | ||
|
||
class SentryApiClient(token: String , org: String) extends LazyLogging { | ||
|
||
val okHttpClient = new OkHttpClient | ||
|
||
val baseEndpoint = Uri.parse("https://sentry.io/api/0/") | ||
|
||
val JsonMediaType = MediaType.parse("application/json") | ||
|
||
def createRelease(createReleaseCommand: CreateRelease): Future[_] = { | ||
|
||
val request = new Builder().url(s"$baseEndpoint/organizations/$org/releases/") | ||
.header("Authorization", s"Bearer $token") | ||
.post(RequestBody.create(JsonMediaType, stringify(toJson(createReleaseCommand)))) | ||
.build() | ||
|
||
val responseF = okHttpClient.execute(request)(resp => logger.info(resp.body().string())) | ||
responseF.onComplete { | ||
tr => logger.info("Response from Sentry: " + tr) | ||
} | ||
responseF | ||
} | ||
|
||
def releasePageUrlFor(project: String)= s"https://sentry.io/$org/$project/releases/" | ||
|
||
def releasePageMarkdownFor(project: String)= s"[$project](${releasePageUrlFor(project)})" | ||
|
||
|
||
|
||
|
||
} | ||
|
||
|
||
object SentryApiClient { | ||
|
||
import play.api.Play.current | ||
val config = play.api.Play.configuration | ||
|
||
lazy val instanceOpt = for { | ||
org <- config.getString("sentry.org") | ||
token <- config.getString("sentry.token") | ||
} yield new SentryApiClient(token,org) | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package lib.sentry.model | ||
|
||
import java.time.Instant | ||
|
||
import com.netaporter.uri.Uri | ||
import org.eclipse.jgit.lib.ObjectId | ||
import play.api.libs.json.{JsString, Json, Writes} | ||
import Sentry._ | ||
import com.madgag.scalagithub.model.RepoId | ||
|
||
object Sentry { | ||
implicit val writesObjectId = new Writes[ObjectId] { | ||
def writes(oid: ObjectId) = JsString(oid.name) | ||
} | ||
|
||
} | ||
|
||
/** | ||
commits (array) – an optional list of commit data to be associated with the release. | ||
Commits must include parameters id (the sha of the commit), and can optionally include | ||
repository, message, author_name, author_email, and timestamp. | ||
*/ | ||
case class Commit( | ||
id: ObjectId, | ||
repository: Option[String], | ||
message: Option[String], | ||
author_name: Option[String], | ||
author_email: Option[String], | ||
timestamp: Option[Instant] | ||
) | ||
|
||
object Commit { | ||
implicit val writesCommit = Json.writes[Commit] | ||
} | ||
|
||
case class Ref( | ||
repository: RepoId, | ||
commit: ObjectId, | ||
previousCommit: Option[ObjectId] = None | ||
) | ||
|
||
object Ref { | ||
implicit val writesRepoId = new Writes[RepoId] { | ||
def writes(repoId: RepoId) = JsString(repoId.fullName) | ||
} | ||
implicit val writesRef = Json.writes[Ref] | ||
} | ||
|
||
/* | ||
https://docs.sentry.io/api/releases/post-organization-releases/ | ||
version (string) – a version identifier for this release. Can be a version number, a commit hash etc. | ||
ref (string) – an optional commit reference. This is useful if a tagged version has been provided. | ||
url (url) – a URL that points to the release. This can be the path to an online interface to the sourcecode for instance. | ||
projects (array) – a list of project slugs that are involved in this release | ||
dateReleased (datetime) – an optional date that indicates when the release went live. If not provided the current time is assumed. | ||
commits (array) – an optional list of commit data to be associated with the release. Commits must include parameters id (the sha of the commit), and can optionally include repository, message, author_name, author_email, and timestamp. | ||
refs (array) – an optional way to indicate the start and end commits for each repository included in a release. Head commits must include parameters repository and commit (the HEAD sha). They can optionally include previousCommit (the sha of the HEAD of the previous release), which should be specified if this is the first time you’ve sent commit data. | ||
*/ | ||
case class CreateRelease( | ||
version: String, | ||
ref: Option[String] = None, | ||
url: Option[Uri] = None, | ||
projects: Seq[String], | ||
dateReleased: Option[Instant] = None, | ||
commits: Seq[Commit] = Seq.empty, | ||
refs: Seq[Ref] = Seq.empty | ||
) | ||
|
||
object CreateRelease { | ||
implicit val writesUri = new Writes[Uri] { | ||
def writes(uri: Uri) = JsString(uri.toString) | ||
} | ||
|
||
implicit val writesCreateRelease = Json.writes[CreateRelease] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,21 +28,22 @@ <h3>Config files</h3> | |
@if(!proutPresenceQuickCheck) { | ||
<span class="octicon octicon-alert"></span> | ||
Quick check for @ProutConfigFileName failed! | ||
@if(repoSnapshot.config.checkpointsByFolder.nonEmpty) { | ||
@if(repoSnapshot.config.configByFolder.nonEmpty) { | ||
GitHub seems to be returning data different to the Git repo itself... | ||
} | ||
} | ||
|
||
<p> | ||
<ul> | ||
@for((folder, configInFolder) <- repoSnapshot.config.checkpointsByFolder) { | ||
@for((folder, configInFolder) <- repoSnapshot.config.configByFolder) { | ||
<li>@configLink(folder) @configInFolder.asOpt match { | ||
case None => { | ||
<span class="octicon octicon-alert" title="Invalid Prout JSON"></span> | ||
} | ||
case Some(validConfig) => { | ||
<span class="octicon octicon-check" title="Parsed as valid Prout JSON"></span> | ||
<h5>Checkpoints</h5> | ||
<ul> | ||
<h5>Checkpoints</h5> | ||
@for(checkpoint <- validConfig.checkpointSet) { | ||
<li> | ||
<b id="[email protected]">@checkpoint.name</b> - <a href="@checkpoint.details.url">@checkpoint.details.url</a> | ||
|
@@ -67,7 +68,20 @@ <h5>Checkpoints</h5> | |
} | ||
</li> | ||
} | ||
|
||
</ul> | ||
|
||
@for(sentryConf <- validConfig.sentry) { | ||
<h5>Sentry</h5> | ||
<ul> | ||
@for(sentryProject <- sentryConf.projects) { | ||
<li>@sentryProject</li> | ||
} | ||
</ul> | ||
@if(lib.sentry.SentryApiClient.instanceOpt.isEmpty) { | ||
...but no Sentry credentials are available! <span class="octicon octicon-alert" title="No Sentry Creds"></span> | ||
} | ||
} | ||
} | ||
} | ||
</li> | ||
|
Oops, something went wrong.