-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Save PR message if creation fails (#113)
Saves the pull request description (entered via editor) to a temporary file if creating the pull request fails. It will re-use the title/description if the user tries to re-create the PR (also just logs the file path to the console in case they want that). The most common cause of this error (in my experience) is expired auth tokens and/or the base branch of a stack having been deleted on GitHub. (we should provide a better experience for the latter but that's outside the scope of this PR)
- Loading branch information
Showing
7 changed files
with
111 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package sanitize | ||
|
||
import ( | ||
"regexp" | ||
"strings" | ||
) | ||
|
||
const ( | ||
fileNameMax = 100 | ||
) | ||
|
||
var ( | ||
filenameReplacePattern = regexp.MustCompile(`[^a-zA-Z0-9]+`) | ||
) | ||
|
||
func FileName(name string) string { | ||
name = strings.ToLower(name) | ||
name = filenameReplacePattern.ReplaceAllString(name, "-") | ||
if len(name) > fileNameMax { | ||
name = name[:fileNameMax] | ||
} | ||
name = strings.Trim(name, "-") | ||
return name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package sanitize | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func TestFileName(t *testing.T) { | ||
for _, tt := range []struct{ Input, Output string }{ | ||
{"", ""}, | ||
{" hello world ", "hello-world"}, | ||
{"hello world", "hello-world"}, | ||
{"hello-world", "hello-world"}, | ||
{"hello_world", "hello-world"}, | ||
{"hello-world-123", "hello-world-123"}, | ||
{"hello-/-world-123!!!", "hello-world-123"}, | ||
} { | ||
name := fmt.Sprintf("%q=>%q", tt.Input, tt.Output) | ||
t.Run(name, func(t *testing.T) { | ||
if got := FileName(tt.Input); got != tt.Output { | ||
t.Errorf("FileName() = %q, want %q", got, tt.Output) | ||
} | ||
}) | ||
} | ||
} |