forked from qt-creator/qt-creator
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:
committed by
Orgad Shaneh
parent
95bd5b0d68
commit
2310ec5891
@@ -37,6 +37,7 @@
|
||||
#include <QDir>
|
||||
#include <QPushButton>
|
||||
#include <QRegExpValidator>
|
||||
#include <QVersionNumber>
|
||||
|
||||
using namespace Git::Internal;
|
||||
|
||||
@@ -151,15 +152,16 @@ GerritPushDialog::GerritPushDialog(const QString &workingDir, const QString &rev
|
||||
this, &GerritPushDialog::validate);
|
||||
|
||||
updateCommits(m_ui->localBranchComboBox->currentIndex());
|
||||
setRemoteBranches();
|
||||
onRemoteChanged(true);
|
||||
|
||||
QRegExpValidator *noSpaceValidator = new QRegExpValidator(QRegExp("^\\S+$"), this);
|
||||
m_ui->reviewersLineEdit->setText(reviewerList);
|
||||
m_ui->reviewersLineEdit->setValidator(noSpaceValidator);
|
||||
m_ui->topicLineEdit->setValidator(noSpaceValidator);
|
||||
m_ui->wipCheckBox->setCheckState(Qt::PartiallyChecked);
|
||||
|
||||
connect(m_ui->remoteComboBox, &GerritRemoteChooser::remoteChanged,
|
||||
this, [this] { setRemoteBranches(); });
|
||||
this, [this] { onRemoteChanged(); });
|
||||
}
|
||||
|
||||
GerritPushDialog::~GerritPushDialog()
|
||||
@@ -209,6 +211,40 @@ void GerritPushDialog::setChangeRange()
|
||||
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
|
||||
{
|
||||
return m_initErrorMessage;
|
||||
@@ -216,16 +252,32 @@ QString GerritPushDialog::initErrorMessage() const
|
||||
|
||||
QString GerritPushDialog::pushTarget() const
|
||||
{
|
||||
QStringList options;
|
||||
QString target = selectedCommit();
|
||||
if (target.isEmpty())
|
||||
target = "HEAD";
|
||||
target += ":refs/" + QLatin1String(m_ui->draftCheckBox->isChecked() ? "drafts" : "for") +
|
||||
'/' + selectedRemoteBranchName();
|
||||
target += ":refs/";
|
||||
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();
|
||||
if (!topic.isEmpty())
|
||||
target += '/' + topic;
|
||||
|
||||
QStringList options;
|
||||
const QStringList reviewersInput = reviewers().split(',', QString::SkipEmptyParts);
|
||||
for (const QString &reviewer : reviewersInput)
|
||||
options << "r=" + reviewer;
|
||||
@@ -302,7 +354,7 @@ void GerritPushDialog::updateCommits(int index)
|
||||
const QString remote = remoteBranch.left(slash);
|
||||
|
||||
if (!m_ui->remoteComboBox->setCurrentRemote(remote))
|
||||
setRemoteBranches();
|
||||
onRemoteChanged();
|
||||
}
|
||||
validate();
|
||||
}
|
||||
|
||||
@@ -61,6 +61,7 @@ public:
|
||||
|
||||
private:
|
||||
void setChangeRange();
|
||||
void onRemoteChanged(bool force = false);
|
||||
void setRemoteBranches(bool includeOld = false);
|
||||
void updateCommits(int index);
|
||||
void validate();
|
||||
@@ -77,6 +78,7 @@ private:
|
||||
Ui::GerritPushDialog *m_ui;
|
||||
RemoteBranchesMap m_remoteBranches;
|
||||
bool m_hasLocalCommits = false;
|
||||
bool m_currentSupportsWip = false;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -76,8 +76,23 @@
|
||||
</item>
|
||||
<item>
|
||||
<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">
|
||||
<string>&Draft</string>
|
||||
<string>&Draft/Private</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="wipCheckBox">
|
||||
<property name="text">
|
||||
<string>&Work-In-Progress</string>
|
||||
</property>
|
||||
<property name="tristate">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
Reference in New Issue
Block a user