dbhub: Support pushing to different branches than "master"

This commit is contained in:
Martin Kleusberg
2017-09-03 13:18:34 +02:00
parent 26f7cfbca4
commit 4339119377
6 changed files with 130 additions and 8 deletions

View File

@@ -181,6 +181,23 @@ void RemoteDatabase::gotReply(QNetworkReply* reply)
emit gotLicenceList(licences);
break;
}
case RequestTypeBranchList:
{
// Read and check results
QJsonDocument json = QJsonDocument::fromJson(reply->readAll());
if(json.isNull() || !json.isObject())
break;
QJsonObject obj = json.object();
// Parse data and assemble branch list
QStringList branches;
for(auto it=obj.constBegin();it!=obj.constEnd();++it)
branches.append(it.key());
// Send branch list to anyone who is interested
emit gotBranchList(branches);
break;
}
case RequestTypePush:
emit uploadFinished(reply->url().toString());
break;
@@ -392,7 +409,7 @@ void RemoteDatabase::fetch(const QString& url, RequestType type, const QString&
}
void RemoteDatabase::push(const QString& filename, const QString& url, const QString& clientCert, const QString& remotename,
const QString& commitMessage, const QString& licence, bool isPublic)
const QString& commitMessage, const QString& licence, bool isPublic, const QString& branch)
{
// Check if network is accessible. If not, abort right here
if(m_manager->networkAccessible() == QNetworkAccessManager::NotAccessible)
@@ -421,6 +438,7 @@ void RemoteDatabase::push(const QString& filename, const QString& url, const QSt
addPart(multipart, "commitmsg", commitMessage);
addPart(multipart, "licence", licence);
addPart(multipart, "public", isPublic ? "true" : "false");
addPart(multipart, "branch", branch);
// Set SSL configuration when trying to access a file via the HTTPS protocol
bool https = QUrl(url).scheme().compare("https", Qt::CaseInsensitive) == 0;

View File

@@ -41,11 +41,12 @@ public:
RequestTypeNewVersionCheck,
RequestTypePush,
RequestTypeLicenceList,
RequestTypeBranchList,
};
void fetch(const QString& url, RequestType type, const QString& clientCert = QString(), QVariant userdata = QVariant());
void push(const QString& filename, const QString& url, const QString& clientCert, const QString& remotename,
const QString& commitMessage = QString(), const QString& licence = QString(), bool isPublic = false);
const QString& commitMessage = QString(), const QString& licence = QString(), bool isPublic = false, const QString& branch = QString("master"));
signals:
// The openFile signal is emitted whenever a remote database file shall be opened in the main window. This happens when the
@@ -57,6 +58,7 @@ signals:
void gotDirList(QString json, QVariant userdata);
void gotCurrentVersion(QString version, QString url);
void gotLicenceList(QMap<QString, QString> licences);
void gotBranchList(QStringList branches);
// The uploadFinished() signal is emitted when a push() call is finished, i.e. a database upload has completed.
void uploadFinished(QString url);

View File

@@ -111,7 +111,7 @@ void RemoteDock::pushDatabase()
// Push database
remoteDatabase.push(mainWindow->getDb().currentFile(), url, remoteModel->currentClientCertificate(), pushDialog.name(),
pushDialog.commitMessage(), pushDialog.licence(), pushDialog.isPublic());
pushDialog.commitMessage(), pushDialog.licence(), pushDialog.isPublic(), pushDialog.branch());
}
void RemoteDock::newDirectoryNode(const QModelIndex& parent)

View File

