Consumes the merge_request JSON as a python object and turn it into a buildbot change.

        :arguments:
            payload
                Python Object that represents the JSON sent by GitLab Service
                Hook.
324069
def _process_merge_request_change(self, payload, event, codebase=None):
        
        attrs = payload['object_attributes']
        commit = attrs['last_commit']
        when_timestamp = dateparse(commit['timestamp'])
        # @todo provide and document a way to choose between http and ssh url
        repo_url = attrs['target']['git_http_url']
        # project name from http headers is empty for me, so get it from object_attributes/target/name
        project = attrs['target']['name']

        # Filter out uninteresting events
        state = attrs['state']
        if re.match('^(closed|merged|approved)$', state):
            log.msg("GitLab MR#{}: Ignoring because state is {}".format(attrs['iid'], state))
            return []
        action = attrs['action']
        if not re.match('^(open|reopen)$', action) and not (action == "update" and "oldrev" in attrs):
            log.msg("GitLab MR#{}: Ignoring because action {} was not open or "
                    "reopen or an update that added code".format(attrs['iid'],
                                                                 action))
            return []

        changes = [{
            'author': '%s <%s>' % (commit['author']['name'],
                                   commit['author']['email']),
            'files': [],  # @todo use rest API
            'comments': "MR#{}: {}\n\n{}".format(attrs['iid'], attrs['title'], attrs['description']),
            'revision': commit['id'],
            'when_timestamp': when_timestamp,
            'branch': attrs['target_branch'],
            'repository': repo_url,
            'project': project,
            'category': event,
            'revlink': attrs['url'],
            'properties': {
                'source_branch': attrs['source_branch'],
                'source_project_id': attrs['source_project_id'],
                'source_repository': attrs['source']['git_http_url'],
                'source_git_ssh_url': attrs['source']['git_ssh_url'],
                'target_branch': attrs['target_branch'],
                'target_project_id': attrs['target_project_id'],
                'target_repository': attrs['target']['git_http_url'],
                'target_git_ssh_url': attrs['target']['git_ssh_url'],
                'event': event,
            },
        }]
        if codebase is not None:
            changes[0]['codebase'] = codebase
        return changes
112190
def patch(self, endpoint, json=None, params=None, **kwargs):
        
        json = kwargs['data'] if 'data' in kwargs else json
        return self._make_request('patch', endpoint, data=json, params=params)
976101
def to_json(self):
        

        result = super(Webhook, self).to_json()
        result.update({
            'name': self.name,
            'url': self.url,
            'topics': self.topics,
            'httpBasicUsername': self.http_basic_username,
            'headers': self.headers
        })

        if self.filters:
            result.update({'filters': self.filters})

        if self.transformation:
            result.update({'transformation': self.transformation})

        return result
621655
def as_json(options={})
      options = @options.merge(options)

      if options[:root]
        { options[:root].to_sym => serializable_hash }.merge(meta_hash).merge(data_hash)
      else
        serializable_hash
      end
    end
161457
def to_json
      loop do
        begin
          json = @payload.to_json
        rescue *JSON_EXCEPTIONS => ex
          @config.logger.debug("#{LOG_LABEL} `notice.to_json` failed: #{ex.class}: #{ex}")
        else
          return json if json && json.bytesize <= MAX_NOTICE_SIZE
        end

        break if truncate == 0
      end
    end
289997
def _create_json(self):
        
        data_json = {
            "rclass": "local",
            "key": self.name,
            "description": self.description,
            "packageType": self.packageType,
            "notes": "",
            "includesPattern": "**/*",
            "excludesPattern": "",
            "repoLayoutRef": self.repoLayoutRef,
            "dockerApiVersion": self.dockerApiVersion,
            "checksumPolicyType": "client-checksums",
            "handleReleases": True,
            "handleSnapshots": True,
            "maxUniqueSnapshots": 0,
            "snapshotVersionBehavior": "unique",
            "suppressPomConsistencyChecks": True,
            "blackedOut": False,
            "propertySets": [],
            "archiveBrowsingEnabled": self.archiveBrowsingEnabled,
            "yumRootDepth": 0,
        }
        return data_json
