Created
May 28, 2021 15:32
-
-
Save dedoussis/1dca803d62a0152d97b5df4aee6ddfbc to your computer and use it in GitHub Desktop.
Delete all deployments of a given GitHub repository
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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