Handle multiline commit messages when creating PR (#149426)

- This makes the body of the pull request non-empty when the commit message consists more than one line.
- The GitHub web client fills the body the same way, too, when you create a pull request.
- Some commit messages consist more than one line, like this one, which is giving more detail about the commit, and can be used as a shortcut to not write the same text when opening a pull request and on GitHub.
- Without these changes, the pull request title will be messed up if the commit message is similar to this.

Co-authored-by: João Moreno <joao.moreno@microsoft.com>
This commit is contained in:
Roj
2022-05-18 21:13:32 +03:00
committed by GitHub
parent 7cf37cbb25
commit 64e09597f1

View File

@@ -102,13 +102,14 @@ async function handlePushError(repository: Repository, remote: Remote, refspec:
let title = `Update ${remoteName}`;
const head = repository.state.HEAD?.name;
let body: string | undefined;
if (head) {
const commit = await repository.getCommit(head);
title = commit.message.replace(/\n.*$/m, '');
title = commit.message.split('\n')[0];
body = commit.message.slice(title.length + 1).trim();
}
let body: string | undefined;
const templates = await findPullRequestTemplates(repository.rootUri);
if (templates.length > 0) {
templates.sort((a, b) => a.path.localeCompare(b.path));