https://docs.atlassian.com/bitbucket-server/rest/6.0.0/bitbucket-rest.html#idp261
322541
async function mergePr(prNo, branchName) {
  logger.debug(`mergePr(${prNo}, ${branchName})`);
  // Used for "automerge" feature
  try {
    const pr = await getPr(prNo);
    if (!pr) {
      throw Object.assign(new Error('not-found'), { statusCode: 404 });
    }
    await api.post(
      `./rest/api/1.0/projects/${config.projectKey}/repos/${
        config.repositorySlug
      }/pull-requests/${prNo}/merge?version=${pr.version}`
    );
    await getPr(prNo, true);
  } catch (err) {
    if (err.statusCode === 404) {
      throw new Error('not-found');
    } else if (err.statusCode === 409) {
      throw new Error('repository-changed');
    } else {
      logger.warn({ err }, `Failed to merge PR`);
      return false;
    }
  }

  logger.debug({ pr: prNo }, 'PR merged');
  // Delete branch
  await deleteBranch(branchName);
  return true;
}
402956
public IBucket deserializeBucket(final DataInput pInput) throws TTIOException {
        try {
            final int kind = pInput.readInt();
            byte[] hash;
            switch (kind) {
            case IConstants.DATABUCKET:
                DataBucket dataBucket = new DataBucket(pInput.readLong(), pInput.readLong());
                for (int offset = 0; offset < IConstants.CONTENT_COUNT; offset++) {
                    int dataKind = pInput.readInt();
                    if (dataKind != IConstants.NULLDATA) {
                        if (dataKind == IConstants.DELETEDDATA) {
                            dataBucket.getDatas()[offset] = new DeletedData(pInput.readLong());
                        } else {
                            dataBucket.getDatas()[offset] = mDataFac.deserializeData(pInput);
                        }
                    }
                }
                return dataBucket;
            case IConstants.METABUCKET:
                MetaBucket metaBucket = new MetaBucket(pInput.readLong());
                final int mapSize = pInput.readInt();
                IMetaEntry key;
                IMetaEntry value;
                for (int i = 0; i < mapSize; i++) {
                    key = mEntryFac.deserializeEntry(pInput);
                    value = mEntryFac.deserializeEntry(pInput);
                    metaBucket.put(key, value);
                }
                return metaBucket;
            case IConstants.UBERBUCKET:
                UberBucket uberBucket =
                    new UberBucket(pInput.readLong(), pInput.readLong(), pInput.readLong());
                uberBucket.setReferenceKey(0, pInput.readLong());
                hash = new byte[pInput.readInt()];
                pInput.readFully(hash);
                uberBucket.setReferenceHash(IReferenceBucket.GUARANTEED_INDIRECT_OFFSET, hash);
                return uberBucket;
            case IConstants.INDIRCTBUCKET:
                IndirectBucket indirectBucket = new IndirectBucket(pInput.readLong());
                for (int offset = 0; offset < indirectBucket.getReferenceKeys().length; offset++) {
                    indirectBucket.setReferenceKey(offset, pInput.readLong());
                }
                for (int offset = 0; offset < indirectBucket.getReferenceHashs().length; offset++) {
                    hash = new byte[pInput.readInt()];
                    pInput.readFully(hash);
                    indirectBucket.setReferenceHash(offset, hash);
                }
                return indirectBucket;
            case IConstants.REVISIONROOTBUCKET:
                RevisionRootBucket revRootBucket =
                    new RevisionRootBucket(pInput.readLong(), pInput.readLong(), pInput.readLong());
                for (int offset = 0; offset < revRootBucket.getReferenceKeys().length; offset++) {
                    revRootBucket.setReferenceKey(offset, pInput.readLong());
                }
                for (int offset = 0; offset < revRootBucket.getReferenceHashs().length; offset++) {
                    hash = new byte[pInput.readInt()];
                    pInput.readFully(hash);
                    revRootBucket.setReferenceHash(offset, hash);
                }
                return revRootBucket;
            default:
                throw new IllegalStateException(
                    "Invalid Kind of Bucket. Something went wrong in the serialization/deserialization");
            }
        } catch (final IOException exc) {
            throw new TTIOException(exc);
        }
    }
