Giter VIP home page Giter VIP logo

lsm-ci's Introduction

lsm-ci

Github continuous integration service for libStorageMgmt

This service is based on the information available from: https://developer.github.com/guides/building-a-ci-server/ except that it's written in python instead of ruby. These examples use http://bottlepy.org and http://www.python-requests.org

Some interesting pieces of functionality that others may want to leverage (see actual code for more detail, these are excerpts):

Setting a status on a commit using the python 'requests' library

def _create_status(repo, sha1, state, desc, context, log_url=None):
    if '/' not in repo:
        raise Exception("Expecting repo to be in form user/repo %s" % repo)

    url = 'https://api.github.com/repos/%s/statuses/%s' % (repo, sha1)
    data = {'state': state, "description": desc, "context": context}

    if log_url:
        data["target_url"] = log_url

    r = requests.post(url, auth=(USER, TOKEN), json=data)
    if r.status_code == 201:
        print('We updated status %s' % str(data))
    else:
        print("Unexpected error on setting status %d" % r.status_code)

Verifying a sha1 payload signature

# Verify the payload using our shared secret with github
def _verify_signature(payload_body, header_signature):
    h = hmac.new(GIT_SECRET, payload_body, hashlib.sha1)
    signature = 'sha1=' + h.hexdigest()
    try:
        # Python 2.7 and later have this which is suggested
        return hmac.compare_digest(signature, header_signature)
    except AttributeError:
        return _tscmp(signature, header_signature)

Handling the event from github (using python bottle)

# The callback for the handler registered with github
@route('/event_handler', method='POST')
def e_handler():

    # Check secret before we do anything
    if not _verify_signature(request.body.read(),
                             request.headers['X-Hub-Signature']):
        response.status = 500
        return

    if request.headers['X-Github-Event'] == 'pull_request':
        repo = request.json["pull_request"]["base"]["repo"]["full_name"]
        sha = request.json["pull_request"]['head']['sha']
        branch = request.json["pull_request"]['head']['ref']
        
        # Set statuses etc. and run tests

    else:
        print("Got an unexpected header from github")
        for k, v in request.headers.items():
            print('%s:%s' % (str(k), str(v)))
        print(request.json)

lsm-ci's People

Contributors

tasleson avatar

Watchers

James Cloos avatar Joe Handzik avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.