shellgithubcommand-line-interfacecicd

finding option id of single select field in github projects by using `gh` cli


I want to update a single select field by using gh command. However, the problem is to find single-select-option-id

gh project item-edit --id $id              \
    --single-select-option-id <option-id>  \
    --field-id $field_id                   \
    --project-id $project_id
variable source result
$id gh project item-list ✔️
$field_id gh project field-list ✔️
<option-id> ✖️

I couldn't manage to fetch the id of this single select field. Is there a solution for this?


Solution

  • The list of values is in the field details. You can see the options in the JSON output only.

    # Get all the fields from a project
    gh project field-list "${PROJECT_NUMBER}" --owner "${ORG}" --format json 
    
    # Get field ID
    gh project field-list "${PROJECT_NUMBER}" --owner "${ORG}" --format json --jq '.fields[]|select(.name == "my-field-name").id'
    
    # Get field option id
    gh project field-list "${PROJECT_NUMBER}" --owner "${ORG}" --format json --jq '.fields[]|select(.name == "my-field-name")|.options[]|select(.name == "My Option Name").id'