This example target provides a command-line interface for querying the GitHub GraphQL API for details on a specific project (V2) item.
This example should always be executed from inside this directory (since it searches for a configuration file here).
At the end of this quick start, you should be able to print out details about GitHub Projects items, like below:
- Install and set up the GitHub CLI tool
- On macOS with Homebrew installed, you can just run:
brew install gh
gh auth login
- On macOS with Homebrew installed, you can just run:
- In this directory, copy
config.example.yaml
toconfig.yaml
- Create a GitHub App in your account (alternatively use an existing app you have already created)
- The only values you need to fill in is the app name and URL (which can be your GitHub profile URL), and you can uncheck
Active
underWebhook
- Under
Organization permissions
, thenProjects
, grantRead-only
permissions
- The only values you need to fill in is the app name and URL (which can be your GitHub profile URL), and you can uncheck
- After successful creation, copy the
App ID
value and replace the example value for the keyappId
inconfig.yaml
- At the bottom of the same page, under
Private keys
, generate a private key for your app - Open the generated and downloaded
.pem
file in a text editor, copy the entire contents, and replace the example value for the keyprivateKey
inconfig.yaml
- Create a new example project (alternatively reuse an existing project you have already created)
- Install your new app on the account containing the new project
- After successful installation, copy the username of the user or organization you installed the app on and replace the example value for the key
username
inconfig.yaml
- Add a new draft issue to your project
- Get the unique node ID for the draft issue:
- From the URL of your new project, copy the ID of the project (
https://github.com/.../{username}/projects/{id}
) - Run the following command, replacing
{username}
and{projectId}
with your corresponding values:gh api graphql -f query='query { organization(login: "{username}") { projectV2(number: {projectId}) { id items(first: 1) { nodes { id } } } } }'
- You should receive a response like this:
{ "data": { "organization": { "projectV2": { "id": "PVT_...", "items": { "nodes": [ { "id": "PVTI_..." } ] } } } } }
- Copy the ID starting with
PVTI_
for use below
- From the URL of your new project, copy the ID of the project (
Here are some example commands for fetching information about the project item or showing help information about the CLI:
swift run GithubProjectsGraphqlClient {project item ID starting with PVTI_}
: send the exact example payload shown aboveswift run GithubProjectsGraphqlClient --help
: print the CLI's help message