def api_pr(): """ React to a received POST request""" WEBLOGGER.info(60 * "#") WEBLOGGER.info("Received POST request.") WEBLOGGER.debug('Access route: ' + str(request.access_route[:])) origin = request.access_route[0] # was using request.remote_addr. access_route could possibly be spoofed if origin not in styleguard.cfg['github_ips']: WEBLOGGER.warning("Origin of request UNKNOWN: " + origin) return 'Error' else: WEBLOGGER.debug("Origin of request: " + origin) try: payload = json.loads(request.form['payload'])['pull_request'] except KeyError: # crutch: if an invalid request arrives locally, load a json file directly if origin == '127.0.0.1': location = os.getenv('OPENSHIFT_REPO_DIR', '') with open(os.path.join(location, 'sample_payload.json'), 'r') as sample: payload = json.load(sample) else: raise styleguard.handle_payload(payload) return 'OK'
def manual_check(): """Initiate manual request for checking a PR""" WEBLOGGER.info('Manual PR check has been requested') WEBLOGGER.debug('Access route: ' + str(request.access_route[:])) # get the number of the requested pr (i.e. URL/check?pr=number) try: pr_number = int(request.args.get('pr', 0)) except ValueError: WEBLOGGER.error('Invalid PR ID! Skipping...') return 'Error: Invalid PR ID!' if pr_number: WEBLOGGER.info('PR number ' + str(pr_number)) styleguard.handle_payload(pr_number) return ('Received request for checking PR ' + str(pr_number)) else: WEBLOGGER.error('Invalid PR ID! Skipping...') return 'Error: Invalid PR ID!'