Skip to content

Commit 1692c4b

Browse files
committed
add showCommitID configuraiton
commit-id:6807a2de
1 parent 6601d51 commit 1692c4b

4 files changed

Lines changed: 35 additions & 0 deletions

File tree

config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ type UserConfig struct {
5555
NoRebase bool `default:"false" yaml:"noRebase"`
5656
DeleteMergedBranches bool `default:"false" yaml:"deleteMergedBranches"`
5757
ShortPRLink bool `default:"false" yaml:"shortPRLink"`
58+
ShowCommitID bool `default:"false" yaml:"showCommitID"`
5859
}
5960

6061
type InternalState struct {

github/pullrequest.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,12 @@ func (pr *PullRequest) String(config *config.Config) string {
185185
prInfo = prURL
186186
}
187187

188+
if config.User.ShowCommitID && len(pr.Commit.CommitHash) >= 8 {
189+
prInfo = pr.Commit.CommitHash[:8] + " " + prInfo
190+
} else if config.User.ShowCommitID && len(pr.Commit.CommitHash) > 0 {
191+
prInfo = pr.Commit.CommitHash + " " + prInfo
192+
}
193+
188194
var mq string
189195
if len(pr.Commits) > 1 {
190196
mq = statusBitIcons(config)["warning"]

github/pullrequest_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,27 @@ func TestString(t *testing.T) {
198198
},
199199
}
200200

201+
cfgWithCommitID := &config.Config{
202+
Repo: &config.RepoConfig{
203+
RequireChecks: true,
204+
RequireApproval: true,
205+
},
206+
User: &config.UserConfig{
207+
StatusBitsEmojis: false,
208+
ShowCommitID: true,
209+
},
210+
}
211+
212+
prWithHash := func(inQueue bool, commits int, hash string) *PullRequest {
213+
return &PullRequest{
214+
InQueue: inQueue,
215+
Commits: make([]git.Commit, commits),
216+
Title: "Title",
217+
Commit: git.Commit{CommitHash: hash},
218+
MergeStatus: PullRequestMergeStatus{},
219+
}
220+
}
221+
201222
tests := []testcase{
202223
{expect: "[?xxx] . 0 : Title", pr: pr(true, 1), cfg: cfg},
203224
{expect: "[?xxx] . 0 : Title", pr: pr(true, 2), cfg: cfg},
@@ -206,6 +227,12 @@ func TestString(t *testing.T) {
206227
{expect: "[?xxx] . https://github.com/testowner/testrepo/pull/0 : Title", pr: pr(true, 1), cfg: cfgWithShowPRLink},
207228
// ShortPRLink: clickable short link via OSC 8
208229
{expect: "[?xxx] . \033]8;;https://github.com/testowner/testrepo/pull/0\033\\PR-0\033]8;;\033\\ : Title", pr: pr(true, 1), cfg: cfgWithShortPRLink},
230+
// ShowCommitID: first 8 chars of commit hash shown
231+
{expect: "[?xxx] . abcd1234 0 : Title", pr: prWithHash(true, 1, "abcd1234ef567890"), cfg: cfgWithCommitID},
232+
// ShowCommitID with short hash (< 8 chars): full hash shown
233+
{expect: "[?xxx] . abcd 0 : Title", pr: prWithHash(true, 1, "abcd"), cfg: cfgWithCommitID},
234+
// ShowCommitID with empty hash: no hash shown
235+
{expect: "[?xxx] . 0 : Title", pr: prWithHash(true, 1, ""), cfg: cfgWithCommitID},
209236
}
210237
for i, test := range tests {
211238
assert.Equal(t, test.expect, test.pr.String(test.cfg), fmt.Sprintf("case %d failed", i))

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ User specific configuration is saved to .spr.yml in the user home directory.
198198
| noRebase | bool | false | when true spr update will not rebase on top of origin |
199199
| deleteMergedBranches | bool | false | delete branches after prs are merged |
200200
| shortPRLink | bool | false | show pull request links as clickable PR-<number> instead of full URL |
201+
| showCommitID | bool | false | show first 8 characters of commit hash for each pull request |
201202

202203
Happy Coding!
203204
-------------

0 commit comments

Comments
 (0)