Gerrit: Support Private/Work-In-Progress push on Gerrit >= 2.15

A private change[1] is only visible to the uploader and reviewers (like
draft in older Gerrit).

A WIP change[2] does not generate notifications until it becomes ready.

[1] https://gerrit-review.googlesource.com/Documentation/intro-user.html#private-changes
[2] https://gerrit-review.googlesource.com/Documentation/user-upload.html#wip

Change-Id: I4905461c529e93e86be934c60eab218ff7474fcd
Reviewed-by: André Hartmann <aha_1980@gmx.de>
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
Orgad Shaneh
2017-10-15 00:15:07 +03:00
committed by Orgad Shaneh
parent 95bd5b0d68
commit 2310ec5891
3 changed files with 76 additions and 7 deletions

View File

@@ -37,6 +37,7 @@
#include <QDir> #include <QDir>
#include <QPushButton> #include <QPushButton>
#include <QRegExpValidator> #include <QRegExpValidator>
#include <QVersionNumber>
using namespace Git::Internal; using namespace Git::Internal;
@@ -151,15 +152,16 @@ GerritPushDialog::GerritPushDialog(const QString &workingDir, const QString &rev
this, &GerritPushDialog::validate); this, &GerritPushDialog::validate);
updateCommits(m_ui->localBranchComboBox->currentIndex()); updateCommits(m_ui->localBranchComboBox->currentIndex());
setRemoteBranches(); onRemoteChanged(true);
QRegExpValidator *noSpaceValidator = new QRegExpValidator(QRegExp("^\\S+$"), this); QRegExpValidator *noSpaceValidator = new QRegExpValidator(QRegExp("^\\S+$"), this);
m_ui->reviewersLineEdit->setText(reviewerList); m_ui->reviewersLineEdit->setText(reviewerList);
m_ui->reviewersLineEdit->setValidator(noSpaceValidator); m_ui->reviewersLineEdit->setValidator(noSpaceValidator);
m_ui->topicLineEdit->setValidator(noSpaceValidator); m_ui->topicLineEdit->setValidator(noSpaceValidator);
m_ui->wipCheckBox->setCheckState(Qt::PartiallyChecked);
connect(m_ui->remoteComboBox, &GerritRemoteChooser::remoteChanged, connect(m_ui->remoteComboBox, &GerritRemoteChooser::remoteChanged,
this, [this] { setRemoteBranches(); }); this, [this] { onRemoteChanged(); });
} }
GerritPushDialog::~GerritPushDialog() GerritPushDialog::~GerritPushDialog()
@@ -209,6 +211,40 @@ void GerritPushDialog::setChangeRange()
tr("Number of commits between %1 and %2: %3").arg(branch, remote, range)); tr("Number of commits between %1 and %2: %3").arg(branch, remote, range));
} }
static bool versionSupportsWip(const QString &version)
{
return QVersionNumber::fromString(version) >= QVersionNumber(2, 15);
}
void GerritPushDialog::onRemoteChanged(bool force)
{
setRemoteBranches();
const QString version = m_ui->remoteComboBox->currentServer().version;
const bool supportsWip = versionSupportsWip(version);
if (!force && supportsWip == m_currentSupportsWip)
return;
m_currentSupportsWip = supportsWip;
m_ui->wipCheckBox->setEnabled(supportsWip);
if (supportsWip) {
m_ui->wipCheckBox->setToolTip(tr("Checked - Mark change as WIP\n"
"Unchecked - Mark change as ready\n"
"Partially checked - Do not change current state"));
m_ui->draftCheckBox->setTristate(true);
if (m_ui->draftCheckBox->checkState() != Qt::Checked)
m_ui->draftCheckBox->setCheckState(Qt::PartiallyChecked);
m_ui->draftCheckBox->setToolTip(tr("Checked - Mark change as private\n"
"Unchecked - Unmark change as private\n"
"Partially checked - Do not change current state"));
} else {
m_ui->wipCheckBox->setToolTip(tr("Supported on Gerrit 2.15 and up"));
m_ui->draftCheckBox->setTristate(false);
if (m_ui->draftCheckBox->checkState() != Qt::Checked)
m_ui->draftCheckBox->setCheckState(Qt::Unchecked);
m_ui->draftCheckBox->setToolTip(tr("Checked - Mark change as draft\n"
"Unchecked - Unmark change as draft"));
}
}
QString GerritPushDialog::initErrorMessage() const QString GerritPushDialog::initErrorMessage() const
{ {
return m_initErrorMessage; return m_initErrorMessage;
@@ -216,16 +252,32 @@ QString GerritPushDialog::initErrorMessage() const
QString GerritPushDialog::pushTarget() const QString GerritPushDialog::pushTarget() const
{ {
QStringList options;
QString target = selectedCommit(); QString target = selectedCommit();
if (target.isEmpty()) if (target.isEmpty())
target = "HEAD"; target = "HEAD";
target += ":refs/" + QLatin1String(m_ui->draftCheckBox->isChecked() ? "drafts" : "for") + target += ":refs/";
'/' + selectedRemoteBranchName(); if (versionSupportsWip(m_ui->remoteComboBox->currentServer().version)) {
target += "for";
const Qt::CheckState draftState = m_ui->draftCheckBox->checkState();
const Qt::CheckState wipState = m_ui->wipCheckBox->checkState();
if (draftState == Qt::Checked)
options << "private";
else if (draftState == Qt::Unchecked)
options << "remove-private";
if (wipState == Qt::Checked)
options << "wip";
else if (wipState == Qt::Unchecked)
options << "ready";
} else {
target += QLatin1String(m_ui->draftCheckBox->isChecked() ? "for" : "drafts");
}
target += '/' + selectedRemoteBranchName();
const QString topic = selectedTopic(); const QString topic = selectedTopic();
if (!topic.isEmpty()) if (!topic.isEmpty())
target += '/' + topic; target += '/' + topic;
QStringList options;
const QStringList reviewersInput = reviewers().split(',', QString::SkipEmptyParts); const QStringList reviewersInput = reviewers().split(',', QString::SkipEmptyParts);
for (const QString &reviewer : reviewersInput) for (const QString &reviewer : reviewersInput)
options << "r=" + reviewer; options << "r=" + reviewer;
@@ -302,7 +354,7 @@ void GerritPushDialog::updateCommits(int index)
const QString remote = remoteBranch.left(slash); const QString remote = remoteBranch.left(slash);
if (!m_ui->remoteComboBox->setCurrentRemote(remote)) if (!m_ui->remoteComboBox->setCurrentRemote(remote))
setRemoteBranches(); onRemoteChanged();
} }
validate(); validate();
} }

View File

@@ -61,6 +61,7 @@ public:
private: private:
void setChangeRange(); void setChangeRange();
void onRemoteChanged(bool force = false);
void setRemoteBranches(bool includeOld = false); void setRemoteBranches(bool includeOld = false);
void updateCommits(int index); void updateCommits(int index);
void validate(); void validate();
@@ -77,6 +78,7 @@ private:
Ui::GerritPushDialog *m_ui; Ui::GerritPushDialog *m_ui;
RemoteBranchesMap m_remoteBranches; RemoteBranchesMap m_remoteBranches;
bool m_hasLocalCommits = false; bool m_hasLocalCommits = false;
bool m_currentSupportsWip = false;
}; };

View File

@@ -76,8 +76,23 @@
</item> </item>
<item> <item>
<widget class="QCheckBox" name="draftCheckBox"> <widget class="QCheckBox" name="draftCheckBox">
<property name="toolTip">
<string>Checked - Mark change as private
Unchecked - Unmark change as private
Semi-checked - Do not change current state</string>
</property>
<property name="text"> <property name="text">
<string>&amp;Draft</string> <string>&amp;Draft/Private</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="wipCheckBox">
<property name="text">
<string>&amp;Work-In-Progress</string>
</property>
<property name="tristate">
<bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>