Skip to content

Commit

Permalink
Merge pull request #95 from DXS-GROUP/InDev
Browse files Browse the repository at this point in the history
Added Issues tab
  • Loading branch information
dxs-coder authored Jun 9, 2024
2 parents cc887a0 + 839699f commit 84d3786
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 22 deletions.
66 changes: 54 additions & 12 deletions src/CodeKeeper/keeperFunc/getProjectInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,29 +135,27 @@ QString MainWindow::getRepositoryData(QString git_url, QTableWidget *table)
createdAt = obj["created_at"].toString();
QDateTime createdDate = QDateTime::fromString(createdAt, Qt::ISODate);
createdAt = createdDate.toString("dd MMM yyyy hh:mm");

openIssues = QString::number(obj["open_issues"].toInt());

// repoData += " \n Watchers: " + QString::number(obj["watchers"].toInt()) + " ";
forks = QString::number(obj["forks"].toInt());
lang = obj["language"].toString();



stars = QString::number(obj["stargazers_count"].toInt());

qint64 size = obj["size"].toDouble();
repoSize = formatFileSize(size);


if (obj.contains("license")) {
QJsonObject licenseObj = obj["license"].toObject();
if (licenseObj.contains("name")) {
license = licenseObj["name"].toString() + " ";
license = licenseObj["name"].toString() + " ";
} else {
qDebug() << "License not found";
qDebug() << "License not found";
}
} else {
qDebug() << "License not found";
qDebug() << "License not found";
}

QUrl commitUrl("https://api.github.com/repos/" + repo + "/commits");
Expand Down Expand Up @@ -227,7 +225,6 @@ QString MainWindow::getRepositoryData(QString git_url, QTableWidget *table)

totalDownloads = QString::number(iTotalDownloads);


// Release info
QUrl releasesUrl("https://api.github.com/repos/" + repo + "/releases/latest");
releasesUrl.setQuery(query);
Expand All @@ -252,7 +249,6 @@ QString MainWindow::getRepositoryData(QString git_url, QTableWidget *table)
QJsonObject releasesObj = releasesDoc.object();
qDebug() << releasesDoc;


release = releasesObj["name"].toString();

dateStr = releasesObj["published_at"].toString();
Expand Down Expand Up @@ -355,8 +351,6 @@ QString MainWindow::getRepositoryData(QString git_url, QTableWidget *table)
table->item(i, 0)->setTextAlignment(Qt::AlignCenter);
}



