Skip to content

Remove old student repositories #1

@king-michael

Description

@king-michael

Remove the old student repositories via api

  • requires:
    • a TOKEN with the permissions: delete_repo, read:org
    • curl (installed on ubuntu)
    • jq (installed on ubuntu)
  • store the following code as script
  • run bash delete_repos.sh TOKEN

delete_repos.sh

#!/bin/bash
GITHUB_TOKEN=$1 
ORGANISATION="KonstanzPythonSchool"
assigment_nr=*

case $GITHUB_TOKEN in 
  ""|-h|-help|--help)
  echo "bash $0 <token>"
  echo "token need to have the permissions : delete_repo, read:org"
  exit 1
  ;;
  *)
  ;;
esac


JSON=$(curl -s -H "Authorization: bearer $GITHUB_TOKEN" https://api.github.com/graphql -d @- << EOF
{ 
 "query" : "query {
    organization(login: \"${ORGANISATION}\") {
      repositories(first: 100, privacy: PRIVATE) {
        nodes { name }
      }
    }
  }"
}
EOF
)

REPOS=$(echo $JSON | jq -r ".data.organization.repositories.nodes[].name")
for repo in $REPOS; do
  if [[ $repo == assignment-${assigment_nr} ]]; then
   echo "delete: $repo"
   curl -H "Authorization: token $GITHUB_TOKEN" -XDELETE https://api.github.com/repos/${ORGANISATION}/$repo
  fi
done

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions