CoveredCA / common-devops

Apache License 2.0
0 stars 0 forks source link

update deployment issue workflow so that the issues have project metadata fields updated for better sorting and filtering #3

Closed tallguyjenks closed 3 months ago

tallguyjenks commented 3 months ago

Have to use the new graph API to access beta projects

Project ID's

related article

can use their graph api explorer and run this query to find the project ID's for the org:

{
  organization(login: "CoveredCA") {
    login
    projectsV2(first: 100) {
      edges {
        node {
          id
          title
        }
      }
    }
  }
}

Field ID's

gh api graphql -f query='
            query($org: String!, $number: Int!) {
              organization(login: $org){
                projectV2(number: $number) {
                  id
                  fields(first:20) {
                    nodes {
                      ... on ProjectV2Field {
                        id
                        name
                      }
                      ... on ProjectV2SingleSelectField {
                        id
                        name
                        options {
                          id
                          name
                        }
                      }
                    }
                  }
                }
              }
            }' -f org=$ORGANIZATION -F number=$PROJECT_NUMBER

run update operations on a given item

gh api graphql -f query='
    mutation {
        updateProjectV2ItemFieldValue(
            input: {
                projectId: "PVT_kwDOAfwVjc4AV0R8"
                itemId: "40946050"
                fieldId: "121975948"
                value: {
                    text: "hello world"
                }
            }
        )
        {
            projectV2Item {
                id
            }
        }
    }'
tallguyjenks commented 3 months ago

jq query to get the results from issue query to grab ID for final graph QL update

jq '.data.organization.projectV2.items.nodes[] | select(.content.number == 17) | select(.content.title | test("cca-[a-zA-Z0-9-]+-[a-zA-Z]api"))' deployment_issues.json | jq -r .content.id
tallguyjenks commented 3 months ago

This bash script could use pagination to get all items in the project to make it easier to manage with jq

# Initial cursor is empty
CURSOR=""

# Loop until all pages are fetched
while : ; do
    # Execute GraphQL query
    RESPONSE=$(gh api graphql -f query='
    query($org: String!, $number: Int!, $cursor: String) {
        organization(login: $org) {
            projectV2(number: $number) {
                items(first: 100, after: $cursor) {
                    pageInfo {
                        hasNextPage
                        endCursor
                    }
                    nodes {
                        id
                        content {
                            ... on Issue {
                                id
                                number
                                title
                            }
                        }
                    }
                }
            }
        }
    }' -f org="$ORGANIZATION" -F number=$PROJECT_NUMBER -f cursor="$CURSOR")

    # Parse items and do something with them, e.g., append to a file
    echo "$RESPONSE" | jq '.data.organization.projectV2.items.nodes[]' >> deployment_issues.json

    # Check if there's a next page; if not, break the loop
    HAS_NEXT_PAGE=$(echo "$RESPONSE" | jq '.data.organization.projectV2.items.pageInfo.hasNextPage')
    if [ "$HAS_NEXT_PAGE" != "true" ]; then
        break
    fi

    # Update cursor to fetch next page
    CURSOR=$(echo "$RESPONSE" | jq -r '.data.organization.projectV2.items.pageInfo.endCursor')
done

echo "All items fetched successfully."
jq '. | select(.content.number == 17) | select(.content.title | test("cca-salesforce-sapi"))' deployment_issues.json
tallguyjenks commented 3 months ago

2024-07-19

got things to start working but i had to change the secrets in the org to be available to all repositories in the org including public, but this is just temporary for testing on workflow call directly from common-devops repository.

after im done testing this reusable flow will need to be called from the pipeline which is called by the child processes and thats how the secrets get accessed. so ultimately the secrets need to be returned to their original state of private and internal repositories only.

also to pick up where i left off:

❗ the job is not liking the interpolation of the variables for the ID's to go into the query, might need separate job steps and pass the variables using github mechanisms rather than pure bash, idk, why arent the variables passing?

tallguyjenks commented 3 months ago

further work to be done on this issue:

tallguyjenks commented 3 months ago

2024-07-23

the new fields are added and populated correctly now for the deployment issue which allows for easier sorting in the deployment dashboard pane and overall filtering is possible too by the version text field now when filtering in the search bar.

for the time being we're calling this work good, theres more that could probably be done here with custom fields but at the moment i think this work is complete.