def jira_webhook():
    """Handle POST requests coming from JIRA, and pass a translated request to GitHub"""

    if not hmac.compare_digest(request.args.get('secret_token', '').encode('utf-8'), secret):
        return jsonify({"code": 403, "error": "Unauthorized"}), 403

    payload = json.loads(request.data.decode('utf-8'))
    event = payload['webhookEvent']
    desc = payload['issue']['fields']['description']
    repo_id, alert_id, _, _ = jiralib.parse_alert_info(desc)

    app.logger.debug('Received JIRA webhook for event "{event}"'.format(event=event))

    if repo_id is None:
        app.logger.debug('Ignoring JIRA webhook for issue not related to a code scanning alert.')
        return jsonify({}), 200

    with sync_lock:
        # we only care about updates to issues
        if event == jiralib.CREATE_EVENT:
            sync.issue_created(desc)
        elif event == jiralib.DELETE_EVENT:
            sync.issue_deleted(desc)
        elif event == jiralib.UPDATE_EVENT:
            sync.issue_changed(desc)
        else:
            app.logger.debug('Ignoring JIRA webhook for event "{event}".'.format(event=event))
            return jsonify({}), 200

    return jsonify({}), 200
 def issue_deleted(self, desc):
     repo_id, alert_num, _, _ = jiralib.parse_alert_info(desc)
     self.sync(
         self.github.getRepository(repo_id).get_alert(alert_num),
         self.jira.fetch_issues(repo_id, alert_num), DIRECTION_J2G)