Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type UserConfig struct {
PreserveTitleAndBody bool `default:"false" yaml:"preserveTitleAndBody"`
NoRebase bool `default:"false" yaml:"noRebase"`
DeleteMergedBranches bool `default:"false" yaml:"deleteMergedBranches"`
ShortPRLink bool `default:"false" yaml:"shortPRLink"`
}

type InternalState struct {
Expand Down
15 changes: 12 additions & 3 deletions github/pullrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,13 @@ func (pr *PullRequest) String(config *config.Config) string {
}

prInfo := fmt.Sprintf("%3d", pr.Number)
if config.User.ShowPRLink {
prInfo = fmt.Sprintf("https://%s/%s/%s/pull/%d",
config.Repo.GitHubHost, config.Repo.GitHubRepoOwner, config.Repo.GitHubRepoName, pr.Number)
prURL := fmt.Sprintf("https://%s/%s/%s/pull/%d",
config.Repo.GitHubHost, config.Repo.GitHubRepoOwner, config.Repo.GitHubRepoName, pr.Number)
if config.User.ShortPRLink {
// OSC 8 terminal hyperlink: \033]8;;URL\033\\TEXT\033]8;;\033\\
prInfo = fmt.Sprintf("\033]8;;%s\033\\PR-%d\033]8;;\033\\", prURL, pr.Number)
} else if config.User.ShowPRLink {
prInfo = prURL
}

var mq string
Expand All @@ -202,6 +206,11 @@ func (pr *PullRequest) String(config *config.Config) string {
terminalWidth = 1000
}
lineLength := utf8.RuneCountInString(line)
if config.User.ShortPRLink {
// OSC 8 escape sequences are invisible; subtract their length
// The escape overhead is: \033]8;; + URL + \033\\ + \033]8;;\033\\ = 12 + len(URL)
lineLength -= 12 + utf8.RuneCountInString(prURL)
}
if config.User.StatusBitsEmojis {
// each emoji consumes 2 chars in the terminal
lineLength += 4
Expand Down
32 changes: 32 additions & 0 deletions github/pullrequest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,42 @@ func TestString(t *testing.T) {
}
}

cfgWithShowPRLink := &config.Config{
Repo: &config.RepoConfig{
RequireChecks: true,
RequireApproval: true,
GitHubHost: "github.com",
GitHubRepoOwner: "testowner",
GitHubRepoName: "testrepo",
},
User: &config.UserConfig{
StatusBitsEmojis: false,
ShowPRLink: true,
},
}

cfgWithShortPRLink := &config.Config{
Repo: &config.RepoConfig{
RequireChecks: true,
RequireApproval: true,
GitHubHost: "github.com",
GitHubRepoOwner: "testowner",
GitHubRepoName: "testrepo",
},
User: &config.UserConfig{
StatusBitsEmojis: false,
ShortPRLink: true,
},
}

tests := []testcase{
{expect: "[?xxx] . 0 : Title", pr: pr(true, 1), cfg: cfg},
{expect: "[?xxx] . 0 : Title", pr: pr(true, 2), cfg: cfg},
{expect: "[?xxx] ! 0 : Title", pr: pr(false, 2), cfg: cfg},
// ShowPRLink: full URL is displayed
{expect: "[?xxx] . https://github.com/testowner/testrepo/pull/0 : Title", pr: pr(true, 1), cfg: cfgWithShowPRLink},
// ShortPRLink: clickable short link via OSC 8
{expect: "[?xxx] . \033]8;;https://github.com/testowner/testrepo/pull/0\033\\PR-0\033]8;;\033\\ : Title", pr: pr(true, 1), cfg: cfgWithShortPRLink},
}
for i, test := range tests {
assert.Equal(t, test.expect, test.pr.String(test.cfg), fmt.Sprintf("case %d failed", i))
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ User specific configuration is saved to .spr.yml in the user home directory.
| preserveTitleAndBody | bool | false | updating pull requests will not overwrite the pr title and body |
| noRebase | bool | false | when true spr update will not rebase on top of origin |
| deleteMergedBranches | bool | false | delete branches after prs are merged |
| shortPRLink | bool | false | show pull request links as clickable PR-<number> instead of full URL |

Happy Coding!
-------------
Expand Down
Loading