|
| 1 | +#!/bin/bash |
| 2 | +set -e |
| 3 | +set -u |
| 4 | +set -o pipefail |
| 5 | + |
| 6 | +GH_ORG=${GH_ORG:-'kubernetes'} |
| 7 | +PROJECT_NUMBER=${PROJECT_NUMBER:-'82'} |
| 8 | + |
| 9 | +echo "GH_ORG=${GH_ORG}" |
| 10 | + |
| 11 | +# Get project ID |
| 12 | +project_id="$(gh api graphql -f query=' |
| 13 | + query($org: String!, $number: Int!) { |
| 14 | + organization(login: $org) { |
| 15 | + projectV2(number: $number) { |
| 16 | + id |
| 17 | + } |
| 18 | + } |
| 19 | + }' -f org=${GH_ORG} -F number=${PROJECT_NUMBER} --jq '.data.organization.projectV2.id')" |
| 20 | +echo "project id: ${project_id}" |
| 21 | + |
| 22 | +# Get list of repos in the org |
| 23 | +repos_json="$(gh api graphql --paginate -f query=' |
| 24 | + query($org: String!, $endCursor: String) { |
| 25 | + viewer { |
| 26 | + organization(login: $org) { |
| 27 | + repositories(first:100, after: $endCursor) { |
| 28 | + nodes { |
| 29 | + name |
| 30 | + } |
| 31 | + pageInfo { |
| 32 | + hasNextPage |
| 33 | + endCursor |
| 34 | + } |
| 35 | + } |
| 36 | + } |
| 37 | + } |
| 38 | + }' -f org=${GH_ORG})" |
| 39 | + |
| 40 | +repos="$(jq ".data.viewer.organization.repositories.nodes[].name" <<< "$repos_json" | tr -d '"' )" |
| 41 | + |
| 42 | +for repo in $repos |
| 43 | +do |
| 44 | + echo "Looking for issues in ${GH_ORG}/${repo}" |
| 45 | + |
| 46 | + # TODO: paginate this query |
| 47 | + issues_json="$(gh api graphql -f query=' |
| 48 | + query($org: String!, $repo: String!) { |
| 49 | + repository(owner: $org, name: $repo) { |
| 50 | + issues(last: 100, labels: ["sig/Windows"], states: OPEN) { |
| 51 | + totalCount |
| 52 | + nodes { |
| 53 | + id |
| 54 | + number |
| 55 | + title |
| 56 | + } |
| 57 | + } |
| 58 | + } |
| 59 | + }' -f org=${GH_ORG} -f repo=${repo})" |
| 60 | + |
| 61 | + num_issues=$(jq ".data.repository.issues.nodes | length" <<< "$issues_json") |
| 62 | + echo " found ${num_issues} in repo" |
| 63 | + |
| 64 | + if [ $num_issues -gt 0 ]; then |
| 65 | + range=$((num_issues - 1)) |
| 66 | + for i in $(seq 0 $range) |
| 67 | + do |
| 68 | + issue_id=$(jq ".data.repository.issues.nodes[$i].id" <<< "$issues_json") |
| 69 | + issue_title=$(jq ".data.repository.issues.nodes[$i].title" <<< "$issues_json") |
| 70 | + issue_number=$(jq ".data.repository.issues.nodes[$i].number" <<< "$issues_json") |
| 71 | + echo " adding ${issue_number} - ${issue_title}" |
| 72 | + |
| 73 | + gh api graphql -f query=' |
| 74 | + mutation($project:ID!, $issue:ID!) { |
| 75 | + addProjectV2ItemById(input: {projectId: $project, contentId: $issue}) { |
| 76 | + item { |
| 77 | + id |
| 78 | + } |
| 79 | + } |
| 80 | + }' -f project=${project_id} -f issue="${issue_id}" --jq .data.addProjectV2ItemById.item.id > /dev/null |
| 81 | + done |
| 82 | + fi |
| 83 | +done |
0 commit comments