Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 11, 2025

Replace gh.Exec("api", "graphql", ...) shell-out with native GraphQL client in checkRepositoryHasDiscussionsUncached().

Changes

  • Use api.DefaultGraphQLClient() and client.Do() instead of subprocess execution
  • Pass variables as map[string]interface{} instead of CLI flags
  • Remove manual JSON unmarshaling (handled by client)

Before/After

// Before: shell-out with manual unmarshaling
stdOut, _, err := gh.Exec("api", "graphql", 
    "-f", fmt.Sprintf("query=%s", query),
    "-f", fmt.Sprintf("owner=%s", owner), 
    "-f", fmt.Sprintf("name=%s", name))
var response GraphQLResponse
json.Unmarshal(stdOut.Bytes(), &response)

// After: native client
client, err := api.DefaultGraphQLClient()
variables := map[string]interface{}{"owner": owner, "name": name}
var response struct { Repository struct { HasDiscussionsEnabled bool } }
client.Do(query, variables, &response)

Eliminates subprocess overhead (~4-8x faster) and provides type-safe variable handling.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • go.googlesource.com
    • Triggering command: /update-job-proxy /update-job-proxy DOCKER est sed -e 66938e9.0 /usr/share/ca-certificates/mozilla/SSL.com_Root_Certification_Authority_ECC.crt est cb5ee0f.0 df98af7ea253e22dconfig /bin/test sed -e CA1.pem /usr/share/ca-certificates/mozilla/UCA_Extended_Validation_Root.crt /bin/test tification_Autho/usr/sbin/iptables TLS_2021.crt by/a39a2078d7d03-t test (dns block)
    • Triggering command: /update-job-proxy /update-job-proxy -o br-64ff6f5f7811 -j DROP /etc/ssl/certs/e-n1 01828a75:go.mod e/git ommScope_Public_/usr/lib/git-core/git /usr/share/ca-cerev-list /usr/bin/sed e/git conf�� --global ty /bin/git ssh://git@github/usr/sbin/iptables /usr/share/ca-ce--wait /bin/test git (dns block)
  • go.uber.org
    • Triggering command: /update-job-proxy /update-job-proxy DOCKER est sed -e 66938e9.0 /usr/share/ca-certificates/mozilla/SSL.com_Root_Certification_Authority_ECC.crt est cb5ee0f.0 df98af7ea253e22dconfig /bin/test sed -e CA1.pem /usr/share/ca-certificates/mozilla/UCA_Extended_Validation_Root.crt /bin/test tification_Autho/usr/sbin/iptables TLS_2021.crt by/a39a2078d7d03-t test (dns block)
    • Triggering command: /update-job-proxy /update-job-proxy -o br-64ff6f5f7811 -j DROP /etc/ssl/certs/e-n1 01828a75:go.mod e/git ommScope_Public_/usr/lib/git-core/git /usr/share/ca-cerev-list /usr/bin/sed e/git conf�� --global ty /bin/git ssh://git@github/usr/sbin/iptables /usr/share/ca-ce--wait /bin/test git (dns block)
  • go.yaml.in
    • Triggering command: /update-job-proxy /update-job-proxy DOCKER est sed -e 66938e9.0 /usr/share/ca-certificates/mozilla/SSL.com_Root_Certification_Authority_ECC.crt est cb5ee0f.0 df98af7ea253e22dconfig /bin/test sed -e CA1.pem /usr/share/ca-certificates/mozilla/UCA_Extended_Validation_Root.crt /bin/test tification_Autho/usr/sbin/iptables TLS_2021.crt by/a39a2078d7d03-t test (dns block)
    • Triggering command: /update-job-proxy /update-job-proxy -o br-64ff6f5f7811 -j DROP /etc/ssl/certs/e-n1 01828a75:go.mod e/git ommScope_Public_/usr/lib/git-core/git /usr/share/ca-cerev-list /usr/bin/sed e/git conf�� --global ty /bin/git ssh://git@github/usr/sbin/iptables /usr/share/ca-ce--wait /bin/test git (dns block)
  • gopkg.in
    • Triggering command: /update-job-proxy /update-job-proxy DOCKER est sed -e 66938e9.0 /usr/share/ca-certificates/mozilla/SSL.com_Root_Certification_Authority_ECC.crt est cb5ee0f.0 df98af7ea253e22dconfig /bin/test sed -e CA1.pem /usr/share/ca-certificates/mozilla/UCA_Extended_Validation_Root.crt /bin/test tification_Autho/usr/sbin/iptables TLS_2021.crt by/a39a2078d7d03-t test (dns block)
    • Triggering command: /update-job-proxy /update-job-proxy -o br-64ff6f5f7811 -j DROP /etc/ssl/certs/e-n1 01828a75:go.mod e/git ommScope_Public_/usr/lib/git-core/git /usr/share/ca-cerev-list /usr/bin/sed e/git conf�� --global ty /bin/git ssh://git@github/usr/sbin/iptables /usr/share/ca-ce--wait /bin/test git (dns block)
  • https://api.github.com/user
    • Triggering command: /usr/bin/gh gh api user --jq .login it/ref/tags/v5 GO111MODULE ps GOINSECURE GOMOD GOMODCACHE ps out.�� out.git GOPROXY /home/REDACTED/work/gh-aw/gh-aw/node_modules/.bin/sh GOSUMDB GOWORK 64/bin/go ; \ fi (http block)
    • Triggering command: /usr/bin/gh gh api user --jq .login action.git GOPROXY /node_modules/.bin/sh GOSUMDB GOWORK 64/pkg/tool/linuxterm-color sh -c prettier --write '**/*.cjs' '**/*.ts' '**/*.json' 64/pkg/tool/linuGO111MODULE 64/bin/node --show-toplevel 64/pkg/tool/linumcp-server 64/bin/go node (http block)
    • Triggering command: /usr/bin/gh gh api user --jq .login s/ format:schema d1f156012a0b1aa062ce6f902e7bf73062f/log.json wright" --help 64/pkg/tool/linu-c 64/pkg/tool/linu"mcp-server-playwright" --help sh -c it/ref/tags/v5 64/pkg/tool/linuGO111MODULE (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>[plan] Migrate GraphQL discussions check to native client</issue_title>
