1

I'm using ProjectsV2 in Github, and since we don't have some pretty basic automations, I'm trying to write my own.

I need to get a list of all my custom fields in the project, so I can then use their ids to modify those fields using my script.

I already managed to get a list of projects, labels, issues, prs, but the custom fields are giving me grief.

I'm trying this and all sorts of variants (which worked for almost every other list I needed):

query { 
  repository(owner:"OWNER", name:"REPO") { 
    projectV2(number: 2) {
        ... on ProjectV2 {
          fields(last: 20) {
            nodes {
              ProjectV2Field
                nodes {
                id
                } 
            }
          }
        }
    }
  }}

What I get is:

{
"errors": [
    {
        "path": [
            "query",
            "repository",
            "projectV2",
            "... on ProjectV2",
            "fields",
            "nodes",
            "ProjectV2Field"
        ],
        "extensions": {
            "code": "selectionMismatch",
            "nodeName": "ProjectV2FieldConfiguration"
        },
        "locations": [
            {
                "line": 6,
                "column": 17
            }
        ],
        "message": "Selections can't be made directly on unions (see selections on ProjectV2FieldConfiguration)"
    },
    {
        "path": [
            "query",
            "repository",
            "projectV2",
            "... on ProjectV2",
            "fields",
            "nodes",
            "nodes"
        ],
        "extensions": {
            "code": "selectionMismatch",
            "nodeName": "ProjectV2FieldConfiguration"
        },
        "locations": [
            {
                "line": 6,
                "column": 17
            }
        ],
        "message": "Selections can't be made directly on unions (see selections on ProjectV2FieldConfiguration)"
    }
]

}

I am new to graphql and I am trying to read Github's docs on it but I just can't figure this structure or what the error message means.

Any tips that can point me on the right direction are very much appreciated. Thanks!

EDIT:

I made some progress. The following query gives me a list of (most of the) fields, but no single select ones:

query {
      repository(owner:"OWNER", name:"REPO") {
        projectV2(number: 2) {
            ... on ProjectV2 {
                fields(first: 100) {
                    nodes {
                        ... on ProjectV2Field {
                            id
                            name
                            dataType
                        }
                    }
                }
            }
        }
      }
}

Response (with ids redacted):

{
"data": {
    "repository": {
        "projectV2": {
            "fields": {
                "nodes": [
                    {
                        "id": "ID",
                        "name": "Title",
                        "dataType": "TITLE"
                    },
                    {
                        "id": "ID",
                        "name": "Assignees",
                        "dataType": "ASSIGNEES"
                    },
                    {},
                    {
                        "id": "ID",
                        "name": "Labels",
                        "dataType": "LABELS"
                    },
                    {
                        "id": "ID",
                        "name": "Linked pull requests",
                        "dataType": "LINKED_PULL_REQUESTS"
                    },
                    {
                        "id": "ID",
                        "name": "Reviewers",
                        "dataType": "REVIEWERS"
                    },
                    {
                        "id": "ID",
                        "name": "Repository",
                        "dataType": "REPOSITORY"
                    },
                    {
                        "id": "ID",
                        "name": "Milestone",
                        "dataType": "MILESTONE"
                    },
                    {
                        "id": "ID",
                        "name": "Due",
                        "dataType": "DATE"
                    },
                    {
                        "id": "ID",
                        "name": "Days",
                        "dataType": "NUMBER"
                    },
                    {
                        "id": "ID",
                        "name": "Target",
                        "dataType": "TEXT"
                    },
                    {
                        "id": "ID",
                        "name": "Start Date",
                        "dataType": "DATE"
                    },
                    {
                        "id": "ID",
                        "name": "End Date",
                        "dataType": "DATE"
                    },
                    {},
                    {
                        "id": "ID",
                        "name": "PR Size",
                        "dataType": "NUMBER"
                    },
                    {}
                ]
            }
        }
    }
}

}

Almost there!

1 Answer 1

0

I know this question is a while ago, but I hope that an adapted version of the following script may be useful for anyone who finds this question in a search.

#!/bin/bash

# Get ProjectV2 fields and single-select options
curl -X POST \
  -H "Authorization: Bearer $GITHUB_TOKEN" \
  -H "Content-Type: application/json" \
  -d "{
    \"query\": \"query(\$nodeId: ID!) {
      node(id: \$nodeId) {
        ... on ProjectV2 {
          fields(first: 20) {
            nodes {
              ... on ProjectV2Field {
                id
                name
                dataType
              }
              ... on ProjectV2IterationField {
                id
                name
                dataType
              }
              ... on ProjectV2SingleSelectField {
                id
                name
                dataType
                options {
                  id
                  name
                  color
                }
              }
            }
          }
        }
      }
    }\",
    \"variables\": {
      \"nodeId\": \"$GITHUB_PROJECT_NODE_ID\"
    }
  }" \
  https://api.github.com/graphql
Sign up to request clarification or add additional context in comments.

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.