#42 Enable reading update info from GitHub Packages REST API

This commit is contained in:
Mat Sutcliffe
2020-07-03 21:10:16 +01:00
parent 8375881941
commit 38a1d24411
9 changed files with 198 additions and 7 deletions

View File

@@ -0,0 +1,52 @@
/* Copyright (C) 2020
* swift project community / contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated,
* or distributed except according to the terms contained in the LICENSE file.
*/
//! \file
#include "githubpackagesreader.h"
#include "blackcore/application.h"
#include "blackconfig/buildconfig.h"
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QStringBuilder>
#include <QUrl>
using namespace BlackMisc::Db;
using namespace BlackConfig;
namespace BlackCore
{
CGitHubPackagesReader::CGitHubPackagesReader(QObject *parent) : QObject(parent)
{}
void CGitHubPackagesReader::readUpdateInfo()
{
// https://docs.github.com/en/rest/reference/repos#releases
const QNetworkRequest request(QUrl(CBuildConfig::gitHubRepoApiUrl() % u"releases"));
auto reply = sApp->getNetworkAccessManager()->get(request);
connect(reply, &QNetworkReply::finished, this, [this, reply]
{
if (reply->error() == QNetworkReply::NoError)
{
const auto updateInfo = CUpdateInfo::fromGitHubReleasesJson(reply->readAll());
if (!updateInfo.isEmpty())
{
m_updateInfo.set(updateInfo);
}
}
reply->deleteLater();
});
}
CUpdateInfo CGitHubPackagesReader::getUpdateInfo() const
{
return m_updateInfo.get();
}
}