Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
properties = self.extractProperties(pr)
# emit the change
yield self.master.data.updates.addChange(
author=author,
committer=committer,
revision=bytes2unicode(revision),
revlink=bytes2unicode(revlink),
comments='GitHub Pull Request #{0} ({1} commit{2})\n{3}\n{4}'.
format(prnumber, commits, 's'
if commits > 0 else '', title, comments),
when_timestamp=datetime2epoch(updated),
branch=bytes2unicode(branch),
category=self.category,
project=project,
repository=bytes2unicode(repo),
files=files,
properties=properties,
src='git')
def submitChanges(self, changes, request, src):
for chdict in changes:
when_timestamp = chdict.get('when_timestamp')
if isinstance(when_timestamp, datetime):
chdict['when_timestamp'] = datetime2epoch(when_timestamp)
# unicodify stuff
for k in ('comments', 'author', 'committer', 'revision', 'branch', 'category',
'revlink', 'repository', 'codebase', 'project'):
if k in chdict:
chdict[k] = bytes2unicode(chdict[k])
if chdict.get('files'):
chdict['files'] = [bytes2unicode(f)
for f in chdict['files']]
if chdict.get('properties'):
chdict['properties'] = dict((bytes2unicode(k), v)
for k, v in chdict['properties'].items())
chid = yield self.master.data.updates.addChange(src=bytes2unicode(src), **chdict)
log.msg("injected change %s" % chid)
def getChanges(self, request):
secret = None
if isinstance(self.options, dict):
secret = self.options.get('secret')
try:
content = request.content.read()
payload = json.loads(bytes2unicode(content))
except Exception as exception:
raise ValueError('Error loading JSON: ' + str(exception))
if secret is not None and secret != payload['secret']:
raise ValueError('Invalid secret')
event_type = bytes2unicode(request.getHeader(_HEADER_EVENT_TYPE))
log.msg("Received event '{}' from gitea".format(event_type))
codebases = request.args.get('codebase', [None])
codebase = bytes2unicode(codebases[0])
changes = []
handler_function = getattr(self, 'process_{}'.format(event_type), None)
if not handler_function:
log.msg("Ignoring gitea event '{}'".format(event_type))
else:
changes = handler_function(payload, event_type, codebase)
def get_update(self, request):
content = request.content.read()
content = bytes2unicode(content)
content_type = request.getHeader(b'Content-Type')
content_type = bytes2unicode(content_type)
if content_type is not None and \
content_type.startswith('application/json'):
update = json.loads(content)
else:
raise ValueError('Unknown content type: {}'
.format(content_type))
return update
def checkFields(fields, negOk=False):
for field in fields:
k = bytes2unicode(field)
if k[0] == '-' and negOk:
k = k[1:]
if k not in entityType.fieldNames:
raise BadRequest("no such field '{}'".format(k))
entityType = endpoint.rtype.entityType
limit = offset = order = fields = None
filters, properties = [], []
for arg in reqArgs:
argStr = bytes2unicode(arg)
if arg == b'order':
order = tuple([bytes2unicode(o) for o in reqArgs[arg]])
checkFields(order, True)
elif arg == b'field':
fields = reqArgs[arg]
checkFields(fields, False)
elif arg == b'limit':
try:
limit = int(reqArgs[arg][0])
except Exception:
raise BadRequest('invalid limit')
elif arg == b'offset':
try:
offset = int(reqArgs[arg][0])
except Exception:
raise BadRequest('invalid offset')
elif arg == b'property':
try:
def forceIdentifier(maxLength, str):
if not isinstance(str, string_types):
raise TypeError("%r cannot be coerced to an identifier" % (str,))
# usually bytes2unicode can handle it
str = util.bytes2unicode(str)
if isIdentifier(maxLength, str):
return str
# trim to length and substitute out invalid characters
str = str[:maxLength]
str = initial_re.sub('_', str)
str = subsequent_re.subn('_', str)[0]
return str
def setProperty(self, name, value, source, runtime=False):
name = util.bytes2unicode(name)
json.dumps(value) # Let the exception propagate ...
source = util.bytes2unicode(source)
self.properties[name] = (value, source)
if runtime:
self.runtime.add(name)
# parse commit api page
page = yield client.getPage(str(pr['source']['commit']['links']['self']['href']))
commit_json = json.loads(page)
# use the full-length hash from now on
revision = commit_json['hash']
revlink = commit_json['links']['html']['href']
# parse repo api page
page = yield client.getPage(str(pr['source']['repository']['links']['self']['href']))
repo_json = json.loads(page)
repo = repo_json['links']['html']['href']
# update database
yield self._setCurrentRev(nr, revision)
# emit the change
yield self.master.data.updates.addChange(
author=bytes2unicode(author),
committer=None,
revision=bytes2unicode(revision),
revlink=bytes2unicode(revlink),
comments='pull-request #%d: %s\n%s' % (
nr, title, prlink),
when_timestamp=datetime2epoch(updated),
branch=bytes2unicode(branch),
category=self.category,
project=self.project,
repository=bytes2unicode(repo),
src='bitbucket',
)
def thd(conn):
patchid = None
if patch_body:
patch_body_bytes = unicode2bytes(patch_body)
patch_base64_bytes = base64.b64encode(patch_body_bytes)
ins = self.db.model.patches.insert()
r = conn.execute(ins, dict(
patchlevel=patch_level,
patch_base64=bytes2unicode(patch_base64_bytes),
patch_author=patch_author,
patch_comment=patch_comment,
subdir=patch_subdir))
patchid = r.inserted_primary_key[0]
return patchid
patchid = yield self.db.pool.do(thd)