forked from qt-creator/qt-creator
Gerrit: Resolve and store gerrit version
This can be used for enabling features that are available from a specific version. Change-Id: I4ce1c8684df2b8e194e8bbb02769ba99fc256408 Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
committed by
Orgad Shaneh
parent
a83755157b
commit
5a7a8cbf74
@@ -32,6 +32,7 @@
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/shellcommand.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/synchronousprocess.h>
|
||||
|
||||
#include <QFile>
|
||||
#include <QJsonDocument>
|
||||
@@ -47,12 +48,14 @@ namespace Internal {
|
||||
|
||||
static const char defaultHostC[] = "codereview.qt-project.org";
|
||||
static const char accountUrlC[] = "/accounts/self";
|
||||
static const char versionUrlC[] = "/config/server/version";
|
||||
static const char isGerritKey[] = "IsGerrit";
|
||||
static const char rootPathKey[] = "RootPath";
|
||||
static const char userNameKey[] = "UserName";
|
||||
static const char fullNameKey[] = "FullName";
|
||||
static const char isAuthenticatedKey[] = "IsAuthenticated";
|
||||
static const char validateCertKey[] = "ValidateCert";
|
||||
static const char versionKey[] = "Version";
|
||||
|
||||
enum ErrorCodes
|
||||
{
|
||||
@@ -151,8 +154,10 @@ bool GerritServer::fillFromRemote(const QString &remote,
|
||||
host = r.host;
|
||||
port = r.port;
|
||||
user.userName = r.userName.isEmpty() ? parameters.server.user.userName : r.userName;
|
||||
if (type == GerritServer::Ssh)
|
||||
if (type == GerritServer::Ssh) {
|
||||
resolveVersion(parameters, forceReload);
|
||||
return true;
|
||||
}
|
||||
curlBinary = parameters.curl;
|
||||
if (curlBinary.isEmpty() || !QFile::exists(curlBinary))
|
||||
return false;
|
||||
@@ -164,7 +169,12 @@ bool GerritServer::fillFromRemote(const QString &remote,
|
||||
// The rest of the path needs to be inspected to find the root path
|
||||
// (can be http://example.net/review)
|
||||
ascendPath();
|
||||
return resolveRoot();
|
||||
if (resolveRoot()) {
|
||||
resolveVersion(parameters, forceReload);
|
||||
saveSettings(Valid);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
case NotGerrit:
|
||||
return false;
|
||||
case Valid:
|
||||
@@ -318,5 +328,45 @@ bool GerritServer::resolveRoot()
|
||||
return false;
|
||||
}
|
||||
|
||||
void GerritServer::resolveVersion(const GerritParameters &p, bool forceReload)
|
||||
{
|
||||
static GitClient *const client = GitPlugin::client();
|
||||
QSettings *settings = Core::ICore::settings();
|
||||
const QString fullVersionKey = "Gerrit/" + host + '/' + versionKey;
|
||||
version = settings->value(fullVersionKey).toString();
|
||||
if (!version.isEmpty() && !forceReload)
|
||||
return;
|
||||
if (type == Ssh) {
|
||||
SynchronousProcess process;
|
||||
QStringList arguments;
|
||||
if (port)
|
||||
arguments << p.portFlag << QString::number(port);
|
||||
arguments << hostArgument() << "gerrit" << "version";
|
||||
const SynchronousProcessResponse resp = client->vcsFullySynchronousExec(
|
||||
QString(), FileName::fromString(p.ssh), arguments,
|
||||
Core::ShellCommand::NoOutput);
|
||||
QString stdOut = resp.stdOut().trimmed();
|
||||
stdOut.remove("gerrit version ");
|
||||
version = stdOut;
|
||||
} else {
|
||||
const QStringList arguments = curlArguments() << (url(RestUrl) + versionUrlC);
|
||||
const SynchronousProcessResponse resp = client->vcsFullySynchronousExec(
|
||||
QString(), FileName::fromString(curlBinary), arguments,
|
||||
Core::ShellCommand::NoOutput);
|
||||
// REST endpoint for version is only available from 2.8 and up. Do not consider invalid
|
||||
// if it fails.
|
||||
if (resp.result == SynchronousProcessResponse::Finished) {
|
||||
QString output = resp.stdOut();
|
||||
if (output.isEmpty())
|
||||
return;
|
||||
output.remove(0, output.indexOf('\n')); // Strip first line
|
||||
output.remove('\n');
|
||||
output.remove('"');
|
||||
version = output;
|
||||
}
|
||||
}
|
||||
settings->setValue(fullVersionKey, version);
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Gerrit
|
||||
|
||||
@@ -75,14 +75,13 @@ public:
|
||||
QString hostArgument() const;
|
||||
QString url(UrlType urlType = DefaultUrl) const;
|
||||
bool fillFromRemote(const QString &remote, const GerritParameters ¶meters, bool forceReload);
|
||||
StoredHostValidity loadSettings();
|
||||
void saveSettings(StoredHostValidity validity) const;
|
||||
int testConnection();
|
||||
QStringList curlArguments() const;
|
||||
|
||||
QString host;
|
||||
GerritUser user;
|
||||
QString rootPath; // for http
|
||||
QString version;
|
||||
unsigned short port = 0;
|
||||
HostType type = Ssh;
|
||||
bool authenticated = true;
|
||||
@@ -90,9 +89,12 @@ public:
|
||||
|
||||
private:
|
||||
QString curlBinary;
|
||||
StoredHostValidity loadSettings();
|
||||
void saveSettings(StoredHostValidity validity) const;
|
||||
bool setupAuthentication();
|
||||
bool ascendPath();
|
||||
bool resolveRoot();
|
||||
void resolveVersion(const GerritParameters &p, bool forceReload);
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
Reference in New Issue
Block a user