1102401
def merge_request(self, request_id):
        
        request_url = "{}pull-request/{}/merge".format(self.create_basic_url(),
                                                       request_id)

        return_value = self._call_api(request_url, method='POST')

        LOG.debug(return_value)
564193
def extract_payload(self, request, verify=True, *args, **kwargs):
        
        payload = self._verify(
            request, return_payload=True, verify=verify, *args, **kwargs
        )
        return payload
1332938
def _perform_update(self, method, resource, payload):
        '''
        
        '''

        # python2/3 compatibility wizardry
        try:
            file_type = file
        except NameError:
            file_type = IOBase

        if isinstance(payload, (dict, list)):
            response = self._perform_request(method, resource,
                                             data=json.dumps(payload))
        elif isinstance(payload, file_type):
            headers = {
                "content-type": "text/csv",
            }
            response = self._perform_request(method, resource, data=payload,
                                             headers=headers)
        else:
            raise Exception("Unrecognized payload {0}. Currently only list-, dictionary-,"
                            " and file-types are supported.".format(type(payload)))

        return response
129030
def put(self, json=None):
        
        return self._call('put', url=self.endpoint, json=json)
773238
def put(self, file):
        
        input_ = {
            "message": file.logs,
            "author": file.author.dict(),
            "content": file.base64,
            "branch": file.branch
        }
        uri = "{api}/repos/{origin}/contents/{path}".format(
            api=self.github_api_url,
            origin=self.origin,
            path=file.path
        )
        data = self.request("PUT", uri, data=input_)

        if data.status_code == 201:
            file.pushed = True
            return file
        else:
            decoded_data = json.loads(data.content.decode("utf-8"))
            return self.ProxyError(
                data.status_code, (decoded_data, "message"),
                step="put", context={
                    "uri": uri,
                    "params": input_
                }
            )
6572
def to_api_repr(self):
        
        info = super(StructEntry, self).to_api_repr()
        info["jsonPayload"] = self.payload
        return info
929425
def json_input(f):
    

    @wraps(f)
    def json_input_decorator(*args, **kwargs):
        # If the data is already transformed, we do not transform it any
        # further.
        task_data = _get_data_from_args(args)

        if task_data is None:
            logging.error("Task data is empty during JSON decoding.")

        if task_data.payload:
            try:
                is_transformed = request.get_json()

                # We transform the data only in the case of plain POST requests.
                if not is_transformed:
                    task_data.transform_payload(json.loads)
            except (ValueError, RuntimeError):
                logging.error(
                    "Exception while processing JSON input decorator.")
                task_data.transform_payload(json.loads)
        else:
            task_data.transform_payload(lambda _: {})

        return f(*args, **kwargs)

    return json_input_decorator
517748
def _message_to_payload(cls, message):
        ''''''
        try:
            return json.loads(message.decode())
        except UnicodeDecodeError:
            message = 'messages must be encoded in UTF-8'
        except json.JSONDecodeError:
            message = 'invalid JSON'
        raise cls._error(cls.PARSE_ERROR, message, True, None)
1238228
def request_payload(cls, request, request_id):
        ''''''
        if isinstance(request.args, dict):
            raise ProtocolError.invalid_args(
                'JSONRPCv1 does not support named arguments')
        return {
            'method': request.method,
            'params': request.args,
            'id': request_id
        }
1084039
def adopt(self, payload, *args, flavour: ModuleType, **kwargs):
        
        if args or kwargs:
            payload = functools.partial(payload, *args, **kwargs)
        self._meta_runner.register_payload(payload, flavour=flavour)
513067
def users_me_merge(self, data, **kwargs):
        ""
        api_path = "/api/v2/users/me/merge.json"
        return self.call(api_path, method="PUT", data=data, **kwargs)