Exemple #1
0
def assign_issue(number, user):
    g = auth_git()
    r = g.get_repo(properties.get('GITHUB_REPO'))
    i = r.get_issue(number)
    print('assigning issue#{0} to {1} on repo {2}'.format(number, user, properties.get('GITHUB_REPO')))
    u = g.get_user(user)
    i.edit(assignee=u)
Exemple #2
0
    def event_fired(self, content):
        if content.get('action') != "opened":
            return
        repo_name = properties.get('GITHUB_REPO')
        branch = content.get('pull_request').get('head').get('ref')
        base_url = "http://raw.github.com/{0}/{1}".format(repo_name, branch)
        sentry.captureMessage('base_url is {0}'.format(base_url))

        repo = git.get_repo()
        num = content.get('pull_request').get('number')
        sentry.captureMessage('pull_request number is {0}'.format(num))
        p = repo.get_pull(num)
        files = p.get_files()

        fd = {}
        ire = {}

        for f in files:
            sentry.captureMessage('working on file: {0}'.format(f.filename))
            if "/" in f.filename:
                dire = '/'.join(f.filename.split("/")[:-1])
            else:
                dire = '/'

            fd[f.filename] = {'changes': f.changes, 
                    'additions': f.additions, 
                    'deletions': f.deletions,
                    }

            if ire.get(dire):
                score = ire.get(dire) + f.changes
            else:
                score = f.changes
            ire[dire] = score

        sorted_ire = sorted(ire.iteritems(), key=operator.itemgetter(1))
        sorted_ire.reverse()
        p = sorted_ire[0][0]
        url = '{0}/{1}/MAINTAINERS'.format(base_url, p)
        print url
        maintainer = urlopen(url).readline()
        if not maintainer:
            sentry.captureMessage('maintainer not found for url {0}'.format(url))
            return
        maintainer_handle = maintainer.split('@')[2].strip()[:-1]
        sentry.captureMessage('read MAINTAINER from {0} and maintainer handle is {1}'.format(url, maintainer_handle))
        assign_issue(num, maintainer_handle)
        create_comment(num, 'cc @{0}, this issue was automatically assigned to you by Gordon'.format(maintainer_handle))
Exemple #3
0
def _maintainer_from_path(path):
    repo_name = properties.get('GITHUB_REPO')

    base_url = "http://raw.github.com/{0}/master".format(repo_name)
    print('base_url is {0}'.format(base_url))
    # based on a path, traverse it backward until you find the maintainer.
    url = '{0}/{1}/MAINTAINERS'.format(base_url, path)
    print url
    maintainer = urlopen(url).readline()
    try:
        print maintainer
        maintainer_handle = maintainer.split('@')[2].strip()[:-1]
        print('read MAINTAINER from {0} and maintainer handle is {1}'.format(url, maintainer_handle))
        return maintainer_handle
    except:
        print('unable to parse maintainer file. invalid format.')
        return _maintainer_from_path('/'.join(path.split('/')[:-1]))
Exemple #4
0
def get_repo():
    g = auth_git()
    print('getting repo {0}'.format(properties.get('GITHUB_REPO')))
    docker_repo = g.get_repo(properties.get('GITHUB_REPO'))
    return docker_repo
Exemple #5
0
def auth_git():
    return git(properties.get('GITHUB_USERNAME'), properties.get('GITHUB_PASSWORD'), timeout=3000)
Exemple #6
0
def update_status(commit_id, state, **kwargs):
    g = auth_git()
    repo = g.get_repo(properties.get('GITHUB_REPO'))
    commit = repo.get_commit(commit_id)
    commit.create_status(state, **kwargs)
    print "created status.."
Exemple #7
0
import redis

from web.config import properties
from web.model import Issue

redis_connection = redis.StrictRedis(host=properties.get("REDIS_HOST"), port=int(properties.get("REDIS_PORT")))


def retrieve_view(key, start=0, stop=4):
    return map(lambda x: obj_from_key(x), redis_connection.lrange(key, start, stop))


def obj_from_key(key):
    if "issue:" in key or "pull:" in key:
        return Issue().from_dict(redis_connection.hgetall(key))
Exemple #8
0
import redis 

from web.config import properties
from web.model import Issue

redis_connection = redis.StrictRedis(host=properties.get('REDIS_HOST'), port=int(properties.get('REDIS_PORT')))


def retrieve_view(key, start=0, stop=4):
    return map(lambda x: obj_from_key(x), redis_connection.lrange(key, start, stop))

def obj_from_key(key):
    if "issue:" in key or "pull:" in key:
        return Issue().from_dict(redis_connection.hgetall(key))