Skip to content
This repository has been archived by the owner on Apr 15, 2020. It is now read-only.

Commit

Permalink
Capture Bitbucket API errors to Sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Apr 16, 2017
1 parent 054bd99 commit ae55e14
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
3 changes: 2 additions & 1 deletion badwolf/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from markupsafe import Markup

from badwolf.utils import to_text, to_binary, sanitize_sensitive_data
from badwolf.extensions import bitbucket
from badwolf.extensions import bitbucket, sentry
from badwolf.bitbucket import BuildStatus, BitbucketAPIError
from badwolf.notification import send_mail, trigger_slack_webhook

Expand Down Expand Up @@ -235,6 +235,7 @@ def update_build_status(self, state, description=None):
self.build_status.update(state, description=description)
except BitbucketAPIError:
logger.exception('Error calling Bitbucket API')
sentry.captureException()

def send_notifications(self, context):
exit_code = context['exit_code']
Expand Down
3 changes: 2 additions & 1 deletion badwolf/deploy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from flask import url_for

from badwolf.extensions import bitbucket
from badwolf.extensions import bitbucket, sentry
from badwolf.utils import run_command
from badwolf.bitbucket import BitbucketAPIError, BuildStatus
from badwolf.deploy.providers.script import ScriptProvider
Expand Down Expand Up @@ -80,3 +80,4 @@ def _update_build_status(self, build_status, state, description=None):
build_status.update(state, description=description)
except BitbucketAPIError:
logger.exception('Error calling Bitbucket API')
sentry.captureException()
7 changes: 6 additions & 1 deletion badwolf/lint/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from flask import url_for
from unidiff import UnidiffParseError

from badwolf.extensions import bitbucket
from badwolf.extensions import bitbucket, sentry
from badwolf.bitbucket import PullRequest, BitbucketAPIError, BuildStatus
from badwolf.lint import Problems
from badwolf.lint.linters.eslint import ESLinter
Expand Down Expand Up @@ -65,6 +65,7 @@ def load_changes(self):
changes = self.pr.diff(self.context.pr_id)
except (BitbucketAPIError, UnidiffParseError):
logger.exception('Error getting pull request diff from API')
sentry.captureException()
return

self.problems.set_changes(changes)
Expand Down Expand Up @@ -129,6 +130,7 @@ def _report(self):
comments = self.pr.all_comments(self.context.pr_id)
except BitbucketAPIError:
logger.exception('Error fetching all comments for pull request')
sentry.captureException()
comments = []

existing_comments_ids = {}
Expand Down Expand Up @@ -177,6 +179,7 @@ def _report(self):
)
except BitbucketAPIError:
logger.exception('Error creating inline comment for pull request')
sentry.captureException()
else:
problem_count += 1

Expand All @@ -194,10 +197,12 @@ def _report(self):
self.pr.delete_comment(self.context.pr_id, existing_comments_ids[comment])
except BitbucketAPIError:
logger.exception('Error deleting pull request comment')
sentry.captureException()
return problem_count

def update_build_status(self, state, description=None):
try:
self.build_status.update(state, description=description)
except BitbucketAPIError:
logger.exception('Error calling Bitbucket API')
sentry.captureException()
3 changes: 2 additions & 1 deletion badwolf/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from flask import current_app, url_for

from badwolf.spec import Specification
from badwolf.extensions import bitbucket
from badwolf.extensions import bitbucket, sentry
from badwolf.bitbucket import BuildStatus, BitbucketAPIError, PullRequest, Changesets
from badwolf.utils import to_text, sanitize_sensitive_data
from badwolf.cloner import RepositoryCloner
Expand Down Expand Up @@ -56,6 +56,7 @@ def start(self):
self._report_git_error(git_err)
except BitbucketAPIError:
logger.exception('Error calling BitBucket API')
sentry.captureException()
except BadwolfException:
pass
finally:
Expand Down
4 changes: 3 additions & 1 deletion badwolf/webhook/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from badwolf.context import Context
from badwolf.tasks import start_pipeline
from badwolf.extensions import bitbucket
from badwolf.extensions import bitbucket, sentry
from badwolf.bitbucket import BitbucketAPIError, PullRequest, BuildStatus


Expand Down Expand Up @@ -164,6 +164,7 @@ def handle_pull_request_approved(payload):
pr_info = pull_request.get(pr_id)
except BitbucketAPIError:
logger.exception('Error calling Bitbucket API')
sentry.captureException()
return

if pr_info['state'] != 'OPEN':
Expand All @@ -190,6 +191,7 @@ def handle_pull_request_approved(payload):
pull_request.merge(pr_id, message)
except BitbucketAPIError:
logger.exception('Error calling Bitbucket API')
sentry.captureException()


@register_event_handler('repo:commit_comment_created')
Expand Down

0 comments on commit ae55e14

Please sign in to comment.