From 2d2b1fcf57b6908a02dd2e33762554a7a96b7ed0 Mon Sep 17 00:00:00 2001 From: Greg Larkin Date: Tue, 7 Feb 2023 14:50:02 -0800 Subject: [PATCH 01/15] Removed REST API project creation from repo setup - now unsupported --- script/create-initial-repo | 18 -------- script/shared_functions | 95 -------------------------------------- 2 files changed, 113 deletions(-) diff --git a/script/create-initial-repo b/script/create-initial-repo index d501d7c6..f4e5d648 100755 --- a/script/create-initial-repo +++ b/script/create-initial-repo @@ -129,23 +129,6 @@ update_readme() { --message "Update _config.yml" } -create_initial_project() { - # Create project and save the project ID so we can use it to create project columns and cards - create_repo_project --repo "$initial_repo_name" \ - --name "Caption Contest" \ - --body "Let's see who can create the best captions for our collection of memes." - local project_id="$REPO_PROJECT_ID" - - # Create project columns and save the ID of the first colum so we can add a card to it - create_project_column --project_id "$project_id" --name "To do" && local column_one="$COLUMN_ID" - create_project_column --project_id "$project_id" --name "In progress" - create_project_column --project_id "$project_id" --name "Done" - - # Add a note to column one - create_project_card --project_id "$project_id" --column_id "$column_one" \ - --note "Each student will update their file in the _slides directory with an image and a caption." -} - update_branch_protections() { # Update branch protection rules for the default branch if http --check-status --ignore-stdin --quiet --auth "$TOKEN_OWNER:$TEACHER_PAT" --raw '{ @@ -205,7 +188,6 @@ clone_initial_repo update_readme update_branch_protections create_initial_issue -create_initial_project enable_github_pages print_done "Here's a link to the repo: $repo_url" diff --git a/script/shared_functions b/script/shared_functions index c7731b22..66e79ce4 100755 --- a/script/shared_functions +++ b/script/shared_functions @@ -78,101 +78,6 @@ create_repo() { fi } -create_repo_project() { - while (($#)); do - case $1 in - --repo) local repo=$2 ;; - --name) local name=$2 ;; - --body) local body=$2 ;; - esac - shift - done - - local projects_endpoint="$org_repos_endpoint/$repo/projects" - - echo -n "Creating project: $name... " - - # Unset $REPO_PROJECT_ID in case it was set previously - unset REPO_PROJECT_ID - - # Create the project and get the project ID - REPO_PROJECT_ID=$(http --check-status --ignore-stdin --auth \ - "$TOKEN_OWNER:$TEACHER_PAT" "$projects_endpoint" \ - "Accept:application/vnd.github.inertia-preview+json" \ - name="$name" \ - body="$body" | - jq .id) - - # Export $REPO_PROJECT_ID so it can be used in other scripts - export REPO_PROJECT_ID - - # Check if $REPO_PROJECT_ID has a value - if [[ -n "$REPO_PROJECT_ID" ]] || [[ "$REPO_PROJECT_ID" = null ]]; then - echo "Done." - else - print_error "Failed to create project." - fi -} - -create_project_column() { - while (($#)); do - case $1 in - --project_id) local project_id=$2 ;; - --name) local name=$2 ;; - esac - shift - done - - local project_column_endpoint="https://$INSTANCE_URL/projects/$project_id/columns" - - echo -n "Creating project column: $name... " - - # Unset $COLUMN_ID in case it was set previously - unset COLUMN_ID - - # Create the project column and get the column ID - COLUMN_ID=$(http --check-status --ignore-stdin --auth \ - "$TOKEN_OWNER:$TEACHER_PAT" "$project_column_endpoint" \ - "Accept:application/vnd.github.inertia-preview+json" \ - project_id="$project_id" \ - name="$name" | - jq .id) - - # Export $COLUMN_ID so it can be used in other scripts - export COLUMN_ID - - # Check if $COLUMN_ID has a value - if [[ -n "$COLUMN_ID" ]] || [[ "$COLUMN_ID" = null ]]; then - echo "Done." - else - print_error "Failed to create project column." - fi -} - -create_project_card() { - while (($#)); do - case $1 in - --project_id) local project_id=$2 ;; - --column_id) local column_id=$2 ;; - --note) local note=$2 ;; - esac - shift - done - - local project_card_endpoint="https://$INSTANCE_URL/projects/columns/$column_id/cards" - - echo -n "Creating project card: $name... " - - if http --check-status --ignore-stdin --quiet --auth \ - "$TOKEN_OWNER:$TEACHER_PAT" "$project_card_endpoint" \ - "Accept:application/vnd.github.inertia-preview+json" \ - project_id="$project_id" \ - column_id="$column_id" \ - note="$note"; then - echo "Done." - fi -} - get_repo_content() { while (($#)); do case $1 in From 1852dd07bbec0bdac86ad97a67d3a430f43613f6 Mon Sep 17 00:00:00 2001 From: Greg Larkin Date: Fri, 10 Feb 2023 10:13:19 -0800 Subject: [PATCH 02/15] Revert "Removed REST API project creation from repo setup - now unsupported" Reimplement using GraphQL API for v2 projects This reverts commit 2d2b1fcf57b6908a02dd2e33762554a7a96b7ed0. --- script/create-initial-repo | 18 ++++++++ script/shared_functions | 95 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+) diff --git a/script/create-initial-repo b/script/create-initial-repo index f4e5d648..d501d7c6 100755 --- a/script/create-initial-repo +++ b/script/create-initial-repo @@ -129,6 +129,23 @@ update_readme() { --message "Update _config.yml" } +create_initial_project() { + # Create project and save the project ID so we can use it to create project columns and cards + create_repo_project --repo "$initial_repo_name" \ + --name "Caption Contest" \ + --body "Let's see who can create the best captions for our collection of memes." + local project_id="$REPO_PROJECT_ID" + + # Create project columns and save the ID of the first colum so we can add a card to it + create_project_column --project_id "$project_id" --name "To do" && local column_one="$COLUMN_ID" + create_project_column --project_id "$project_id" --name "In progress" + create_project_column --project_id "$project_id" --name "Done" + + # Add a note to column one + create_project_card --project_id "$project_id" --column_id "$column_one" \ + --note "Each student will update their file in the _slides directory with an image and a caption." +} + update_branch_protections() { # Update branch protection rules for the default branch if http --check-status --ignore-stdin --quiet --auth "$TOKEN_OWNER:$TEACHER_PAT" --raw '{ @@ -188,6 +205,7 @@ clone_initial_repo update_readme update_branch_protections create_initial_issue +create_initial_project enable_github_pages print_done "Here's a link to the repo: $repo_url" diff --git a/script/shared_functions b/script/shared_functions index 66e79ce4..c7731b22 100755 --- a/script/shared_functions +++ b/script/shared_functions @@ -78,6 +78,101 @@ create_repo() { fi } +create_repo_project() { + while (($#)); do + case $1 in + --repo) local repo=$2 ;; + --name) local name=$2 ;; + --body) local body=$2 ;; + esac + shift + done + + local projects_endpoint="$org_repos_endpoint/$repo/projects" + + echo -n "Creating project: $name... " + + # Unset $REPO_PROJECT_ID in case it was set previously + unset REPO_PROJECT_ID + + # Create the project and get the project ID + REPO_PROJECT_ID=$(http --check-status --ignore-stdin --auth \ + "$TOKEN_OWNER:$TEACHER_PAT" "$projects_endpoint" \ + "Accept:application/vnd.github.inertia-preview+json" \ + name="$name" \ + body="$body" | + jq .id) + + # Export $REPO_PROJECT_ID so it can be used in other scripts + export REPO_PROJECT_ID + + # Check if $REPO_PROJECT_ID has a value + if [[ -n "$REPO_PROJECT_ID" ]] || [[ "$REPO_PROJECT_ID" = null ]]; then + echo "Done." + else + print_error "Failed to create project." + fi +} + +create_project_column() { + while (($#)); do + case $1 in + --project_id) local project_id=$2 ;; + --name) local name=$2 ;; + esac + shift + done + + local project_column_endpoint="https://$INSTANCE_URL/projects/$project_id/columns" + + echo -n "Creating project column: $name... " + + # Unset $COLUMN_ID in case it was set previously + unset COLUMN_ID + + # Create the project column and get the column ID + COLUMN_ID=$(http --check-status --ignore-stdin --auth \ + "$TOKEN_OWNER:$TEACHER_PAT" "$project_column_endpoint" \ + "Accept:application/vnd.github.inertia-preview+json" \ + project_id="$project_id" \ + name="$name" | + jq .id) + + # Export $COLUMN_ID so it can be used in other scripts + export COLUMN_ID + + # Check if $COLUMN_ID has a value + if [[ -n "$COLUMN_ID" ]] || [[ "$COLUMN_ID" = null ]]; then + echo "Done." + else + print_error "Failed to create project column." + fi +} + +create_project_card() { + while (($#)); do + case $1 in + --project_id) local project_id=$2 ;; + --column_id) local column_id=$2 ;; + --note) local note=$2 ;; + esac + shift + done + + local project_card_endpoint="https://$INSTANCE_URL/projects/columns/$column_id/cards" + + echo -n "Creating project card: $name... " + + if http --check-status --ignore-stdin --quiet --auth \ + "$TOKEN_OWNER:$TEACHER_PAT" "$project_card_endpoint" \ + "Accept:application/vnd.github.inertia-preview+json" \ + project_id="$project_id" \ + column_id="$column_id" \ + note="$note"; then + echo "Done." + fi +} + get_repo_content() { while (($#)); do case $1 in From bbfd936da8588a6b10305ea82eb733ccdabf0f83 Mon Sep 17 00:00:00 2001 From: Greg Larkin Date: Fri, 10 Feb 2023 12:28:15 -0800 Subject: [PATCH 03/15] Updated project creation to use GraphQL API for V2 projects --- script/create-initial-repo | 13 ++++++------- script/shared_functions | 40 +++++++++++++++++++++++++++++--------- 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/script/create-initial-repo b/script/create-initial-repo index d501d7c6..b90d9f20 100755 --- a/script/create-initial-repo +++ b/script/create-initial-repo @@ -132,18 +132,17 @@ update_readme() { create_initial_project() { # Create project and save the project ID so we can use it to create project columns and cards create_repo_project --repo "$initial_repo_name" \ - --name "Caption Contest" \ - --body "Let's see who can create the best captions for our collection of memes." + --name "Caption Contest" local project_id="$REPO_PROJECT_ID" # Create project columns and save the ID of the first colum so we can add a card to it - create_project_column --project_id "$project_id" --name "To do" && local column_one="$COLUMN_ID" - create_project_column --project_id "$project_id" --name "In progress" - create_project_column --project_id "$project_id" --name "Done" + # create_project_column --project_id "$project_id" --name "To do" && local column_one="$COLUMN_ID" + # create_project_column --project_id "$project_id" --name "In progress" + # create_project_column --project_id "$project_id" --name "Done" # Add a note to column one - create_project_card --project_id "$project_id" --column_id "$column_one" \ - --note "Each student will update their file in the _slides directory with an image and a caption." + # create_project_card --project_id "$project_id" --column_id "$column_one" \ + # --note "Each student will update their file in the _slides directory with an image and a caption." } update_branch_protections() { diff --git a/script/shared_functions b/script/shared_functions index c7731b22..9d68ccf2 100755 --- a/script/shared_functions +++ b/script/shared_functions @@ -83,25 +83,47 @@ create_repo_project() { case $1 in --repo) local repo=$2 ;; --name) local name=$2 ;; - --body) local body=$2 ;; esac shift done - local projects_endpoint="$org_repos_endpoint/$repo/projects" - echo -n "Creating project: $name... " # Unset $REPO_PROJECT_ID in case it was set previously unset REPO_PROJECT_ID + # Set GH_TOKEN here for gh api. This should be handled more generally once + # all API calls are converted to GraphQL. + GH_TOKEN=$TEACHER_PAT + + # Get the organization's ID + ORG_ID=$(gh api -H "Accept: application/vnd.github+json" /users/$CLASS_ORG --jq '.node_id') + + # Get the repository's ID + REPO_ID=$(gh api graphql --paginate -f org_name=$CLASS_ORG -f repo_name=$repo -f query=' + query GetRepo($org_name:String!, $repo_name:String!) { + repository(name: $repo_name, owner: $org_name ) { + id + } + } +' --jq '.data.repository.id') + # Create the project and get the project ID - REPO_PROJECT_ID=$(http --check-status --ignore-stdin --auth \ - "$TOKEN_OWNER:$TEACHER_PAT" "$projects_endpoint" \ - "Accept:application/vnd.github.inertia-preview+json" \ - name="$name" \ - body="$body" | - jq .id) + REPO_PROJECT_ID=$(gh api graphql -f owner_id=$ORG_ID -f repo_id=$REPO_ID -f name="$name" -f query=' + mutation CreateProject($owner_id:ID!, $repo_id:ID!, $name:String!){ + createProjectV2( + input: { + ownerId: $owner_id, + repositoryId: $repo_id, + title: $name + } + ){ + projectV2 { + id + } + } + } +' --jq '.data[].projectV2.id') # Export $REPO_PROJECT_ID so it can be used in other scripts export REPO_PROJECT_ID From e336d96f9227ff81f2226b9dfa4ac78edef56837 Mon Sep 17 00:00:00 2001 From: Greg Larkin Date: Fri, 10 Feb 2023 13:05:54 -0800 Subject: [PATCH 04/15] Fix Superlinter complaint --- script/shared_functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/shared_functions b/script/shared_functions index 9d68ccf2..ce06ff6c 100755 --- a/script/shared_functions +++ b/script/shared_functions @@ -121,7 +121,7 @@ create_repo_project() { projectV2 { id } - } + } } ' --jq '.data[].projectV2.id') From 6cb0010e8b96ad8cf9125cbf93e8e709a720e3b6 Mon Sep 17 00:00:00 2001 From: Greg Larkin Date: Fri, 10 Feb 2023 15:13:20 -0800 Subject: [PATCH 05/15] Disable unused env var shellcheck warning since it's used implicitly. --- script/shared_functions | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/script/shared_functions b/script/shared_functions index ce06ff6c..58119427 100755 --- a/script/shared_functions +++ b/script/shared_functions @@ -93,7 +93,11 @@ create_repo_project() { unset REPO_PROJECT_ID # Set GH_TOKEN here for gh api. This should be handled more generally once - # all API calls are converted to GraphQL. + # all API calls are converted to GraphQL. Disable the shellcheck warning here + # since this variable is not directly used in this script but read by the + # gh api command. + + # shellcheck disable=SC2034 GH_TOKEN=$TEACHER_PAT # Get the organization's ID From 49e7b8664245356d1b5da2428061106999e1a670 Mon Sep 17 00:00:00 2001 From: Greg Larkin Date: Fri, 10 Feb 2023 15:26:05 -0800 Subject: [PATCH 06/15] Resolve the rest of the SuperLinter info messages --- script/shared_functions | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/script/shared_functions b/script/shared_functions index 58119427..31c14070 100755 --- a/script/shared_functions +++ b/script/shared_functions @@ -101,10 +101,11 @@ create_repo_project() { GH_TOKEN=$TEACHER_PAT # Get the organization's ID - ORG_ID=$(gh api -H "Accept: application/vnd.github+json" /users/$CLASS_ORG --jq '.node_id') + ORG_ID=$(gh api -H "Accept: application/vnd.github+json" "/users/$CLASS_ORG" --jq '.node_id') # Get the repository's ID - REPO_ID=$(gh api graphql --paginate -f org_name=$CLASS_ORG -f repo_name=$repo -f query=' + # shellcheck disable=SC2016 + REPO_ID=$(gh api graphql --paginate -f org_name="$CLASS_ORG" -f repo_name="$repo" -f query=' query GetRepo($org_name:String!, $repo_name:String!) { repository(name: $repo_name, owner: $org_name ) { id @@ -113,7 +114,8 @@ create_repo_project() { ' --jq '.data.repository.id') # Create the project and get the project ID - REPO_PROJECT_ID=$(gh api graphql -f owner_id=$ORG_ID -f repo_id=$REPO_ID -f name="$name" -f query=' + # shellcheck disable=SC2016 + REPO_PROJECT_ID=$(gh api graphql -f owner_id="$ORG_ID" -f repo_id="$REPO_ID" -f name="$name" -f query=' mutation CreateProject($owner_id:ID!, $repo_id:ID!, $name:String!){ createProjectV2( input: { From 9cb594e8f806d52f6196613f9926201eb2d8cb96 Mon Sep 17 00:00:00 2001 From: Greg Larkin Date: Mon, 13 Feb 2023 15:20:03 -0800 Subject: [PATCH 07/15] Re-added the ability to set the project description, now using GraphQL --- script/create-initial-repo | 3 ++- script/shared_functions | 49 +++++++++++++++++++++++++------------- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/script/create-initial-repo b/script/create-initial-repo index b90d9f20..cf8606e3 100755 --- a/script/create-initial-repo +++ b/script/create-initial-repo @@ -132,7 +132,8 @@ update_readme() { create_initial_project() { # Create project and save the project ID so we can use it to create project columns and cards create_repo_project --repo "$initial_repo_name" \ - --name "Caption Contest" + --name "Caption Contest" \ + --body "Let's see who can create the best captions for our collection of memes." local project_id="$REPO_PROJECT_ID" # Create project columns and save the ID of the first colum so we can add a card to it diff --git a/script/shared_functions b/script/shared_functions index 31c14070..3a7062ae 100755 --- a/script/shared_functions +++ b/script/shared_functions @@ -83,6 +83,7 @@ create_repo_project() { case $1 in --repo) local repo=$2 ;; --name) local name=$2 ;; + --body) local body=$2 ;; esac shift done @@ -98,7 +99,7 @@ create_repo_project() { # gh api command. # shellcheck disable=SC2034 - GH_TOKEN=$TEACHER_PAT + export GH_TOKEN=$TEACHER_PAT # Get the organization's ID ORG_ID=$(gh api -H "Accept: application/vnd.github+json" "/users/$CLASS_ORG" --jq '.node_id') @@ -111,31 +112,47 @@ create_repo_project() { id } } -' --jq '.data.repository.id') + ' --jq '.data.repository.id') # Create the project and get the project ID # shellcheck disable=SC2016 REPO_PROJECT_ID=$(gh api graphql -f owner_id="$ORG_ID" -f repo_id="$REPO_ID" -f name="$name" -f query=' - mutation CreateProject($owner_id:ID!, $repo_id:ID!, $name:String!){ - createProjectV2( - input: { - ownerId: $owner_id, - repositoryId: $repo_id, - title: $name - } - ){ - projectV2 { - id - } - } - } -' --jq '.data[].projectV2.id') + mutation CreateProject($owner_id:ID!, $repo_id:ID!, $name:String!){ + createProjectV2( + input: { + ownerId: $owner_id, + repositoryId: $repo_id, + title: $name + } + ){ + projectV2 { + id + } + } + } + ' --jq '.data[].projectV2.id') # Export $REPO_PROJECT_ID so it can be used in other scripts export REPO_PROJECT_ID # Check if $REPO_PROJECT_ID has a value if [[ -n "$REPO_PROJECT_ID" ]] || [[ "$REPO_PROJECT_ID" = null ]]; then + # After it's been created, update the project with the short description + gh api graphql -f proj_id="$REPO_PROJECT_ID" -f desc="$body" -f query=' + mutation UpdateProjectWithDescription($proj_id:ID!, $desc:String) { + updateProjectV2( + input: { + projectId: $proj_id, + shortDescription: $desc + } + ){ + projectV2 { + id + } + } + } + ' + echo "Done." else print_error "Failed to create project." From e3fd8361e9b209dcb7bef36bff4fc782b192f06d Mon Sep 17 00:00:00 2001 From: Greg Larkin Date: Mon, 13 Feb 2023 15:57:07 -0800 Subject: [PATCH 08/15] Implement project column creation with GraphQL --- script/create-initial-repo | 14 +++++++++++--- script/shared_functions | 33 ++++++++++++++++----------------- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/script/create-initial-repo b/script/create-initial-repo index cf8606e3..bb827581 100755 --- a/script/create-initial-repo +++ b/script/create-initial-repo @@ -137,9 +137,9 @@ create_initial_project() { local project_id="$REPO_PROJECT_ID" # Create project columns and save the ID of the first colum so we can add a card to it - # create_project_column --project_id "$project_id" --name "To do" && local column_one="$COLUMN_ID" - # create_project_column --project_id "$project_id" --name "In progress" - # create_project_column --project_id "$project_id" --name "Done" + create_project_column --project_id "$project_id" --name "To do" && local column_one="$COLUMN_ID" + create_project_column --project_id "$project_id" --name "In progress" + create_project_column --project_id "$project_id" --name "Done" # Add a note to column one # create_project_card --project_id "$project_id" --column_id "$column_one" \ @@ -192,6 +192,14 @@ enable_github_pages() { fi } +# Set GH_TOKEN here for gh api. This should be handled more generally once +# all API calls are converted to GraphQL. Disable the shellcheck warning here +# since this variable is not directly used in this script but used by the +# gh api commands elsewhere. + +# shellcheck disable=SC2034 +export GH_TOKEN=$TEACHER_PAT + # Get the repo name get_initial_repo_name diff --git a/script/shared_functions b/script/shared_functions index 3a7062ae..b030f371 100755 --- a/script/shared_functions +++ b/script/shared_functions @@ -93,14 +93,6 @@ create_repo_project() { # Unset $REPO_PROJECT_ID in case it was set previously unset REPO_PROJECT_ID - # Set GH_TOKEN here for gh api. This should be handled more generally once - # all API calls are converted to GraphQL. Disable the shellcheck warning here - # since this variable is not directly used in this script but read by the - # gh api command. - - # shellcheck disable=SC2034 - export GH_TOKEN=$TEACHER_PAT - # Get the organization's ID ORG_ID=$(gh api -H "Accept: application/vnd.github+json" "/users/$CLASS_ORG" --jq '.node_id') @@ -138,6 +130,7 @@ create_repo_project() { # Check if $REPO_PROJECT_ID has a value if [[ -n "$REPO_PROJECT_ID" ]] || [[ "$REPO_PROJECT_ID" = null ]]; then # After it's been created, update the project with the short description + # shellcheck disable=SC2016 gh api graphql -f proj_id="$REPO_PROJECT_ID" -f desc="$body" -f query=' mutation UpdateProjectWithDescription($proj_id:ID!, $desc:String) { updateProjectV2( @@ -167,21 +160,27 @@ create_project_column() { esac shift done - - local project_column_endpoint="https://$INSTANCE_URL/projects/$project_id/columns" - + echo -n "Creating project column: $name... " # Unset $COLUMN_ID in case it was set previously unset COLUMN_ID # Create the project column and get the column ID - COLUMN_ID=$(http --check-status --ignore-stdin --auth \ - "$TOKEN_OWNER:$TEACHER_PAT" "$project_column_endpoint" \ - "Accept:application/vnd.github.inertia-preview+json" \ - project_id="$project_id" \ - name="$name" | - jq .id) + COLUMN_ID=$(gh api graphql -f proj_id="$project_id" -f name="$name" -f query=' + mutation CreateProjectColumn($proj_id:ID!, $name:String!) { + createProjectColumn( + input: { + project_id: $proj_id, + name: $name + } + ){ + project_column { + id + } + } + } + ' --jq '.data[].project_column.id') # Export $COLUMN_ID so it can be used in other scripts export COLUMN_ID From be65bc31e6fbfe1a55acd3709ee5777c7c8199a0 Mon Sep 17 00:00:00 2001 From: Greg Larkin Date: Mon, 13 Feb 2023 16:12:04 -0800 Subject: [PATCH 09/15] Cleaning up SuperLinter warnings --- script/create-initial-repo | 10 +++------- script/shared_functions | 1 + 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/script/create-initial-repo b/script/create-initial-repo index bb827581..9d65a12c 100755 --- a/script/create-initial-repo +++ b/script/create-initial-repo @@ -142,8 +142,8 @@ create_initial_project() { create_project_column --project_id "$project_id" --name "Done" # Add a note to column one - # create_project_card --project_id "$project_id" --column_id "$column_one" \ - # --note "Each student will update their file in the _slides directory with an image and a caption." + create_project_card --project_id "$project_id" --column_id "$column_one" \ + --note "Each student will update their file in the _slides directory with an image and a caption." } update_branch_protections() { @@ -193,11 +193,7 @@ enable_github_pages() { } # Set GH_TOKEN here for gh api. This should be handled more generally once -# all API calls are converted to GraphQL. Disable the shellcheck warning here -# since this variable is not directly used in this script but used by the -# gh api commands elsewhere. - -# shellcheck disable=SC2034 +# all API calls are converted to GraphQL. export GH_TOKEN=$TEACHER_PAT # Get the repo name diff --git a/script/shared_functions b/script/shared_functions index b030f371..575aaa07 100755 --- a/script/shared_functions +++ b/script/shared_functions @@ -167,6 +167,7 @@ create_project_column() { unset COLUMN_ID # Create the project column and get the column ID + # shellcheck disable=SC2016 COLUMN_ID=$(gh api graphql -f proj_id="$project_id" -f name="$name" -f query=' mutation CreateProjectColumn($proj_id:ID!, $name:String!) { createProjectColumn( From 8134684088df0d7a2ef79304bb64125f2aac2b76 Mon Sep 17 00:00:00 2001 From: Greg Larkin Date: Mon, 13 Feb 2023 16:15:43 -0800 Subject: [PATCH 10/15] Removed whitespace --- script/shared_functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/shared_functions b/script/shared_functions index 575aaa07..aeb2cc1c 100755 --- a/script/shared_functions +++ b/script/shared_functions @@ -160,7 +160,7 @@ create_project_column() { esac shift done - + echo -n "Creating project column: $name... " # Unset $COLUMN_ID in case it was set previously From cd4e3e684b3f2ccbdddd91e94bbfb3896bdf0988 Mon Sep 17 00:00:00 2001 From: Greg Larkin Date: Mon, 13 Feb 2023 18:07:51 -0800 Subject: [PATCH 11/15] Revert "Implement project column creation with GraphQL" This reverts commit e3fd8361e9b209dcb7bef36bff4fc782b192f06d. --- script/create-initial-repo | 10 +++------- script/shared_functions | 32 ++++++++++++++++---------------- 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/script/create-initial-repo b/script/create-initial-repo index 9d65a12c..11040354 100755 --- a/script/create-initial-repo +++ b/script/create-initial-repo @@ -137,9 +137,9 @@ create_initial_project() { local project_id="$REPO_PROJECT_ID" # Create project columns and save the ID of the first colum so we can add a card to it - create_project_column --project_id "$project_id" --name "To do" && local column_one="$COLUMN_ID" - create_project_column --project_id "$project_id" --name "In progress" - create_project_column --project_id "$project_id" --name "Done" + # create_project_column --project_id "$project_id" --name "To do" && local column_one="$COLUMN_ID" + # create_project_column --project_id "$project_id" --name "In progress" + # create_project_column --project_id "$project_id" --name "Done" # Add a note to column one create_project_card --project_id "$project_id" --column_id "$column_one" \ @@ -192,10 +192,6 @@ enable_github_pages() { fi } -# Set GH_TOKEN here for gh api. This should be handled more generally once -# all API calls are converted to GraphQL. -export GH_TOKEN=$TEACHER_PAT - # Get the repo name get_initial_repo_name diff --git a/script/shared_functions b/script/shared_functions index aeb2cc1c..3a7062ae 100755 --- a/script/shared_functions +++ b/script/shared_functions @@ -93,6 +93,14 @@ create_repo_project() { # Unset $REPO_PROJECT_ID in case it was set previously unset REPO_PROJECT_ID + # Set GH_TOKEN here for gh api. This should be handled more generally once + # all API calls are converted to GraphQL. Disable the shellcheck warning here + # since this variable is not directly used in this script but read by the + # gh api command. + + # shellcheck disable=SC2034 + export GH_TOKEN=$TEACHER_PAT + # Get the organization's ID ORG_ID=$(gh api -H "Accept: application/vnd.github+json" "/users/$CLASS_ORG" --jq '.node_id') @@ -130,7 +138,6 @@ create_repo_project() { # Check if $REPO_PROJECT_ID has a value if [[ -n "$REPO_PROJECT_ID" ]] || [[ "$REPO_PROJECT_ID" = null ]]; then # After it's been created, update the project with the short description - # shellcheck disable=SC2016 gh api graphql -f proj_id="$REPO_PROJECT_ID" -f desc="$body" -f query=' mutation UpdateProjectWithDescription($proj_id:ID!, $desc:String) { updateProjectV2( @@ -161,27 +168,20 @@ create_project_column() { shift done + local project_column_endpoint="https://$INSTANCE_URL/projects/$project_id/columns" + echo -n "Creating project column: $name... " # Unset $COLUMN_ID in case it was set previously unset COLUMN_ID # Create the project column and get the column ID - # shellcheck disable=SC2016 - COLUMN_ID=$(gh api graphql -f proj_id="$project_id" -f name="$name" -f query=' - mutation CreateProjectColumn($proj_id:ID!, $name:String!) { - createProjectColumn( - input: { - project_id: $proj_id, - name: $name - } - ){ - project_column { - id - } - } - } - ' --jq '.data[].project_column.id') + COLUMN_ID=$(http --check-status --ignore-stdin --auth \ + "$TOKEN_OWNER:$TEACHER_PAT" "$project_column_endpoint" \ + "Accept:application/vnd.github.inertia-preview+json" \ + project_id="$project_id" \ + name="$name" | + jq .id) # Export $COLUMN_ID so it can be used in other scripts export COLUMN_ID From 6613ce939a2ff00a33f141c8571fe5dba2aff356 Mon Sep 17 00:00:00 2001 From: Greg Larkin Date: Mon, 13 Feb 2023 18:11:59 -0800 Subject: [PATCH 12/15] Fix SuperLinter error and disable project card creation --- script/create-initial-repo | 4 ++-- script/shared_functions | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/script/create-initial-repo b/script/create-initial-repo index 11040354..10ec8e6e 100755 --- a/script/create-initial-repo +++ b/script/create-initial-repo @@ -142,8 +142,8 @@ create_initial_project() { # create_project_column --project_id "$project_id" --name "Done" # Add a note to column one - create_project_card --project_id "$project_id" --column_id "$column_one" \ - --note "Each student will update their file in the _slides directory with an image and a caption." + # create_project_card --project_id "$project_id" --column_id "$column_one" \ + # --note "Each student will update their file in the _slides directory with an image and a caption." } update_branch_protections() { diff --git a/script/shared_functions b/script/shared_functions index 3a7062ae..be92375a 100755 --- a/script/shared_functions +++ b/script/shared_functions @@ -138,6 +138,7 @@ create_repo_project() { # Check if $REPO_PROJECT_ID has a value if [[ -n "$REPO_PROJECT_ID" ]] || [[ "$REPO_PROJECT_ID" = null ]]; then # After it's been created, update the project with the short description + # shellcheck disable=SC2016 gh api graphql -f proj_id="$REPO_PROJECT_ID" -f desc="$body" -f query=' mutation UpdateProjectWithDescription($proj_id:ID!, $desc:String) { updateProjectV2( From 75cf4cc036280e2b69a887831a62cf5df8995639 Mon Sep 17 00:00:00 2001 From: Greg Larkin Date: Tue, 14 Feb 2023 13:20:52 -0800 Subject: [PATCH 13/15] Log the output of the projectV2 update --- script/shared_functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/shared_functions b/script/shared_functions index be92375a..fdbbb89c 100755 --- a/script/shared_functions +++ b/script/shared_functions @@ -152,7 +152,7 @@ create_repo_project() { } } } - ' + ' >> log.out 2>&1 echo "Done." else From a9eb19c851e64a56b7b503535de301f2de6ea888 Mon Sep 17 00:00:00 2001 From: Greg Larkin Date: Tue, 14 Feb 2023 13:32:19 -0800 Subject: [PATCH 14/15] Move setting GH_TOKEN to a higher script for all functions that may need it --- script/create-initial-repo | 3 +++ script/shared_functions | 8 -------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/script/create-initial-repo b/script/create-initial-repo index 10ec8e6e..6af1983b 100755 --- a/script/create-initial-repo +++ b/script/create-initial-repo @@ -192,6 +192,9 @@ enable_github_pages() { fi } +# Set GH_TOKEN here for gh api +export GH_TOKEN=$TEACHER_PAT + # Get the repo name get_initial_repo_name diff --git a/script/shared_functions b/script/shared_functions index fdbbb89c..98ad8336 100755 --- a/script/shared_functions +++ b/script/shared_functions @@ -93,14 +93,6 @@ create_repo_project() { # Unset $REPO_PROJECT_ID in case it was set previously unset REPO_PROJECT_ID - # Set GH_TOKEN here for gh api. This should be handled more generally once - # all API calls are converted to GraphQL. Disable the shellcheck warning here - # since this variable is not directly used in this script but read by the - # gh api command. - - # shellcheck disable=SC2034 - export GH_TOKEN=$TEACHER_PAT - # Get the organization's ID ORG_ID=$(gh api -H "Accept: application/vnd.github+json" "/users/$CLASS_ORG" --jq '.node_id') From 783118ef41925454bbe1c4000c13f0e0f629b1b8 Mon Sep 17 00:00:00 2001 From: Greg Larkin Date: Tue, 14 Feb 2023 13:42:56 -0800 Subject: [PATCH 15/15] Whitespace fix --- script/shared_functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/shared_functions b/script/shared_functions index 98ad8336..7bed3a42 100755 --- a/script/shared_functions +++ b/script/shared_functions @@ -144,7 +144,7 @@ create_repo_project() { } } } - ' >> log.out 2>&1 + ' >>log.out 2>&1 echo "Done." else