Enhance 2nd round of issue and PR number output

This commit is contained in:
Andy Feller 2024-03-01 15:42:43 -05:00
parent 3bb5f54073
commit bcdc917f08
5 changed files with 43 additions and 43 deletions

View file

@ -200,9 +200,9 @@ func reason(reason string) string {
// is parameterized on a bunch of options.
//
// Example output: "Locked as RESOLVED: Issue #31 (Title of issue)"
func status(state string, lockable *api.Issue, opts *LockOptions) string {
return fmt.Sprintf("%sed%s: %s #%d (%s)",
state, reason(opts.Reason), alias[opts.ParentCmd].FullName, lockable.Number, lockable.Title)
func status(state string, lockable *api.Issue, baseRepo ghrepo.Interface, opts *LockOptions) string {
return fmt.Sprintf("%sed%s: %s %s#%d (%s)",
state, reason(opts.Reason), alias[opts.ParentCmd].FullName, ghrepo.FullName(baseRepo), lockable.Number, lockable.Title)
}
// lockRun will lock or unlock a conversation.
@ -224,10 +224,10 @@ func lockRun(state string, opts *LockOptions) error {
currentType := alias[parent.Typename]
correctType := alias[issuePr.Typename]
return fmt.Errorf("%s %s #%d not found, but found %s #%d. Use `gh %s %s %d` instead",
return fmt.Errorf("%s %s %s#%d not found, but found %s %s#%d. Use `gh %s %s %d` instead",
cs.FailureIconWithColor(cs.Red),
currentType.FullName, issuePr.Number,
strings.ToLower(correctType.FullName), issuePr.Number,
currentType.FullName, ghrepo.FullName(baseRepo), issuePr.Number,
strings.ToLower(correctType.FullName), ghrepo.FullName(baseRepo), issuePr.Number,
correctType.Name, strings.ToLower(state), issuePr.Number)
}
@ -243,7 +243,7 @@ func lockRun(state string, opts *LockOptions) error {
}
successMsg := fmt.Sprintf("%s %s\n",
cs.SuccessIconWithColor(cs.Green), status(state, issuePr, opts))
cs.SuccessIconWithColor(cs.Green), status(state, issuePr, baseRepo, opts))
switch state {
case Lock:
@ -254,8 +254,8 @@ func lockRun(state string, opts *LockOptions) error {
relocked, err = relockLockable(httpClient, baseRepo, issuePr, opts)
if !relocked {
successMsg = fmt.Sprintf("%s #%d already locked%s. Nothing changed.\n",
parent.FullName, issuePr.Number, reason(issuePr.ActiveLockReason))
successMsg = fmt.Sprintf("%s %s#%d already locked%s. Nothing changed.\n",
parent.FullName, ghrepo.FullName(baseRepo), issuePr.Number, reason(issuePr.ActiveLockReason))
}
}
@ -263,8 +263,8 @@ func lockRun(state string, opts *LockOptions) error {
if issuePr.Locked {
err = unlockLockable(httpClient, baseRepo, issuePr, opts)
} else {
successMsg = fmt.Sprintf("%s #%d already unlocked. Nothing changed.\n",
parent.FullName, issuePr.Number)
successMsg = fmt.Sprintf("%s %s#%d already unlocked. Nothing changed.\n",
parent.FullName, ghrepo.FullName(baseRepo), issuePr.Number)
}
default:
panic("bad state")
@ -334,8 +334,8 @@ func relockLockable(httpClient *http.Client, repo ghrepo.Interface, lockable *ap
return false, errors.New("already locked")
}
prompt := fmt.Sprintf("%s #%d already locked%s. Unlock and lock again%s?",
alias[opts.ParentCmd].FullName, lockable.Number, reason(lockable.ActiveLockReason), reason(opts.Reason))
prompt := fmt.Sprintf("%s %s#%d already locked%s. Unlock and lock again%s?",
alias[opts.ParentCmd].FullName, ghrepo.FullName(repo), lockable.Number, reason(lockable.ActiveLockReason), reason(opts.Reason))
relocked, err := opts.Prompter.Confirm(prompt, true)
if err != nil {

View file

@ -234,7 +234,7 @@ func Test_runLock(t *testing.T) {
return -1, prompter.NoSuchPromptErr(p)
}
},
wantOut: "✓ Locked as TOO_HEATED: Issue #451 (traverse the library)\n",
wantOut: "✓ Locked as TOO_HEATED: Issue OWNER/REPO#451 (traverse the library)\n",
},
{
name: "lock issue with explicit reason tty",
@ -261,7 +261,7 @@ func Test_runLock(t *testing.T) {
"lockedRecord": {
"locked": true }}}}`))
},
wantOut: "✓ Locked as OFF_TOPIC: Issue #451 (traverse the library)\n",
wantOut: "✓ Locked as OFF_TOPIC: Issue OWNER/REPO#451 (traverse the library)\n",
},
{
name: "unlock issue tty",
@ -288,7 +288,7 @@ func Test_runLock(t *testing.T) {
"unlockedRecord": {
"locked": false }}}}`))
},
wantOut: "✓ Unlocked: Issue #451 (traverse the library)\n",
wantOut: "✓ Unlocked: Issue OWNER/REPO#451 (traverse the library)\n",
},
{
name: "unlock issue nontty",
@ -375,14 +375,14 @@ func Test_runLock(t *testing.T) {
},
promptStubs: func(t *testing.T, pm *prompter.PrompterMock) {
pm.ConfirmFunc = func(p string, d bool) (bool, error) {
if p == "Issue #451 already locked. Unlock and lock again as OFF_TOPIC?" {
if p == "Issue OWNER/REPO#451 already locked. Unlock and lock again as OFF_TOPIC?" {
return true, nil
}
return false, prompter.NoSuchPromptErr(p)
}
},
wantOut: "✓ Locked as OFF_TOPIC: Issue #451 (traverse the library)\n",
wantOut: "✓ Locked as OFF_TOPIC: Issue OWNER/REPO#451 (traverse the library)\n",
},
{
name: "relock issue nontty",
@ -462,7 +462,7 @@ func Test_runLock(t *testing.T) {
return -1, prompter.NoSuchPromptErr(p)
}
},
wantOut: "✓ Locked as TOO_HEATED: Pull request #451 (traverse the library)\n",
wantOut: "✓ Locked as TOO_HEATED: Pull request OWNER/REPO#451 (traverse the library)\n",
},
{
name: "lock pr with explicit reason tty",
@ -489,7 +489,7 @@ func Test_runLock(t *testing.T) {
"lockedRecord": {
"locked": true }}}}`))
},
wantOut: "✓ Locked as OFF_TOPIC: Pull request #451 (traverse the library)\n",
wantOut: "✓ Locked as OFF_TOPIC: Pull request OWNER/REPO#451 (traverse the library)\n",
},
{
name: "lock pr with explicit nontty",
@ -566,7 +566,7 @@ func Test_runLock(t *testing.T) {
"unlockedRecord": {
"locked": false }}}}`))
},
wantOut: "✓ Unlocked: Pull request #451 (traverse the library)\n",
wantOut: "✓ Unlocked: Pull request OWNER/REPO#451 (traverse the library)\n",
},
{
name: "relock pr tty",
@ -603,14 +603,14 @@ func Test_runLock(t *testing.T) {
},
promptStubs: func(t *testing.T, pm *prompter.PrompterMock) {
pm.ConfirmFunc = func(p string, d bool) (bool, error) {
if p == "Pull request #451 already locked. Unlock and lock again as OFF_TOPIC?" {
if p == "Pull request OWNER/REPO#451 already locked. Unlock and lock again as OFF_TOPIC?" {
return true, nil
}
return false, prompter.NoSuchPromptErr(p)
}
},
wantOut: "✓ Locked as OFF_TOPIC: Pull request #451 (traverse the library)\n",
wantOut: "✓ Locked as OFF_TOPIC: Pull request OWNER/REPO#451 (traverse the library)\n",
},
{
name: "relock pr nontty",

View file

@ -62,7 +62,7 @@ func transferRun(opts *TransferOptions) error {
return err
}
if issue.IsPullRequest() {
return fmt.Errorf("issue #%d is a pull request and cannot be transferred", issue.Number)
return fmt.Errorf("issue %s#%d is a pull request and cannot be transferred", ghrepo.FullName(baseRepo), issue.Number)
}
destRepo, err := ghrepo.FromFullNameWithHost(opts.DestRepoSelector, baseRepo.RepoHost())

View file

@ -207,14 +207,14 @@ func (m *mergeContext) disableAutoMerge() error {
if err := disableAutoMerge(m.httpClient, m.baseRepo, m.pr.ID); err != nil {
return err
}
return m.infof("%s Auto-merge disabled for pull request #%d\n", m.cs.SuccessIconWithColor(m.cs.Green), m.pr.Number)
return m.infof("%s Auto-merge disabled for pull request %s#%d\n", m.cs.SuccessIconWithColor(m.cs.Green), ghrepo.FullName(m.baseRepo), m.pr.Number)
}
// Check if this pull request is in a merge queue
func (m *mergeContext) inMergeQueue() error {
// if the pull request is in a merge queue no further action is possible
if m.pr.IsInMergeQueue {
_ = m.warnf("%s Pull request #%d is already queued to merge\n", m.cs.WarningIcon(), m.pr.Number)
_ = m.warnf("%s Pull request %s#%d is already queued to merge\n", m.cs.WarningIcon(), ghrepo.FullName(m.baseRepo), m.pr.Number)
return ErrAlreadyInMergeQueue
}
return nil
@ -251,7 +251,7 @@ func (m *mergeContext) canMerge() error {
return nil
}
_ = m.warnf("%s Pull request #%d is not mergeable: %s.\n", m.cs.FailureIcon(), m.pr.Number, reason)
_ = m.warnf("%s Pull request %s#%d is not mergeable: %s.\n", m.cs.FailureIcon(), ghrepo.FullName(m.baseRepo), m.pr.Number, reason)
_ = m.warnf("To have the pull request merged after all the requirements have been met, add the `--auto` flag.\n")
if remote := remoteForMergeConflictResolution(m.baseRepo, m.pr, m.opts); remote != nil {
mergeOrRebase := "merge"
@ -344,7 +344,7 @@ func (m *mergeContext) merge() error {
}
if m.shouldAddToMergeQueue() {
_ = m.infof("%s Pull request #%d will be added to the merge queue for %s when ready\n", m.cs.SuccessIconWithColor(m.cs.Green), m.pr.Number, m.pr.BaseRefName)
_ = m.infof("%s Pull request %s#%d will be added to the merge queue for %s when ready\n", m.cs.SuccessIconWithColor(m.cs.Green), ghrepo.FullName(m.baseRepo), m.pr.Number, m.pr.BaseRefName)
return nil
}
@ -356,7 +356,7 @@ func (m *mergeContext) merge() error {
case PullRequestMergeMethodSquash:
method = " via squash"
}
return m.infof("%s Pull request #%d will be automatically merged%s when all requirements are met\n", m.cs.SuccessIconWithColor(m.cs.Green), m.pr.Number, method)
return m.infof("%s Pull request %s#%d will be automatically merged%s when all requirements are met\n", m.cs.SuccessIconWithColor(m.cs.Green), ghrepo.FullName(m.baseRepo), m.pr.Number, method)
}
action := "Merged"
@ -377,13 +377,13 @@ func (m *mergeContext) deleteLocalBranch() error {
if m.merged {
if m.opts.IO.CanPrompt() && !m.opts.IsDeleteBranchIndicated {
confirmed, err := m.opts.Prompter.Confirm(fmt.Sprintf("Pull request #%d was already merged. Delete the branch locally?", m.pr.Number), false)
confirmed, err := m.opts.Prompter.Confirm(fmt.Sprintf("Pull request %s#%d was already merged. Delete the branch locally?", ghrepo.FullName(m.baseRepo), m.pr.Number), false)
if err != nil {
return fmt.Errorf("could not prompt: %w", err)
}
m.deleteBranch = confirmed
} else {
_ = m.warnf(fmt.Sprintf("%s Pull request #%d was already merged\n", m.cs.WarningIcon(), m.pr.Number))
_ = m.warnf(fmt.Sprintf("%s Pull request %s#%d was already merged\n", m.cs.WarningIcon(), ghrepo.FullName(m.baseRepo), m.pr.Number))
}
}

View file

@ -369,7 +369,7 @@ func TestPrMerge_blocked(t *testing.T) {
assert.Equal(t, "", output.String())
assert.Equal(t, heredoc.Docf(`
X Pull request #1 is not mergeable: the base branch policy prohibits the merge.
X Pull request OWNER/REPO#1 is not mergeable: the base branch policy prohibits the merge.
To have the pull request merged after all the requirements have been met, add the %[1]s--auto%[1]s flag.
To use administrator privileges to immediately merge the pull request, add the %[1]s--admin%[1]s flag.
`, "`"), output.Stderr())
@ -402,7 +402,7 @@ func TestPrMerge_dirty(t *testing.T) {
assert.Equal(t, "", output.String())
assert.Equal(t, heredoc.Docf(`
X Pull request #123 is not mergeable: the merge commit cannot be cleanly created.
X Pull request OWNER/REPO#123 is not mergeable: the merge commit cannot be cleanly created.
To have the pull request merged after all the requirements have been met, add the %[1]s--auto%[1]s flag.
Run the following to resolve the merge conflicts locally:
gh pr checkout 123 && git fetch origin trunk && git merge origin/trunk
@ -1085,7 +1085,7 @@ func TestPrMerge_alreadyMerged(t *testing.T) {
pm := &prompter.PrompterMock{
ConfirmFunc: func(p string, d bool) (bool, error) {
if p == "Pull request #4 was already merged. Delete the branch locally?" {
if p == "Pull request OWNER/REPO#4 was already merged. Delete the branch locally?" {
return true, nil
} else {
return false, prompter.NoSuchPromptErr(p)
@ -1129,7 +1129,7 @@ func TestPrMerge_alreadyMerged_withMergeStrategy(t *testing.T) {
}
assert.Equal(t, "", output.String())
assert.Equal(t, "! Pull request #4 was already merged\n", output.Stderr())
assert.Equal(t, "! Pull request OWNER/REPO#4 was already merged\n", output.Stderr())
}
func TestPrMerge_alreadyMerged_withMergeStrategy_TTY(t *testing.T) {
@ -1156,7 +1156,7 @@ func TestPrMerge_alreadyMerged_withMergeStrategy_TTY(t *testing.T) {
pm := &prompter.PrompterMock{
ConfirmFunc: func(p string, d bool) (bool, error) {
if p == "Pull request #4 was already merged. Delete the branch locally?" {
if p == "Pull request OWNER/REPO#4 was already merged. Delete the branch locally?" {
return true, nil
} else {
return false, prompter.NoSuchPromptErr(p)
@ -1196,7 +1196,7 @@ func TestPrMerge_alreadyMerged_withMergeStrategy_crossRepo(t *testing.T) {
pm := &prompter.PrompterMock{
ConfirmFunc: func(p string, d bool) (bool, error) {
if p == "Pull request #4 was already merged. Delete the branch locally?" {
if p == "Pull request OWNER/REPO#4 was already merged. Delete the branch locally?" {
return d, nil
} else {
return false, prompter.NoSuchPromptErr(p)
@ -1576,7 +1576,7 @@ func TestMergeRun_autoMerge(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, "", stdout.String())
assert.Equal(t, "✓ Pull request #123 will be automatically merged via squash when all requirements are met\n", stderr.String())
assert.Equal(t, "✓ Pull request OWNER/REPO#123 will be automatically merged via squash when all requirements are met\n", stderr.String())
}
func TestMergeRun_autoMerge_directMerge(t *testing.T) {
@ -1649,7 +1649,7 @@ func TestMergeRun_disableAutoMerge(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, "", stdout.String())
assert.Equal(t, "✓ Auto-merge disabled for pull request #123\n", stderr.String())
assert.Equal(t, "✓ Auto-merge disabled for pull request OWNER/REPO#123\n", stderr.String())
}
func TestPrInMergeQueue(t *testing.T) {
@ -1680,7 +1680,7 @@ func TestPrInMergeQueue(t *testing.T) {
}
assert.Equal(t, "", output.String())
assert.Equal(t, "! Pull request #1 is already queued to merge\n", output.Stderr())
assert.Equal(t, "! Pull request OWNER/REPO#1 is already queued to merge\n", output.Stderr())
}
func TestPrAddToMergeQueueWithMergeMethod(t *testing.T) {
@ -1718,7 +1718,7 @@ func TestPrAddToMergeQueueWithMergeMethod(t *testing.T) {
t.Fatalf("error running command `pr merge`: %v", err)
}
assert.Equal(t, "", output.String())
assert.Equal(t, "! The merge strategy for main is set by the merge queue\n✓ Pull request #1 will be added to the merge queue for main when ready\n", output.Stderr())
assert.Equal(t, "! The merge strategy for main is set by the merge queue\n✓ Pull request OWNER/REPO#1 will be added to the merge queue for main when ready\n", output.Stderr())
}
func TestPrAddToMergeQueueClean(t *testing.T) {
@ -1758,7 +1758,7 @@ func TestPrAddToMergeQueueClean(t *testing.T) {
}
assert.Equal(t, "", output.String())
assert.Equal(t, "✓ Pull request #1 will be added to the merge queue for main when ready\n", output.Stderr())
assert.Equal(t, "✓ Pull request OWNER/REPO#1 will be added to the merge queue for main when ready\n", output.Stderr())
}
func TestPrAddToMergeQueueBlocked(t *testing.T) {
@ -1798,7 +1798,7 @@ func TestPrAddToMergeQueueBlocked(t *testing.T) {
}
assert.Equal(t, "", output.String())
assert.Equal(t, "✓ Pull request #1 will be added to the merge queue for main when ready\n", output.Stderr())
assert.Equal(t, "✓ Pull request OWNER/REPO#1 will be added to the merge queue for main when ready\n", output.Stderr())
}
func TestPrAddToMergeQueueAdmin(t *testing.T) {