806946
@Override
  public String requestDepositAddress(Currency currency, String... arguments) throws IOException {

    final BitsoDepositAddress response = getBitsoBitcoinDepositAddress();
    return response.getDepositAddress();
  }
593614
@Override
    public org.fcrepo.server.types.gen.MIMETypedStream getDatastreamDissemination(String pid,
                                                                                  String dsID,
                                                                                  String asOfDateTime) {
        MessageContext ctx = context.getMessageContext();
        Context context = ReadOnlyContext.getSoapContext(ctx);
        assertInitialized();
        try {
            org.fcrepo.server.storage.types.MIMETypedStream mimeTypedStream =
                    m_access.getDatastreamDissemination(context,
                                                        pid,
                                                        dsID,
                                                        DateUtility
                                                                .parseDateOrNull(asOfDateTime));
            org.fcrepo.server.types.gen.MIMETypedStream genMIMETypedStream =
                    TypeUtility
                            .convertMIMETypedStreamToGenMIMETypedStream(mimeTypedStream);
            return genMIMETypedStream;
        } catch (OutOfMemoryError oome) {
            LOG.error("Out of memory error getting " + dsID
                    + " datastream dissemination for " + pid);
            String exceptionText =
                    "The datastream you are attempting to retrieve is too large "
                            + "to transfer via getDatastreamDissemination (as determined "
                            + "by the server memory allocation.) Consider retrieving this "
                            + "datastream via REST at: ";
            String restURL =
                    describeRepository().getRepositoryBaseURL() + "/get/" + pid
                            + "/" + dsID;
            throw CXFUtility.getFault(new Exception(exceptionText + restURL));

        } catch (Throwable th) {
            LOG.error("Error getting datastream dissemination", th);
            throw CXFUtility.getFault(th);
        }
    }
