Removed communication with ISMAS from git client.

This commit is contained in:
Gerhard Hoffmann 2023-08-02 15:17:10 +02:00
parent a94606ca89
commit 371cc1a187
2 changed files with 49 additions and 75 deletions

View File

@ -1,6 +1,7 @@
#include "git_client.h"
#include "update.h"
#include "worker.h"
#include "utils.h"
#include <QRegularExpression>
#include <QDebug>
@ -22,67 +23,6 @@ GitClient::GitClient(QString const &customerNrStr,
if (!m_worker) {
qCritical() << "ERROR CASTING PARENT TO WORKER FAILED";
}
connect(this, SIGNAL(ismasUpdatesAvailable()),
this, SLOT(onIsmasUpdatesAvailable()), Qt::QueuedConnection);
}
void GitClient::onIsmasUpdatesAvailable() {
if (QDir(m_customerRepository).exists()) {
qInfo() << UpdateStatus(UPDATE_STATUS::GIT_FETCH_UPDATES_REQUEST,
QString("FETCHING OF ") + m_repositoryPath +
QString(" INTO ") + m_customerRepository);
std::optional<QString> changes = gitFetch();
if (changes) {
std::optional<QStringList> changedFileNames = gitDiff(changes.value());
if (changedFileNames) {
qInfo() << UpdateStatus(UPDATE_STATUS::GIT_FETCH_UPDATES_REQUEST_SUCCESS,
QString("FETCHED NEW FILES ") +
changedFileNames.value().join(",") +
QString(" INTO ") + m_customerRepository);
if (gitPull()) {
qInfo() << UpdateStatus(UPDATE_STATUS::GIT_PULL_UPDATES_SUCCESS,
QString("PULL NEW FILES ") +
changedFileNames.value().join(",") +
QString(" INTO ") + m_customerRepository);
emit m_worker->handleChangedFiles(changedFileNames.value());
} else {
qCritical() << UpdateStatus(UPDATE_STATUS::GIT_PULL_UPDATES_FAILURE,
QString("PULLING NEW FILES ") +
changedFileNames.value().join(",") +
QString(" INTO ") + m_customerRepository + " FAILED");
emit m_worker->terminateUpdateProcess();
}
} else {
qCritical() << "NO CHANGES IN" << m_repositoryPath
<< "(" << m_customerRepository << ")";
emit m_worker->finishUpdateProcess(false);
}
} else {
qCritical() << UpdateStatus(UPDATE_STATUS::GIT_FETCH_UPDATES_REQUEST_FAILURE,
QString("NO CHANGES IN ") + m_repositoryPath +
QString(" (%1)").arg(m_customerRepository));
emit m_worker->finishUpdateProcess(false);
}
} else {
if (gitCloneAndCheckoutBranch()) {
qInfo() << "CLONED" << m_repositoryPath
<< "AND CHECKED OUT INTO" << m_customerRepository;
} else {
qCritical() << "ERROR CLONING " << m_repositoryPath
<< "AND/OR CHECKING OUT INTO" << m_customerRepository;
emit m_worker->terminateUpdateProcess();
}
}
}
bool GitClient::gitCloneCustomerRepository() {
@ -128,10 +68,31 @@ bool GitClient::copyGitConfigFromMaster() { // only allowed when called in
return false;
}
bool GitClient::gitCheckoutBranch() {
QStringList GitClient::gitBranchNames() {
// git config --global pager.branch false
QStringList bNames;
if (QDir(m_customerRepository).exists()) {
QString gitCommand("git branch -a");
Command c(gitCommand);
if (c.execute(m_customerRepository)) {
QString const result = c.getCommandResult();
return result.split('\n');
}
}
return bNames;
}
bool GitClient::gitCheckoutBranch() {
// TODO: nachsehen, ob der Branch ueberhaupt existiert
if (QDir(m_customerRepository).exists()) {
int zoneNr = Utils::read1stLineOfFile("/etc/zone_nr");
m_branchName = (zoneNr != 0)
? QString("zg1/zone%1").arg(zoneNr) : "master";
QString gitCommand("git checkout ");
gitCommand += m_branchName;
Command c(gitCommand);
return c.execute(m_customerRepository); // execute command in customerRepo
}
@ -146,11 +107,13 @@ bool GitClient::gitCloneAndCheckoutBranch() {
if (gitCheckoutBranch()) {
return true;
} else {
m_worker->terminateUpdateProcess();
// TODO
// m_worker->terminateUpdateProcess();
}
//}
} else {
m_worker->terminateUpdateProcess();
// TODO
//m_worker->terminateUpdateProcess();
}
return false;
}
@ -201,12 +164,18 @@ std::optional<QStringList> GitClient::gitDiff(QString const &commits) {
*/
std::optional<QString> GitClient::gitFetch() {
if (QDir(m_customerRepository).exists()) {
// TODO
UpdateStatus status (UPDATE_STATUS::GIT_FETCH_UPDATES, "GIT FETCH UPDATES");
qInfo() << status;
//emit m_worker->sendCmdEventToIsmas(
// m_worker->getIsmasClient().updateOfPSAContinues(
// "GIT FETCH UPDATES", status.m_statusDescription));
Command c("git fetch");
if (c.execute(m_customerRepository)) {
QString const s = c.getCommandResult().trimmed();
qCritical() << "GIT RESULT" << s;
if (!s.isEmpty()) {
QStringList lines = Update::split(s, '\n');
if (!lines.empty()) {
@ -215,6 +184,15 @@ std::optional<QString> GitClient::gitFetch() {
QRegularExpressionMatch match = re.match(lines.last());
if (match.hasMatch()) {
if (re.captureCount() == 3) { // start with full match (0), then the other 3 matches
// TODO
status = UpdateStatus(UPDATE_STATUS::GIT_FETCH_UPDATES_REQUEST_SUCCESS,
QString("GIT SUCCESSFULLY FETCHED ") + m_customerRepository);
qInfo() << status;
//emit m_worker->sendCmdEventToIsmas(
// m_worker->getIsmasClient().updateOfPSAContinues(
// "GIT_FETCH_UPDATES SUCCESS", status.m_statusDescription));
return match.captured(2);
} else {
qCritical() << "ERROR WRONG CAPTURE COUNT FOR 'GIT FETCH'" << re.captureCount();

View File

@ -2,9 +2,11 @@
#define GIT_CLIENT_H_INCLUDED
#include <QObject>
#include <QStringList>
#include <optional>
#include "process/command.h"
#include "ismas/ismas_client.h"
class Worker;
class GitClient : public QObject {
@ -14,7 +16,7 @@ class GitClient : public QObject {
QString const m_repositoryPath;
QString const m_customerNr;
QString const m_workingDirectory;
QString const m_branchName;
QString m_branchName;
QString const m_customerRepository;
bool copyGitConfigFromMaster();
@ -28,6 +30,7 @@ class GitClient : public QObject {
bool gitCloneCustomerRepository();
bool gitCheckoutBranch();
QStringList gitBranchNames();
QString const workingDirectory() const { return m_workingDirectory; }
QString workingDirectory() { return m_workingDirectory; }
@ -50,13 +53,6 @@ class GitClient : public QObject {
QString gitBlob(QString fileName);
QString gitCommitForBlob(QString blob);
bool gitIsFileTracked(QString file2name);
signals:
void ismasUpdatesAvailable();
public slots:
void onIsmasUpdatesAvailable();
};
#endif // GIT_CLIENT_H_INCLUDED