Gerrit: Replace bool argument with an enum, and merge url getters

Change-Id: I82035b37de31830f26297944ea0fce8b898201a4
Reviewed-by: André Hartmann <aha_1980@gmx.de>
This commit is contained in:
Orgad Shaneh
2017-03-02 08:37:56 +02:00
committed by Orgad Shaneh
parent 45ffa75054
commit 45a84ea6b5
3 changed files with 19 additions and 17 deletions

View File

@@ -200,7 +200,8 @@ QString GerritChange::filterString() const
QStringList GerritChange::gitFetchArguments(const GerritServer &server) const
{
const QString url = currentPatchSet.url.isEmpty() ? server.url(true) + '/' + project
const QString url = currentPatchSet.url.isEmpty()
? server.url(GerritServer::UrlWithHttpUser) + '/' + project
: currentPatchSet.url;
return {"fetch", url, currentPatchSet.ref};
}
@@ -271,7 +272,7 @@ QueryContext::QueryContext(const QString &query,
<< "--format=JSON" << query;
} else {
m_binary = p->curl;
const QString url = server.restUrl() + "/changes/?q="
const QString url = server.url(GerritServer::RestUrl) + "/changes/?q="
+ QString::fromUtf8(QUrl::toPercentEncoding(query))
+ "&o=CURRENT_REVISION&o=DETAILED_LABELS&o=DETAILED_ACCOUNTS";
m_arguments = GerritServer::curlArguments() << url;

View File

@@ -152,7 +152,7 @@ QString GerritServer::hostArgument() const
return user.userName.isEmpty() ? host : (user.userName + '@' + host);
}
QString GerritServer::url(bool withHttpUser) const
QString GerritServer::url(UrlType urlType) const
{
QString protocol;
switch (type) {
@@ -161,22 +161,17 @@ QString GerritServer::url(bool withHttpUser) const
case Https: protocol = "https"; break;
}
QString res = protocol + "://";
if (type == Ssh || withHttpUser)
if (type == Ssh || urlType != DefaultUrl)
res += hostArgument();
else
res += host;
if (port)
res += ':' + QString::number(port);
if (type != Ssh)
if (type != Ssh) {
res += rootPath;
return res;
}
QString GerritServer::restUrl() const
{
QString res = url(true);
if (type != Ssh && authenticated)
if (authenticated && urlType == RestUrl)
res += "/a";
}
return res;
}
@@ -238,7 +233,7 @@ QStringList GerritServer::curlArguments()
int GerritServer::testConnection()
{
static Git::Internal::GitClient *const client = Git::Internal::GitPlugin::client();
const QStringList arguments = curlArguments() << (restUrl() + accountUrlC);
const QStringList arguments = curlArguments() << (url(RestUrl) + accountUrlC);
const SynchronousProcessResponse resp = client->vcsFullySynchronousExec(
QString(), FileName::fromString(curlBinary), arguments,
Core::ShellCommand::NoOutput);

View File

@@ -54,12 +54,18 @@ public:
Ssh
};
enum UrlType
{
DefaultUrl,
UrlWithHttpUser,
RestUrl
};
GerritServer();
GerritServer(const QString &host, unsigned short port, const QString &userName, HostType type);
bool operator==(const GerritServer &other) const;
QString hostArgument() const;
QString url(bool withHttpUser = false) const;
QString restUrl() const;
QString url(UrlType urlType = DefaultUrl) const;
bool fillFromRemote(const QString &remote, const GerritParameters &parameters);
int testConnection();
static QStringList curlArguments();