def validate_commit(self, payload): """Check if a commit contains a file we are looking for.""" ret_vals = [] if type(payload) != dict: logger.error( 'Received {} instead of dict in validate_commit'.format( type(payload))) raise ValueError( 'Value supplied to validate_commit must be dict, received {}'. format(type(payload))) for item in payload['files']: if item.get('raw_url') is None: continue if is_root_package_json(item.get('raw_url')) or item.get( 'filename').lower().endswith('requirements.txt'): url_info = parse_for_meta(item.get('raw_url')) repo_data = { 'repo_name': url_info['repo'], 'sha': payload.get('sha'), 'user': url_info['user'], 'repo_type': item.get('filename').lower(), 'check_state': 'FOUND', 'target_file_url': item.get('raw_url') } ret_vals.append(repo_data) return ret_vals
def test_parse_for_metadata_includes_dashes(self): url = 'https://github.com/therodan/typescript-web-starterkit/raw/a7565173719bff61c5910d6fcdbdf8de2ff90374/package.json' res = parse_for_meta(url) self.assertEqual(res['user'], 'therodan') self.assertEqual(res['repo'], 'typescript-web-starterkit')
def test_parse_for_metadata_includes_dots(self): url = 'https://github.com/selfsun/selffun.github.io/commits/c04b63c3d04814363d22d764c717edb41bb1a971' res = parse_for_meta(url) self.assertEqual(res['user'], 'selfsun') self.assertEqual(res['repo'], 'selffun.github.io')
def test_parse_for_metadata_includes_underscores(self): url = 'https://github.com/cao5zy/design_microservice/commits/87effaafd92250582155574703a46eb2612687d8' res = parse_for_meta(url) self.assertEqual(res['user'], 'cao5zy') self.assertEqual(res['repo'], 'design_microservice')
def test_parse_for_metadata(self): url = 'https://github.com/xuqianjin/ExpressMongooseRestApi/raw/3b96ee2ec03212613bb3509a7d0f0cdad120bce6/package.json' res = parse_for_meta(url) self.assertEqual(res['user'], 'xuqianjin') self.assertEqual(res['repo'], 'ExpressMongooseRestApi')