<issue_description>## Objective

Replace gh.Exec("api", "graphql", ...) shell-outs with the native GraphQL API client for checking if discussions are enabled.

Context

The discussions feature detection uses GraphQL queries via shell-outs. The native GraphQL client provides type-safe variable handling and cleaner query execution.

Files to Modify

  • Update: pkg/workflow/repository_features_validation.go (lines ~286-310)

Current Implementation

stdOut, _, err := gh.Exec("api", "graphql", 
    "-f", fmt.Sprintf("query=%s", query),
    "-f", fmt.Sprintf("owner=%s", owner), 
    "-f", fmt.Sprintf("name=%s", name))
if err != nil {
    // error handling
}
var response GraphQLResponse
if err := json.Unmarshal(stdOut.Bytes(), &response); err != nil {
    return false, fmt.Errorf("failed to parse GraphQL response: %w", err)
}

Target Implementation

import "github.com/cli/go-gh/v2/pkg/api"

client, err := api.DefaultGraphQLClient()
if err != nil {
    return false, fmt.Errorf("failed to create GraphQL client: %w", err)
}

variables := map[string]interface{}{
    "owner": owner,
    "name":  name,
}

var response GraphQLResponse
err = client.Query("HasDiscussions", &response, variables)
if err != nil {
    // error handling
}

Approach

  1. Import github.com/cli/go-gh/v2/pkg/api
  2. Create GraphQL client with api.DefaultGraphQLClient()
  3. Define variables as map[string]interface{}
  4. Replace shell-out with client.Query()
  5. Update error handling
  6. Test with repositories that have/don't have discussions

Acceptance Criteria

  • gh.Exec("api", "graphql", ...) replaced with client.Query()
  • Variables passed as map instead of CLI flags
  • Manual JSON unmarshaling removed
  • GraphQL query still correctly detects discussions
  • Error handling preserves fallback behavior
  • All unit tests pass (make test-unit)

Expected Impact

  • Performance: ~4-8x faster GraphQL queries
  • Code Quality: Type-safe variable handling
  • Maintainability: Cleaner query execution

Estimated Effort

20-30 minutes
Related to #5828

AI generated by Plan Command for discussion #5826

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits December 11, 2025 20:21
Co-authored-by: mnkiefer <8320933+mnkiefer@users.noreply.github.com>
Replace gh.Exec shell-out with api.DefaultGraphQLClient() for checking if discussions are enabled. The native client provides type-safe variable handling and cleaner query execution.

Changes:
- Import github.com/cli/go-gh/v2/pkg/api
- Use api.DefaultGraphQLClient() instead of gh.Exec
- Pass variables as map instead of CLI flags
- Use client.Do() for direct query execution
- Remove manual JSON unmarshaling (handled by client)
- Maintain same error handling and fallback behavior

Related to #5828

Co-authored-by: mnkiefer <8320933+mnkiefer@users.noreply.github.com>
Copilot AI changed the title [WIP] Migrate GraphQL discussions check to native client Migrate GraphQL discussions check to native client Dec 11, 2025
Copilot AI requested a review from mnkiefer December 11, 2025 20:46
@pelikhan pelikhan closed this Dec 11, 2025
@pelikhan pelikhan deleted the copilot/migrate-graphql-client-checks branch December 15, 2025 04:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[plan] Migrate GraphQL discussions check to native client

3 participants