Initial implementation of GithubWorkflowTool

Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-12-27 03:03:18 +00:00
parent 7121ad38d3
commit 9b992001f3
37 changed files with 2711 additions and 1 deletions

126
src/core/RepoManager.cpp Normal file
View File

@@ -0,0 +1,126 @@
#include "core/RepoManager.h"
#include "core/StorageProvider.h"
#include <QProcess>
#include <QDir>
#include <QDebug>
namespace gwt {
namespace core {
RepoManager::RepoManager(QObject* parent)
: QObject(parent)
, m_storage(StorageProvider::instance())
{
}
RepoManager::~RepoManager() = default;
bool RepoManager::cloneRepository(const QString& repoUrl, const QString& branch) {
QString localPath = m_storage.getRepoDirectory(repoUrl);
if (isCloned(repoUrl)) {
emit error("Repository already cloned at: " + localPath);
return false;
}
QDir().mkpath(QFileInfo(localPath).path());
QProcess git;
QStringList args;
args << "clone";
if (!branch.isEmpty()) {
args << "--branch" << branch;
}
args << repoUrl << localPath;
git.start("git", args);
if (!git.waitForStarted()) {
emit error("Failed to start git process");
return false;
}
emit cloneProgress(10, "Cloning repository...");
// Wait for completion with timeout
if (!git.waitForFinished(300000)) { // 5 minutes timeout
emit error("Git clone timeout");
git.kill();
return false;
}
if (git.exitCode() != 0) {
QString errorMsg = QString::fromUtf8(git.readAllStandardError());
emit error("Git clone failed: " + errorMsg);
return false;
}
emit cloneProgress(100, "Clone completed");
emit cloneFinished(true);
return true;
}
bool RepoManager::updateRepository(const QString& repoUrl) {
QString localPath = getLocalPath(repoUrl);
if (!isCloned(repoUrl)) {
emit error("Repository not cloned: " + repoUrl);
return false;
}
QProcess git;
git.setWorkingDirectory(localPath);
git.start("git", QStringList() << "pull");
if (!git.waitForFinished(60000)) { // 1 minute timeout
emit error("Git pull timeout");
return false;
}
if (git.exitCode() != 0) {
QString errorMsg = QString::fromUtf8(git.readAllStandardError());
emit error("Git pull failed: " + errorMsg);
return false;
}
return true;
}
QString RepoManager::getLocalPath(const QString& repoUrl) const {
return m_storage.getRepoDirectory(repoUrl);
}
bool RepoManager::isCloned(const QString& repoUrl) const {
QString localPath = getLocalPath(repoUrl);
QDir dir(localPath);
return dir.exists() && dir.exists(".git");
}
QStringList RepoManager::listRepositories() const {
QStringList repos;
QString root = m_storage.getRepoStorageRoot();
QDir rootDir(root);
if (!rootDir.exists()) {
return repos;
}
// Recursively find all directories with .git
QFileInfoList entries = rootDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
for (const QFileInfo& entry : entries) {
QDir hostDir(entry.filePath());
QFileInfoList repoEntries = hostDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
for (const QFileInfo& repoEntry : repoEntries) {
if (QDir(repoEntry.filePath()).exists(".git")) {
repos << repoEntry.filePath();
}
}
}
return repos;
}
} // namespace core
} // namespace gwt