Skip to content

Instantly share code, notes, and snippets.

@dedoussis
Created May 28, 2021 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dedoussis/1dca803d62a0152d97b5df4aee6ddfbc to your computer and use it in GitHub Desktop.
Save dedoussis/1dca803d62a0152d97b5df4aee6ddfbc to your computer and use it in GitHub Desktop.
Delete all deployments of a given GitHub repository
#!/usr/bin/env python3
"""
Clears all deployments from a given repo
Requirements: pip install PyGithub
Usage: GITHUB_ACCESS_TOKEN=${MY_PAT} REPO_NAME=twbs/bootstrap delete_deployments.py
"""
from github import Github
import os
def main():
client = Github(os.environ["GITHUB_ACCESS_TOKEN"])
repo = client.get_repo(os.environ["REPO_NAME"])
for deployment in repo.get_deployments():
headers, data = client._Github__requester.requestJsonAndCheck(
"DELETE", deployment.url
)
print(headers, data)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment