Drop client-side feature detection for issue relationships
Let the API return its own "unsupported" error rather than gating the relationship mutations behind a client-side IssueRelationships check. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
8f9069b275
commit
315dafbf74
4 changed files with 4 additions and 83 deletions
|
|
@ -423,14 +423,8 @@ func createRun(opts *CreateOptions) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
// TODO IssueRelationshipsCleanup
|
||||
if issueFeatures.IssueRelationshipsSupported {
|
||||
err = applyRelationships(apiClient, baseRepo, newIssue, opts)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
} else if len(opts.BlockedBy) > 0 || len(opts.Blocking) > 0 {
|
||||
err = fmt.Errorf("issue relationships are not supported on this GitHub Enterprise Server version")
|
||||
err = applyRelationships(apiClient, baseRepo, newIssue, opts)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -941,58 +941,6 @@ func Test_createRun(t *testing.T) {
|
|||
wantsStdout: "https://github.com/OWNER/REPO/issues/123\n",
|
||||
wantsStderr: "\nCreating issue in OWNER/REPO\n\n",
|
||||
},
|
||||
{
|
||||
name: "blocked-by unsupported on GHES",
|
||||
opts: CreateOptions{
|
||||
Detector: &fd.DisabledDetectorMock{},
|
||||
Title: "blocked issue",
|
||||
Body: "blocked body",
|
||||
BlockedBy: []string{"200"},
|
||||
},
|
||||
httpStubs: func(_ *testing.T, r *httpmock.Registry) {
|
||||
r.Register(
|
||||
httpmock.GraphQL(`query IssueRepositoryInfo\b`),
|
||||
httpmock.StringResponse(`
|
||||
{ "data": { "repository": {
|
||||
"id": "REPOID",
|
||||
"hasIssuesEnabled": true
|
||||
} } }`))
|
||||
r.Register(
|
||||
httpmock.GraphQL(`mutation IssueCreate\b`),
|
||||
httpmock.StringResponse(`
|
||||
{ "data": { "createIssue": { "issue": {
|
||||
"id": "ISSUE_ID_123",
|
||||
"URL": "https://github.com/OWNER/REPO/issues/123"
|
||||
} } } }`))
|
||||
},
|
||||
wantsErr: "issue relationships are not supported on this GitHub Enterprise Server version",
|
||||
},
|
||||
{
|
||||
name: "blocking unsupported on GHES",
|
||||
opts: CreateOptions{
|
||||
Detector: &fd.DisabledDetectorMock{},
|
||||
Title: "blocking issue",
|
||||
Body: "blocking body",
|
||||
Blocking: []string{"300"},
|
||||
},
|
||||
httpStubs: func(_ *testing.T, r *httpmock.Registry) {
|
||||
r.Register(
|
||||
httpmock.GraphQL(`query IssueRepositoryInfo\b`),
|
||||
httpmock.StringResponse(`
|
||||
{ "data": { "repository": {
|
||||
"id": "REPOID",
|
||||
"hasIssuesEnabled": true
|
||||
} } }`))
|
||||
r.Register(
|
||||
httpmock.GraphQL(`mutation IssueCreate\b`),
|
||||
httpmock.StringResponse(`
|
||||
{ "data": { "createIssue": { "issue": {
|
||||
"id": "ISSUE_ID_123",
|
||||
"URL": "https://github.com/OWNER/REPO/issues/123"
|
||||
} } } }`))
|
||||
},
|
||||
wantsErr: "issue relationships are not supported on this GitHub Enterprise Server version",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -424,7 +424,7 @@ func editRun(opts *EditOptions) error {
|
|||
}
|
||||
|
||||
// Relationship mutations
|
||||
if err := applyEditRelationships(apiClient, baseRepo, issue, opts, issueFeatures); err != nil {
|
||||
if err := applyEditRelationships(apiClient, baseRepo, issue, opts); err != nil {
|
||||
failedIssueChan <- fmt.Sprintf("failed to update relationships for %s: %s", issue.URL, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -529,18 +529,13 @@ func applyEditSubIssues(client *api.Client, baseRepo ghrepo.Interface, issue *ap
|
|||
return nil
|
||||
}
|
||||
|
||||
func applyEditRelationships(client *api.Client, baseRepo ghrepo.Interface, issue *api.Issue, opts *EditOptions, features fd.IssueFeatures) error {
|
||||
func applyEditRelationships(client *api.Client, baseRepo ghrepo.Interface, issue *api.Issue, opts *EditOptions) error {
|
||||
hasRelationshipFlags := len(opts.AddBlockedBy) > 0 || len(opts.RemoveBlockedBy) > 0 ||
|
||||
len(opts.AddBlocking) > 0 || len(opts.RemoveBlocking) > 0
|
||||
if !hasRelationshipFlags {
|
||||
return nil
|
||||
}
|
||||
|
||||
// TODO IssueRelationshipsCleanup
|
||||
if !features.IssueRelationshipsSupported {
|
||||
return fmt.Errorf("issue relationships are not supported on this GitHub Enterprise Server version")
|
||||
}
|
||||
|
||||
hostname := baseRepo.RepoHost()
|
||||
|
||||
for _, ref := range opts.AddBlockedBy {
|
||||
|
|
|
|||
|
|
@ -1227,22 +1227,6 @@ func Test_editRun(t *testing.T) {
|
|||
},
|
||||
stdout: "https://github.com/OWNER/REPO/issue/123\n",
|
||||
},
|
||||
{
|
||||
name: "relationships unsupported on GHES",
|
||||
input: &EditOptions{
|
||||
Detector: &fd.DisabledDetectorMock{},
|
||||
IssueNumbers: []int{123},
|
||||
Interactive: false,
|
||||
AddBlockedBy: []string{"200"},
|
||||
FetchOptions: func(_ *api.Client, _ ghrepo.Interface, _ *prShared.Editable, _ gh.ProjectsV1Support) error {
|
||||
return nil
|
||||
},
|
||||
},
|
||||
httpStubs: func(t *testing.T, reg *httpmock.Registry) {
|
||||
mockIssueGet(t, reg)
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "batch edit type",
|
||||
input: &EditOptions{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue