# -*- python -*-
# ex: set syntax=python:

import logging
import urllib2
import json
import string
import re

from password import *
from buildbot.status.web.hooks.github import GitHubEventHandler
from dateutil.parser import parse as dateparse
from twisted.python import log

builders_common="arch,"
builders_linux="centos7,centos8,centosstream8,debian10,fedora33,builtin,"
builders_freebsd="freebsd12,freebsd13,freebsd14"

builders_push_master=builders_common+builders_linux+builders_freebsd+"coverage"
builders_push_release=builders_common+builders_linux+builders_freebsd

builders_pr_master=builders_common+builders_linux+builders_freebsd
builders_pr_release=builders_common+builders_linux+builders_freebsd

# Default builders for non-top PR commits
builders_pr_minimum="arch"

def query_url(url, token=None):
    log.msg("Making request to '%s'" % url)
    request = urllib2.Request(url)
    if token:
        request.add_header("Authorization", "token %s" % token)
    response = urllib2.urlopen(request)

    return json.loads(response.read())

#
# Custom class to determine how to handle incoming Github changes.
#
class CustomGitHubEventHandler(GitHubEventHandler):
    valid_props = [
        ('^Build[-\s]linux:\s*(yes|no)\s*$', 'override-buildlinux'),
        ('^Build[-\s]zfs:\s*(yes|no)\s*$', 'override-buildzfs'),
        ('^Built[-\s]in:\s*(yes|no)\s*$', 'override-builtin'),
        ('^Check[-\s]lint:\s*(yes|no)\s*$', 'override-checklint'),
        ('^Configure[-|\s]zfs:(.*)$', 'override-configzfs'),