From 9351f272dc780bfc0c75d6d9777db70747879cb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 9 Jun 2022 14:38:58 +0200 Subject: [PATCH] pr merge: fix merge queue API access for PAT consumers The github.com API right now doesn't seem to make merge queue APIs available to people who use PAT to authenticate gh requests. This switches the conditional request strategy to also do feature-detection for dotcom (instead of just for Enterprise). --- .../featuredetection/feature_detection.go | 9 ++++--- .../feature_detection_test.go | 25 +++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/internal/featuredetection/feature_detection.go b/internal/featuredetection/feature_detection.go index 45800a8d7..5e6430f09 100644 --- a/internal/featuredetection/feature_detection.go +++ b/internal/featuredetection/feature_detection.go @@ -72,9 +72,12 @@ func (d *detector) IssueFeatures() (IssueFeatures, error) { } func (d *detector) PullRequestFeatures() (PullRequestFeatures, error) { - if !ghinstance.IsEnterprise(d.host) { - return allPullRequestFeatures, nil - } + // TODO: reinstate the short-circuit once the APIs are fully available on github.com + // https://github.com/cli/cli/issues/5778 + // + // if !ghinstance.IsEnterprise(d.host) { + // return allPullRequestFeatures, nil + // } features := PullRequestFeatures{ ReviewDecision: true, diff --git a/internal/featuredetection/feature_detection_test.go b/internal/featuredetection/feature_detection_test.go index ae8695482..261a099f4 100644 --- a/internal/featuredetection/feature_detection_test.go +++ b/internal/featuredetection/feature_detection_test.go @@ -20,6 +20,14 @@ func TestPullRequestFeatures(t *testing.T) { { name: "github.com", hostname: "github.com", + queryResponse: map[string]string{ + `query PullRequest_fields\b`: heredoc.Doc(` + { "data": { "PullRequest": { "fields": [ + {"name": "isInMergeQueue"}, + {"name": "isMergeQueueEnabled"} + ] } } } + `), + }, wantFeatures: PullRequestFeatures{ ReviewDecision: true, StatusCheckRollup: true, @@ -28,6 +36,23 @@ func TestPullRequestFeatures(t *testing.T) { }, wantErr: false, }, + { + name: "github.com with no merge queue", + hostname: "github.com", + queryResponse: map[string]string{ + `query PullRequest_fields\b`: heredoc.Doc(` + { "data": { "PullRequest": { "fields": [ + ] } } } + `), + }, + wantFeatures: PullRequestFeatures{ + ReviewDecision: true, + StatusCheckRollup: true, + BranchProtectionRule: true, + MergeQueue: false, + }, + wantErr: false, + }, { name: "GHE", hostname: "git.my.org",