Truncate commit title longer than 255 characters

* chore(gitea-git-clone): update changelog and package version
* fix(gitea-git-clone): truncate commit titles and bodies longer than 255 and 65535 characters respectively
* feat(gitea-git-clone): show warning messages when commit titles and bodies are truncated
This commit is contained in:
2024-10-23 12:19:17 +02:00
parent a5aaa54906
commit aea0ffbac6
5 changed files with 38 additions and 8 deletions

View File

@ -122,19 +122,36 @@ async function createGiteaPullRequest() {
// Den letzten Commit und den Branch abrufen
const { title, body } = await getLastCommit(currentWorkspaceFolder);
const branch = await getCurrentBranch(currentWorkspaceFolder);
if (!branch) {
vscode.window.showErrorMessage(localize('giteaClone.noBranch', 'Could not determine the branch.'));
return;
}
// Base-Branch über die Gitea API ermitteln
const baseBranch = await getDefaultBranch(instanceUrl, owner, repo, token);
// Titel und Body auf maximale Länge beschränken
const maxTitleLength = 255;
const maxBodyLength = 65535; // Beispielwert, kann je nach Gitea-Konfiguration variieren
let truncatedTitle = title;
let truncatedBody = body;
if (title.length > maxTitleLength) {
truncatedTitle = title.substring(0, maxTitleLength);
vscode.window.showWarningMessage(localize('giteaClone.titleTruncated', 'The commit message was too long and has been truncated for the pull request title.'));
}
if (body.length > maxBodyLength) {
truncatedBody = body.substring(0, maxBodyLength);
vscode.window.showWarningMessage(localize('giteaClone.bodyTruncated', 'The commit message body was too long and has been truncated for the pull request description.'));
}
// API-Request-Daten vorbereiten
const prData = {
title: title, // Der letzte Commit als Titel
body: body || '', // Commit-Kommentare als Body
title: truncatedTitle, // Der getrunkierte Titel
body: truncatedBody || '', // Der getrunkierte Body
head: branch, // Der aktuelle Branch als "head"
base: baseBranch // Der ermittelte base-Branch
};