Skip to content

Commit

Permalink
1.0.0-rc.1 Release
Browse files Browse the repository at this point in the history
* First official release
  • Loading branch information
Andre Rabold committed Jul 5, 2017
1 parent da580df commit 148d5f4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 32 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "serverless-sentry",
"version": "1.0.0",
"version": "1.0.0-rc.1",
"description": "Serverless Sentry Plugin - Automatically send errors and exceptions to Sentry (https://sentry.io)",
"main": "src/index.js",
"author": "Andre Rabold",
Expand Down
6 changes: 2 additions & 4 deletions src/git-rev.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const exec = require("child_process").exec
, BbPromise = require("bluebird")
, path = require("path")
, _ = require("lodash");


Expand All @@ -12,7 +11,7 @@ class GitRev {

_command(cmd) {
return new BbPromise((resolve, reject) => {
exec(cmd, { cwd: _.get(this.opts, "cwd") }, function (err, stdout /*, stderr */) {
exec(cmd, this.opts, function (err, stdout /*, stderr */) {
return err ? reject(err) : resolve(_.trim(_.replace(stdout, /\n/g, "")));
});
});
Expand Down Expand Up @@ -48,8 +47,7 @@ class GitRev {
}

origin() {
return this._command("git config --get remote.origin.url")
.then(str => _.last(_.split(str, path.sep)));
return this._command("git config --get remote.origin.url");
}
}

Expand Down
61 changes: 34 additions & 27 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,42 +105,58 @@ class Sentry {

instrumentFunction(functionObject) {
const sentryConfig = _.assign({}, this.sentry, _.get(functionObject, "sentry"));
const envVars = {};

if (_.has(sentryConfig, "dsn")) {
functionObject.environment.SENTRY_DSN = sentryConfig.dsn;
_.set(functionObject, "environment.SENTRY_DSN", sentryConfig.dsn);
}
if (_.has(sentryConfig, "release.version")) {
functionObject.environment.SENTRY_RELEASE = sentryConfig.release.version;
_.set(functionObject, "environment.SENTRY_RELEASE", sentryConfig.release.version);
}
if (_.has(sentryConfig, "environment")) {
functionObject.environment.SENTRY_ENVIRONMENT = sentryConfig.environment;
_.set(functionObject, "environment.SENTRY_ENVIRONMENT", sentryConfig.environment);
}
if (_.has(sentryConfig, "autoBreadcrumbs")) {
functionObject.environment.SENTRY_AUTO_BREADCRUMBS = sentryConfig.autoBreadcrumbs;
_.set(functionObject, "environment.SENTRY_AUTO_BREADCRUMBS", sentryConfig.autoBreadcrumbs);
}
if (_.has(sentryConfig, "filterLocal")) {
functionObject.environment.SENTRY_FILTER_LOCAL = sentryConfig.filterLocal;
_.set(functionObject, "environment.SENTRY_FILTER_LOCAL", sentryConfig.filterLocal);
}
if (_.has(sentryConfig, "captureErrors")) {
functionObject.environment.SENTRY_CAPTURE_ERRORS = sentryConfig.captureErrors;
_.set(functionObject, "environment.SENTRY_CAPTURE_ERRORS", sentryConfig.captureErrors);
}
if (_.has(sentryConfig, "captureUnhandledRejections")) {
functionObject.environment.SENTRY_CAPTURE_UNHANDLED = sentryConfig.captureUnhandledRejections;
_.set(functionObject, "environment.SENTRY_CAPTURE_UNHANDLED", sentryConfig.captureUnhandledRejections);
}
if (_.has(sentryConfig, "captureMemoryWarnings")) {
functionObject.environment.SENTRY_CAPTURE_MEMORY = sentryConfig.captureMemoryWarnings;
_.set(functionObject, "environment.SENTRY_CAPTURE_MEMORY", sentryConfig.captureMemoryWarnings);
}
if (_.has(sentryConfig, "captureTimeoutWarnings")) {
functionObject.environment.SENTRY_CAPTURE_TIMEOUTS = sentryConfig.captureTimeoutWarnings;
_.set(functionObject, "environment.SENTRY_CAPTURE_TIMEOUTS", sentryConfig.captureTimeoutWarnings);
}

// Extend the function specific environment variables
functionObject.environment = _.assign(envVars, functionObject.environment);

return BbPromise.resolve(functionObject);
}

_resolveGitRefs(gitRev) {
return BbPromise.join(
gitRev.origin().then(str => str.match(/[:\/]([^\/]+\/[^\/]+?)(?:\.git)?$/i)[1]).catch(_.noop),
gitRev.long()
)
.spread((repository, commit) => {
_.forEach(_.get(this.sentry, "release.refs", []), ref => {
if (ref && ref.repository === "git") {
ref.repository = repository;
}
if (ref && ref.commit === "git") {
ref.commit = commit;
}
if (ref && ref.previousCommit === "git") {
delete ref.previousCommit; // not available via git
}
});
});
}

setRelease() {
if (this.sentry.release && !_.isPlainObject(this.sentry.release)) {
// Expand to the long form
Expand All @@ -161,22 +177,14 @@ class Sentry {
const gitRev = new GitRev({ cwd: this._serverless.config.servicePath });
return gitRev.tag()
.then(version => {
// Populate the refs (if not set manually already)
_.set(this.sentry, "release.version", version);
if (!_.has(this.sentry, "release.refs")) {
return BbPromise.join(
gitRev.origin()
.then(str => str.match(/[:\/]([^\/]+\/[^\/]+?)(\.git)?$/ig)[1])
.catch(_.noop),
gitRev.long()
)
.spread((repository, commit) => {
if (repository && commit) {
const refs = [{ repository, commit }];
_.set(this.sentry, "release.refs", refs);
}
});
// By default use git to resolve repository and commit hash
_.set(this.sentry, "release.refs", [{
repository: "git", commit: "git"
}]);
}
return this._resolveGitRefs(gitRev);
})
.catch(err => {
// No git available.
Expand Down Expand Up @@ -211,7 +219,6 @@ class Sentry {
const project = this.sentry.project;
const release = this.sentry.release;
this._serverless.cli.log(`Sentry: Creating new release "${release.version}"...`);

return BbPromise.fromCallback(cb =>
request.post(`https://sentry.io/api/0/organizations/${organization}/releases/`)
.set("Authorization", `Bearer ${this.sentry.authToken}`)
Expand Down

0 comments on commit 148d5f4

Please sign in to comment.