Clickable links for PRs in the changelog (#2588)

This commit is contained in:
DanielSvoboda 2025-03-04 12:07:45 -03:00 committed by GitHub
parent f62884ffda
commit dc52cfb9bc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -19,7 +19,7 @@
#include <QStandardPaths> #include <QStandardPaths>
#include <QString> #include <QString>
#include <QStringList> #include <QStringList>
#include <QTextEdit> #include <QTextBrowser>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <common/config.h> #include <common/config.h>
#include <common/path_util.h> #include <common/path_util.h>
@ -247,7 +247,7 @@ void CheckUpdate::setupUI(const QString& downloadUrl, const QString& latestDate,
bool latest_isWIP = latestRev.endsWith("WIP", Qt::CaseInsensitive); bool latest_isWIP = latestRev.endsWith("WIP", Qt::CaseInsensitive);
if (current_isWIP && !latest_isWIP) { if (current_isWIP && !latest_isWIP) {
} else { } else {
QTextEdit* textField = new QTextEdit(this); QTextBrowser* textField = new QTextBrowser(this);
textField->setReadOnly(true); textField->setReadOnly(true);
textField->setFixedWidth(500); textField->setFixedWidth(500);
textField->setFixedHeight(200); textField->setFixedHeight(200);
@ -349,8 +349,28 @@ void CheckUpdate::requestChangelog(const QString& currentRev, const QString& lat
} }
// Update the text field with the changelog // Update the text field with the changelog
QTextEdit* textField = findChild<QTextEdit*>(); QTextBrowser* textField = findChild<QTextBrowser*>();
if (textField) { if (textField) {
QRegularExpression re("\\(\\#(\\d+)\\)");
QString newChanges;
int lastIndex = 0;
QRegularExpressionMatchIterator i = re.globalMatch(changes);
while (i.hasNext()) {
QRegularExpressionMatch match = i.next();
newChanges += changes.mid(lastIndex, match.capturedStart() - lastIndex);
QString num = match.captured(1);
newChanges +=
QString(
"(<a "
"href=\"https://github.com/shadps4-emu/shadPS4/pull/%1\">#%1</a>)")
.arg(num);
lastIndex = match.capturedEnd();
}
newChanges += changes.mid(lastIndex);
changes = newChanges;
textField->setOpenExternalLinks(true);
textField->setHtml("<h2>" + tr("Changes") + ":</h2>" + changes); textField->setHtml("<h2>" + tr("Changes") + ":</h2>" + changes);
} }