mirror of
https://github.com/github/gh-stack.git
synced 2026-09-14 20:26:28 +08:00
dcb5885053
Detect merge queue status via the GitHub GraphQL API's mergeQueueEntry field and temporarily skip queued branches in push, sync, and submit commands. Unlike merged state (which is persisted permanently), queued state is transient — held in-memory only via a json:"-" tagged field on BranchRef. Each command run re-checks queue status from the API, so if a PR is ejected from the queue it becomes active again on next run. Changes: - Add MergeQueueEntry to PullRequest GraphQL struct and PRDetails - Add IsQueued()/IsSkipped()/QueuedBranches() to stack model - Update ActiveBranches() family to exclude queued branches - Skip queued branches in push, sync (rebase + push), and submit - Add queued icon, style, and QUEUED state label in TUI view - Add comprehensive tests for queued state handling Closes github/pull-requests#24019 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
package github
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestPRURL(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
host string
|
|
owner string
|
|
repo string
|
|
number int
|
|
want string
|
|
}{
|
|
{"github.com", "github.com", "owner", "repo", 42, "https://github.com/owner/repo/pull/42"},
|
|
{"GHES host", "ghes.example.com", "myorg", "myrepo", 99, "https://ghes.example.com/myorg/myrepo/pull/99"},
|
|
{"empty host defaults to github.com", "", "owner", "repo", 1, "https://github.com/owner/repo/pull/1"},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := PRURL(tt.host, tt.owner, tt.repo, tt.number)
|
|
assert.Equal(t, tt.want, got)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestPullRequest_IsQueued(t *testing.T) {
|
|
t.Run("not queued when MergeQueueEntry is nil", func(t *testing.T) {
|
|
pr := &PullRequest{Number: 1}
|
|
assert.False(t, pr.IsQueued())
|
|
})
|
|
|
|
t.Run("queued when MergeQueueEntry has ID", func(t *testing.T) {
|
|
pr := &PullRequest{
|
|
Number: 1,
|
|
MergeQueueEntry: &MergeQueueEntry{ID: "MQE_123"},
|
|
}
|
|
assert.True(t, pr.IsQueued())
|
|
})
|
|
|
|
t.Run("nil receiver is safe", func(t *testing.T) {
|
|
var pr *PullRequest
|
|
assert.False(t, pr.IsQueued())
|
|
})
|
|
}
|