message: Update Bitbucket API to be compatible with Version 2.0
diff: namespace {
  const QString kSshFmt = "git@bitbucket.org:%1";
  +const QString kContentType = "application/json";
  +const char *kPasswordProperty = "password";
  } // anon. namespace
  @@ -28,35 +30,49 @@ Bitbucket::Bitbucket(const QString &username)
  {
  QObject::connect(&mMgr, &QNetworkAccessManager::finished, this,
  [this](QNetworkReply *reply) {
  + QString password = reply->property(kPasswordProperty).toString();
  + if (password.isEmpty())
  + return;
  +
  reply->deleteLater();
  - if (reply->error() == QNetworkReply::NoError) {
  + if (reply->error() != QNetworkReply::NoError) {
  + mError->setText(tr("Connection failed"), reply->errorString());
  + mProgress->finish();
  + return;
  + }
  QJsonDocument doc = QJsonDocument::fromJson(reply->readAll());
  - QJsonArray array = doc.array();
  + QJsonObject jsonObject = doc.object();
  + QJsonArray array = jsonObject["values"].toArray();
  for (int i = 0; i < array.size(); ++i) {
  QJsonObject obj = array.at(i).toObject();
  - if (obj.value("scm").toString() != "git")
  - continue;
  -
  - QString name = obj.value("name").toString();
  - QString owner = obj.value("owner").toString();
  - QString fullName = QString("%1/%2").arg(owner, name);
  + QJsonObject repository = obj.value("repository").toObject();
  + QString name = repository.value("name").toString();
  + QString fullName = repository.value("full_name").toString();
  QUrl httpsUrl;
  httpsUrl.setHost(host());
  httpsUrl.setScheme("https");
  httpsUrl.setUserName(this->username());
  httpsUrl.setPath(QString("/%1").arg(fullName));
  -
  Repository *repo = addRepository(name, fullName);
  repo->setUrl(Repository::Https, httpsUrl.toString());
  repo->setUrl(Repository::Ssh, kSshFmt.arg(fullName));
  }
  - } else {
  - mError->setText(tr("Connection failed"), reply->errorString());
  - }
  + QString next = jsonObject["next"].toString();
  + if (next.isEmpty()) {
  mProgress->finish();
  + return;
  + }
  +
  + // Request next page.
  + QNetworkRequest request(next);
  + if (setHeaders(request, password)) {
  + QNetworkReply *reply = mMgr.get(request);
  + reply->setProperty(kPasswordProperty, password);
  + startProgress();
  + }
  });
  }
  @@ -79,14 +95,19 @@ void Bitbucket::connect(const QString &password)
  {
  clearRepos();
  - QNetworkRequest request(url() + "/user/repositories");
  + QNetworkRequest request(url() + "/user/permissions/repositories?sort=repository.name&pagelen=100");
  + request.setHeader(QNetworkRequest::ContentTypeHeader, kContentType);
  +
  if (setHeaders(request, password)) {
  mMgr.get(request);
  + QNetworkReply *reply = mMgr.get(request);
  + reply->setProperty(kPasswordProperty,
  + !password.isEmpty() ? password : this->password());
  startProgress();
  }
  }
  QString Bitbucket::defaultUrl()
  {
  - return QStringLiteral("https://api.bitbucket.org/1.0");
  + return QStringLiteral("https://api.bitbucket.org/2.0");
  }
  