Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
tallguyjenks opened this issue Jul 18, 2024 · 5 comments
Assignees
Labels
enhancement Improvement of existing features and functionality

Comments

@tallguyjenks
Copy link
Member

tallguyjenks commented Jul 18, 2024

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 tallguyjenks added the enhancement Improvement of existing features and functionality label Jul 18, 2024
@tallguyjenks tallguyjenks self-assigned this Jul 18, 2024
@tallguyjenks
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

tallguyjenks commented Jul 19, 2024

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.

  • return org secrets back to their initial state

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
Copy link
Member Author

tallguyjenks commented Jul 22, 2024

further work to be done on this issue:

  • make new fields for major, minor, and patch versions so the app can actually be sorted correctly as it is still sorting based on text string values incorrectly
    • make those fields
    • update the reusable action to modify those fields
    • parse the version number value to correctly grab the parts

@tallguyjenks
Copy link
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement of existing features and functionality
Projects
None yet
Development

No branches or pull requests

1 participant