Skip to content

Commit

Permalink
Fix issue with double quotes in PR body
Browse files Browse the repository at this point in the history
  • Loading branch information
geofflamrock committed Dec 27, 2024
1 parent 44bd701 commit e1f654d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Stack/Git/GitHubOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class GitHubOperations(IOutputProvider outputProvider, GitHubOperationSet

public GitHubPullRequest? CreatePullRequest(string headBranch, string baseBranch, string title, string bodyFilePath, bool draft)
{
var command = $"pr create --title \"{title}\" --body-file \"{bodyFilePath}\" --base {baseBranch} --head {headBranch}";
var command = $"pr create --title \"{Sanitize(title)}\" --body-file \"{bodyFilePath}\" --base {baseBranch} --head {headBranch}";

if (draft)
{
Expand All @@ -81,7 +81,7 @@ public class GitHubOperations(IOutputProvider outputProvider, GitHubOperationSet

public void EditPullRequest(int number, string body)
{
ExecuteGitHubCommand($"pr edit {number} --body \"{body}\"");
ExecuteGitHubCommand($"pr edit {number} --body \"{Sanitize(body)}\"");
}

public void OpenPullRequest(GitHubPullRequest pullRequest)
Expand Down Expand Up @@ -156,4 +156,9 @@ private void ExecuteGitHubCommandInternal(string command)
}
}
}

private string Sanitize(string value)
{
return value.Replace("\"", "\\\"");
}
}

0 comments on commit e1f654d

Please sign in to comment.