945576
function createMachineID(val_bb3, val_ff2, val_3b3) {
	// Machine IDs are binary KV objects with root key MessageObject and three hashes named BB3, FF2, and 3B3.
	// I don't feel like writing a proper BinaryKV serializer, so this will work fine.

	let buffer = ByteBuffer.allocate(155, ByteBuffer.LITTLE_ENDIAN);
	buffer.writeByte(0); // 1 byte, total 1
	buffer.writeCString("MessageObject"); // 14 bytes, total 15

	buffer.writeByte(1); // 1 byte, total 16
	buffer.writeCString("BB3"); // 4 bytes, total 20
	buffer.writeCString(sha1(val_bb3)); // 41 bytes, total 61

	buffer.writeByte(1); // 1 byte, total 62
	buffer.writeCString("FF2"); // 4 bytes, total 66
	buffer.writeCString(sha1(val_ff2)); // 41 bytes, total 107

	buffer.writeByte(1); // 1 byte, total 108
	buffer.writeCString("3B3"); // 4 bytes, total 112
	buffer.writeCString(sha1(val_3b3)); // 41 bytes, total 153

	buffer.writeByte(8); // 1 byte, total 154
	buffer.writeByte(8); // 1 byte, total 155

	return buffer.flip().toBuffer();

	function sha1(input) {
		let hash = Crypto.createHash('sha1');
		hash.update(input, 'utf8');
		return hash.digest('hex');
	}
}
238965
static void getNumDataBytesAndNumECBytesForBlockID(int numTotalBytes,
                                                     int numDataBytes,
                                                     int numRSBlocks,
                                                     int blockID,
                                                     int[] numDataBytesInBlock,
                                                     int[] numECBytesInBlock) throws WriterException {
    if (blockID >= numRSBlocks) {
      throw new WriterException("Block ID too large");
    }
    // numRsBlocksInGroup2 = 196 % 5 = 1
    int numRsBlocksInGroup2 = numTotalBytes % numRSBlocks;
    // numRsBlocksInGroup1 = 5 - 1 = 4
    int numRsBlocksInGroup1 = numRSBlocks - numRsBlocksInGroup2;
    // numTotalBytesInGroup1 = 196 / 5 = 39
    int numTotalBytesInGroup1 = numTotalBytes / numRSBlocks;
    // numTotalBytesInGroup2 = 39 + 1 = 40
    int numTotalBytesInGroup2 = numTotalBytesInGroup1 + 1;
    // numDataBytesInGroup1 = 66 / 5 = 13
    int numDataBytesInGroup1 = numDataBytes / numRSBlocks;
    // numDataBytesInGroup2 = 13 + 1 = 14
    int numDataBytesInGroup2 = numDataBytesInGroup1 + 1;
    // numEcBytesInGroup1 = 39 - 13 = 26
    int numEcBytesInGroup1 = numTotalBytesInGroup1 - numDataBytesInGroup1;
    // numEcBytesInGroup2 = 40 - 14 = 26
    int numEcBytesInGroup2 = numTotalBytesInGroup2 - numDataBytesInGroup2;
    // Sanity checks.
    // 26 = 26
    if (numEcBytesInGroup1 != numEcBytesInGroup2) {
      throw new WriterException("EC bytes mismatch");
    }
    // 5 = 4 + 1.
    if (numRSBlocks != numRsBlocksInGroup1 + numRsBlocksInGroup2) {
      throw new WriterException("RS blocks mismatch");
    }
    // 196 = (13 + 26) * 4 + (14 + 26) * 1
    if (numTotalBytes !=
        ((numDataBytesInGroup1 + numEcBytesInGroup1) *
            numRsBlocksInGroup1) +
            ((numDataBytesInGroup2 + numEcBytesInGroup2) *
                numRsBlocksInGroup2)) {
      throw new WriterException("Total bytes mismatch");
    }

    if (blockID < numRsBlocksInGroup1) {
      numDataBytesInBlock[0] = numDataBytesInGroup1;
      numECBytesInBlock[0] = numEcBytesInGroup1;
    } else {
      numDataBytesInBlock[0] = numDataBytesInGroup2;
      numECBytesInBlock[0] = numEcBytesInGroup2;
    }
  }
224938
def _create_identifier(rdtype, name, content):
        
        sha256 = hashlib.sha256()
        sha256.update((rdtype + '/').encode('UTF-8'))
        sha256.update((name + '/').encode('UTF-8'))
        sha256.update(content.encode('UTF-8'))
        return sha256.hexdigest()[0:7]
725682
function generateEsJws(protect, bits, key) {
  if (key instanceof Buffer) {
    key = key.toString();
  } else if (typeof key !== 'string') {
    throw new TypeError('Key must be a buffer or a UTF-8 string');
  }
  if (!key.includes('-----BEGIN') || !key.includes('KEY-----')) {
    throw new TypeError('Key must be a PEM formatted EC private key');
  }
  let signer = crypto.createSign(`SHA${bits}`);
  signer.update(protect);
  let size = 32;
  if (bits === 384) {
    size = 48;
  } else if (bits === 512) {
    size = 66;
  }
  let signature = buf2b64url(ecdsa.derToConcat(signer.sign(key), size));
  return `${protect}.${signature}`;
}
807387
def sha256sum(path, blocksize=65536):
    
    sig = hashlib.sha256()
    with open(path, 'rb') as f:
        buf = f.read(blocksize)
        while len(buf) > 0:
            sig.update(buf)
            buf = f.read(blocksize)
    return sig.hexdigest()
784919
@Override
  public String requestDepositAddress(Currency currency, String... arguments) throws IOException {
    if (currency.equals(Currency.BTC)) {
      return getBitstampBitcoinDepositAddress().getDepositAddress();
    } else if (currency.equals(Currency.LTC)) {
      return getBitstampLitecoinDepositAddress().getDepositAddress();
    } else if (currency.equals(Currency.XRP)) {
      return getRippleDepositAddress().getAddressAndDt();
    } else if (currency.equals(Currency.BCH)) {
      return getBitstampBitcoinCashDepositAddress().getDepositAddress();
    } else if (currency.equals(Currency.ETH)) {
      return getBitstampEthereumDepositAddress().getDepositAddress();
    } else {
      throw new IllegalStateException("Unsupported currency " + currency);
    }
  }
