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

Migrate teach-class script to project v2 API #390

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions script/create-initial-repo
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,13 @@ 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" \
--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() {
Expand Down Expand Up @@ -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

Expand Down
54 changes: 46 additions & 8 deletions script/shared_functions
Original file line number Diff line number Diff line change
Expand Up @@ -88,26 +88,64 @@ create_repo_project() {
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

# 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
# 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
}
}
' --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)
# 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')

# 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
# 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(
input: {
projectId: $proj_id,
shortDescription: $desc
}
){
projectV2 {
id
}
}
}
' >>log.out 2>&1

echo "Done."
else
print_error "Failed to create project."
Expand Down