.  ./.gh-api-examples.conf

# 


org=${1:-$org}

graphql_query=tmp/graphql_query.txt

cat <<EOF >$graphql_query
query{
  organization(login:"$org") {
    repositories(first:50){
      nodes{
        name
        vulnerabilityAlerts(first:100){
          nodes{
            createdAt
            dismissedAt
            dismissReason
            securityAdvisory{ ghsaId description }
            vulnerableManifestPath
            vulnerableManifestFilename
            securityVulnerability{
              firstPatchedVersion{
                identifier
              }
              vulnerableVersionRange
              package{
                name
                ecosystem
              }
              severity
              advisory {
                id
              }
            }
          }
        }
          }
        }
      }
    }
EOF

cat >&2 $graphql_query

json_file=tmp/graphql-organization-vulnerabilities-payload.json
jq -n \
  --arg graphql_query "$(cat $graphql_query)" \
  '{query: $graphql_query}' > ${json_file}


curl ${curl_custom_flags} \
     -H "Accept: application/vnd.github.v3+json" \
     -H "Authorization: Bearer ${GITHUB_TOKEN}" \
        "${GITHUB_APIV4_BASE_URL}" -d @${json_file} | jq