882651
public HashMap<String, List<String>> parseUidAssignV1() {
    final String json = query.getContent();
    if (json == null || json.isEmpty()) {
      throw new BadRequestException(HttpResponseStatus.BAD_REQUEST,
          "Missing message content",
          "Supply valid JSON formatted data in the body of your request");
    }
    try {
      return JSON.parseToObject(json, UID_ASSIGN);
    } catch (IllegalArgumentException iae) {
      throw new BadRequestException("Unable to parse the given JSON", iae);
    }
  }
1109935
def _request(self, method, url, headers=None, params=None, **aio_kwargs):
        """"""
        auth = None
        access_token = params.pop(self.access_token_key, None)
        if access_token:
            headers['Authorization'] = "Bearer %s" % access_token
        else:
            auth = BasicAuth(self.client_id, self.client_secret)

        return super(Bitbucket2Client, self)._request(
            method, url, headers=headers, params=params, auth=auth, **aio_kwargs)
1253153
def unsigned_request(self, path, payload=None):
    
    headers = {"content-type": "application/json", "accept": "application/json", "X-accept-version": "2.0.0"}
    try:
      if payload:
        response = requests.post(self.uri + path, verify=self.verify, data=json.dumps(payload), headers=headers)
      else:
        response = requests.get(self.uri + path, verify=self.verify, headers=headers)
    except Exception as pro:
      raise BitPayConnectionError('Connection refused')
    return response
1153317
def p2sh_script
      h160 = CoinOp.syncbit(@network[:name]) do
        @native.get_hash160
      end
      self.class.new(blob: Bitcoin::Script.to_p2sh_script(h160), network: @network[:name])
    end
343861
function(bucketingKey) {
    try {
      // NOTE: the mmh library already does cast the hash value as an unsigned 32bit int
      // https://github.com/perezd/node-murmurhash/blob/master/murmurhash.js#L115
      var hashValue = murmurhash.v3(bucketingKey, HASH_SEED);
      var ratio = hashValue / MAX_HASH_VALUE;
      return parseInt(ratio * MAX_TRAFFIC_VALUE, 10);
    } catch (ex) {
      throw new Error(sprintf(ERROR_MESSAGES.INVALID_BUCKETING_ID, MODULE_NAME, bucketingKey, ex.message));
    }
  }
326485
function parseRepoURL(inputUrl) {
  if (!inputUrl) {
    throw new ServerlessError('URL is required');
  }

  const url = URL.parse(inputUrl.replace(/\/$/, ''));

  // check if url parameter is a valid url
  if (!url.host) {
    throw new ServerlessError('The URL you passed is not a valid URL');
  }

  switch (url.hostname) {
    case 'github.com': {
      return parseGitHubURL(url);
    }
    case 'bitbucket.org': {
      return parseBitbucketURL(url);
    }
    case 'gitlab.com': {
      return parseGitlabURL(url);
    }
    default: {
      const msg =
        'The URL you passed is not one of the valid providers: "GitHub", "Bitbucket", or "GitLab".';
      throw new ServerlessError(msg);
    }
  }
}
96383
boolean insertToBucket(int hashCode, int pointer, boolean spillingAllowed, boolean sizeAddAndCheckResize) throws IOException {
		final int posHashCode = findBucket(hashCode);
		// get the bucket for the given hash code
		final int bucketArrayPos = posHashCode >> table.bucketsPerSegmentBits;
		final int bucketInSegmentPos = (posHashCode & table.bucketsPerSegmentMask) << BUCKET_SIZE_BITS;
		final MemorySegment bucket = this.buckets[bucketArrayPos];
		return insertToBucket(bucket, bucketInSegmentPos, hashCode, pointer, spillingAllowed, sizeAddAndCheckResize);
	}