Module: GitHubRepoDeleter
- Defined in:
- lib/github_repo_deleter.rb
Overview
A simple module with a single method, GitHubRepoDeleter.delete_repo
Use this if you need to programatically delete a GitHub repository, since that functionality is not yet exposed through their API. This module uses RestClient to make the requests, and it handles the details of the session cookies and XSRF/CSRF protection for you. It took me enough time to work out the details that I hope maybe this saves someone else the trouble some day.
Example:
GitHubRepoDeleter.delete_repo('yourgithubusername', 'yourgithubpassword',
'nameofrepotodelete')
#=> true
Because this relies on “faking” a web browser, it could stop working any time GitHub makes changes to their website. I wouldn’t use this in any production context.
Also, THIS DELETES THE REPOSITORY FROM GITHUB! USE AT YOUR OWN RISK. I AM NOT RESPONSIBLE IF YOU DO SOMETHING STUPID.
Class Method Summary collapse
Class Method Details
.delete_repo(login, password, repo_name) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/github_repo_deleter.rb', line 26 def delete_repo(login, password, repo_name) = {} auth_token = ('https://github.com/login', ) ('https://github.com/session', {:login => login, :password => password, :commit => 'Log in', :authenticity_token => auth_token}, ) repo_admin_url = "https://github.com/#{login}/#{repo_name}/admin" auth_token = (repo_admin_url, ) (repo_admin_url + '/delete', {:_method => 'delete', :authenticity_token => auth_token}, ) return true end |