예제 #1
0
def on_issue_comment(data):
    log_incoming_comment(data)
    subject = {
        "repo": data["repository"]["id"],
        "issue_id": data["issue"]["number"],
        "sender": data["sender"]["login"],
        "command": data["comment"]["body"]
    }

    action.execute("config.yaml", TOKEN, WORKFLOW, ADMINS.split(","),
                   "on_comment", subject)
예제 #2
0
def on_issues(data):
    logger.info("issue action:{} {}".format(data["action"],
                                            data["issue"]["number"]))
    git_action = data["action"]
    if git_action != "opened":
        return
    subject = {
        "repo": data["repository"]["id"],
        "issue_id": data["issue"]["number"],
        "sender": data["sender"]["login"],
        "command": "opened"
    }
    action.execute("config.yaml", TOKEN, WORKFLOW, ADMINS.split(","),
                   "on_issue", subject)
예제 #3
0
def webhook(request):
    if request.method != "POST":
        return "Method Not Allowed"

    data = request.get_json()
    event_type = request.headers["X-GitHub-Event"]
    event_action = data["action"]
    logger.log_struct({
        "Event Type": event_type,
        "Event ID": request.headers["X-GitHub-Delivery"],
        "Action": event_action
    })

    if event_type == "issues":
        if event_action != "opened":
            return "Action '{}' is not supported".format(event_action)
        subject = {
            "repo": data["repository"]["id"],
            "issue_id": data["issue"]["number"],
            "sender": data["sender"]["login"],
            "command": "opened"
        }
        logger.log_struct(subject)
        action.execute("config.yaml", TOKEN, WORKFLOW, ADMINS.split(","),
                       "on_issue", subject, float(INTERVAL))
        return "Event 'issues' had been processed."

    if event_type == "issue_comment":
        if event_action not in ["created", "edited"]:
            return "Action '{}' is not supported".format(event_action)
        subject = {
            "repo": data["repository"]["id"],
            "issue_id": data["issue"]["number"],
            "sender": data["sender"]["login"],
            "command": data["comment"]["body"]
        }
        logger.log_struct(subject)
        action.execute("config.yaml", TOKEN, WORKFLOW, ADMINS.split(","),
                       "on_comment", subject, float(INTERVAL))
        return "Event 'issue_comment' had been processed."

    return "Current event '{}' is not supported.".format(event_type)
예제 #4
0
def webhook():
    if request.method != "POST":
        return "405 Method not allowed"

    data = request.get_json(force=True)
    event_type = request.headers["X-GitHub-Event"]
    event_action = data["action"]

    if event_type == "issues":
        logger.info("issue action:{} {}".format(data["action"],
                                                data["issue"]["number"]))
        if event_action != "opened":
            return "Action '{}' is not supported".format(event_action)
        subject = {
            "repo": data["repository"]["id"],
            "issue_id": data["issue"]["number"],
            "sender": data["sender"]["login"],
            "command": "opened"
        }
        action.execute("config.yaml", TOKEN, WORKFLOW, ADMINS.split(","),
                       "on_issue", subject, float(INTERVAL))
        return "Event 'issue' had been processed."

    if event_type == "issue_comment":
        log_incoming_comment(data)
        if event_action not in ["created", "edited"]:
            return "Action '{}' is not supported".format(event_action)
        subject = {
            "repo": data["repository"]["id"],
            "issue_id": data["issue"]["number"],
            "sender": data["sender"]["login"],
            "command": data["comment"]["body"]
        }
        action.execute("config.yaml", TOKEN, WORKFLOW, ADMINS.split(","),
                       "on_comment", subject, float(INTERVAL))
        return "Event 'issue_comment' had been processed."

    return "Current event '{}' is not supported.".format(event_type)