@@ -1,4 +1,5 @@
#include <QPushButton>
#include <QUrlQuery>
#include "RemotePushDialog.h"
#include "ui_RemotePushDialog.h"
@@ -7,6 +8,8 @@
RemotePushDialog::RemotePushDialog(QWidget* parent, RemoteDatabase& remote, const QString& host, const QString& clientCert, const QString& name) :
QDialog(parent),
ui(new Ui::RemotePushDialog),
m_host(host),
m_clientCert(clientCert),
remoteDatabase(remote)
{
// Create UI
@@ -21,6 +24,10 @@ RemotePushDialog::RemotePushDialog(QWidget* parent, RemoteDatabase& remote, cons
// Fetch list of available licences
connect(&remoteDatabase, &RemoteDatabase::gotLicenceList, this, &RemotePushDialog::fillInLicences);
remoteDatabase.fetch(host + "licence/list", RemoteDatabase::RequestTypeLicenceList, clientCert);
// Prepare fetching list of available branches
connect(&remoteDatabase, &RemoteDatabase::gotBranchList, this, &RemotePushDialog::fillInBranches);
reloadBranchList();
}
RemotePushDialog::~RemotePushDialog()
@@ -45,6 +52,9 @@ void RemotePushDialog::checkInput()
if(ui->editCommitMessage->toPlainText().size() > 1024)
valid = false;
if(ui->comboBranch->currentText().size() < 1 || ui->comboBranch->currentText().size() > 32)
valid = false;
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(valid);
}
@@ -70,7 +80,12 @@ QString RemotePushDialog::licence() const
bool RemotePushDialog::isPublic() const
{
return ui->checkPublic->isChecked();
return ui->checkPublic->isChecked();
}
QString RemotePushDialog::branch() const
{
return ui->comboBranch->currentText();
}
void RemotePushDialog::fillInLicences(const QMap<QString, QString>& licences)
@@ -83,3 +98,31 @@ void RemotePushDialog::fillInLicences(const QMap<QString, QString>& licences)
for(auto it=licences.constBegin();it!=licences.constEnd();++it)
ui->comboLicence->addItem(it.value(), it.key());
}
void RemotePushDialog::fillInBranches(const QStringList& branches)
{
// Clear branch list and add the default master branch
ui->comboBranch->clear();
ui->comboBranch->addItem("master");
// Add rest of the branch list to the combo box
foreach(const QString& branch, branches)
{
if(branch != "master")
ui->comboBranch->addItem(branch);
}
}
void RemotePushDialog::reloadBranchList()
{
// Assemble query URL
QUrl url(m_host + "branch/list");
QUrlQuery query;
query.addQueryItem("username", remoteDatabase.getInfoFromClientCert(m_clientCert, RemoteDatabase::CertInfoUser));
query.addQueryItem("folder", "/");
query.addQueryItem("dbname", ui->editName->text());
url.setQuery(query);
// Send request
remoteDatabase.fetch(url.toString(), RemoteDatabase::RequestTypeBranchList, m_clientCert);
}

View File

@@ -21,10 +21,15 @@ public:
QString commitMessage() const;
QString licence() const;
bool isPublic() const;
QString branch() const;
private:
Ui::RemotePushDialog* ui;
// Connection details
QString m_host;
QString m_clientCert;
// Reference to the remote database object which is stored somewhere in the main window
RemoteDatabase& remoteDatabase;
@@ -32,7 +37,10 @@ protected slots:
void checkInput();
virtual void accept();
void reloadBranchList();
void fillInLicences(const QMap<QString, QString>& licences);
void fillInBranches(const QStringList& branches);
};
#endif

View File

@@ -57,7 +57,7 @@ p, li { white-space: pre-wrap; }
</property>
</widget>
</item>
<item row="3" column="0">
<item row="4" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Database licence</string>
@@ -67,7 +67,7 @@ p, li { white-space: pre-wrap; }
</property>
</widget>
</item>
<item row="3" column="1">
<item row="4" column="1">
<widget class="QComboBox" name="comboLicence">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
@@ -77,7 +77,7 @@ p, li { white-space: pre-wrap; }
</property>
</widget>
</item>
<item row="2" column="0">
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Public</string>
@@ -87,9 +87,26 @@ p, li { white-space: pre-wrap; }
</property>
</widget>
</item>
<item row="2" column="1">
<item row="3" column="1">
<widget class="QCheckBox" name="checkPublic"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Branch</string>
</property>
<property name="buddy">
<cstring>comboBranch</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="comboBranch">
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
@@ -107,6 +124,7 @@ p, li { white-space: pre-wrap; }
<tabstops>
<tabstop>editName</tabstop>
<tabstop>editCommitMessage</tabstop>
<tabstop>comboBranch</tabstop>
<tabstop>checkPublic</tabstop>
<tabstop>comboLicence</tabstop>
</tabstops>
@@ -192,8 +210,41 @@ p, li { white-space: pre-wrap; }
</hint>
</hints>
</connection>
<connection>
<sender>editName</sender>
<signal>editingFinished()</signal>
<receiver>RemotePushDialog</receiver>
<slot>reloadBranchList()</slot>
<hints>
<hint type="sourcelabel">
<x>176</x>
<y>25</y>
</hint>
<hint type="destinationlabel">
<x>77</x>
<y>3</y>
</hint>
</hints>
</connection>
<connection>
<sender>comboBranch</sender>
<signal>currentTextChanged(QString)</signal>
<receiver>RemotePushDialog</receiver>
<slot>checkInput()</slot>
<hints>
<hint type="sourcelabel">
<x>172</x>
<y>138</y>
</hint>
<hint type="destinationlabel">
<x>33</x>
<y>151</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>checkInput()</slot>
<slot>reloadBranchList()</slot>
</slots>
</ui>