for (int row = 0; row < table->rowCount(); ++row) {
for (int col = 0; col < table->columnCount(); ++col) {
QTableWidgetItem *item = table->item(row, col);
Expand All @@ -368,3 +362,51 @@ QString MainWindow::getRepositoryData(QString git_url, QTableWidget *table)

return repoData;
}

QString MainWindow::getProjectIssues(QString git_url)
{
int maxLength = 120;
QString prefix = "https://github.com/";
QString repo = git_url.replace(prefix, "");
QString issuesData;

QUrl url("https://api.github.com/repos/" + repo + "/issues");
QNetworkRequest request(url);

QNetworkAccessManager manager;
QNetworkReply *reply = manager.get(request);

request.setHeader(QNetworkRequest::UserAgentHeader, "CodeKeeper");
request.setRawHeader("Authorization", ("Bearer " + git_token).toUtf8());
request.setRawHeader("X-GitHub-Api-Version", "2022-11-28");
request.setRawHeader("Accept", "application/vnd.github.v3+json");

QEventLoop loop;
QObject::connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);

loop.exec();

if (reply->error() == QNetworkReply::NoError) {
QByteArray data = reply->readAll();
QJsonDocument json = QJsonDocument::fromJson(data);
QJsonArray issues = json.array();

qDebug() << json;

foreach (const QJsonValue &issue, issues) {
QJsonObject issueObject = issue.toObject();
QString title = issueObject["title"].toString();
QString body = issueObject["body"].toString();
QString shortBody = body.left(maxLength);
QString link = issueObject["html_url"].toString();

issuesData += "<br><br><h2>" + title + "</h2>" + shortBody + "<br><br><a style='color: #84a0bf; text-decoration: none;' href=\"" + link + "\">Open</a><br>";
}
} else {
qWarning() << "Error: " << reply->errorString();
}
reply->deleteLater();

qDebug() << issuesData;
return issuesData;
}
50 changes: 40 additions & 10 deletions src/CodeKeeper/keeperFunc/projectsFunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,19 @@ void MainWindow::openProject(QListWidget *listWidget, QListWidgetItem *item)
{
if (item) {
QDialog dialog(this);
dialog.setFixedSize(400, 550);
dialog.setFixedSize(420, 550);
dialog.setWindowTitle(tr("Edit project"));
dialog.setWindowFlags(windowFlags() | Qt::FramelessWindowHint);

QVBoxLayout *centralLayout = new QVBoxLayout(&dialog);

QTabWidget *tabs = new QTabWidget();
tabs->setMovable(true);
// tabs->setTabPosition(QTabWidget::South);

QWidget *projectTab = new QWidget();
QGridLayout mainLayout(projectTab);

QString data = item->text();
QStringList splitData = data.split("\n");

Expand All @@ -138,8 +147,6 @@ void MainWindow::openProject(QListWidget *listWidget, QListWidgetItem *item)
qDebug() << "Open project: " << projectData[0] << " " << projectData[1] << " "
<< projectData[2] << " " << projectData[3] << " " << projectData[4];

QGridLayout mainLayout(&dialog);

QLineEdit *title = new QLineEdit();
title->setAlignment(Qt::AlignCenter);
title->setPlaceholderText(" Project name: ");
Expand All @@ -155,7 +162,7 @@ void MainWindow::openProject(QListWidget *listWidget, QListWidgetItem *item)
linkToGit->setFont(selectedFont);

QComboBox *documentation = new QComboBox();
documentation->setFixedSize(190, 20);
documentation->setFixedSize(200, 20);
documentation->setFont(selectedFont);

QLabel *lastMod = new QLabel();
Expand Down Expand Up @@ -220,10 +227,31 @@ void MainWindow::openProject(QListWidget *listWidget, QListWidgetItem *item)
mainLayout.addWidget(cancelBtn, 7, 0, 1, 2, Qt::AlignCenter);
mainLayout.addWidget(lastMod, 5, 0, 1, 2, Qt::AlignCenter);

QWidget *issuesTab = new QWidget();
QGridLayout issuesLayout(issuesTab);

QLabel *issuesLabel = new QLabel();
issuesLabel->setWordWrap(true);
issuesLabel->setTextFormat(Qt::RichText);
issuesLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
issuesLabel->setText("Issues");
issuesLabel->setOpenExternalLinks(true);
issuesLabel->setFont(selectedFont);
issuesLabel->setStyleSheet("font-size: " + font_size + "pt;");
issuesLabel->setAlignment(Qt::AlignCenter);
issuesLayout.addWidget(issuesLabel, 0, 0, 1, 3);

tabs->addTab(projectTab, "Project");
tabs->addTab(issuesTab, "Issues");

centralLayout->addWidget(tabs);

QThread *thread = new QThread;
QObject::connect(thread, &QThread::started, this, [this, projectData, git_stats]() {
getRepositoryData(projectData[1], git_stats);
});
QObject::connect(thread, &QThread::started, this,
[this, projectData, git_stats, issuesLabel]() {
getRepositoryData(projectData[1], git_stats);
issuesLabel->setText(getProjectIssues(projectData[1]));
});
thread->start();

QObject::connect(saveDataBtn, &QPushButton::clicked, [&]() {
Expand Down Expand Up @@ -258,9 +286,11 @@ void MainWindow::openProject(QListWidget *listWidget, QListWidgetItem *item)
// createGitBadges(repo, git_stats);

QThread *thread = new QThread;
QObject::connect(
thread, &QThread::started, this,
[this, projectData, repo, git_stats]() { getRepositoryData(repo, git_stats); });
QObject::connect(thread, &QThread::started, this,
[this, projectData, repo, git_stats, issuesLabel]() {
getRepositoryData(repo, git_stats);
issuesLabel->setText(getProjectIssues(repo));
});
thread->start();
});

Expand Down
1 change: 1 addition & 0 deletions src/CodeKeeper/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ class MainWindow : public QMainWindow

private slots:
QString getRepositoryData(QString git_url, QTableWidget *table);
QString getProjectIssues(QString git_url);

void openSettingsWindow();
void fOpenAccountWindow();
Expand Down

0 comments on commit 84d3786

Please sign in to comment.