Module: GitHubRepoDeleter

Defined in:
lib/github_repo_deleter.rb

Overview

Don't use this. Apparently you can delete them with the v2 API.

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



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/github_repo_deleter.rb', line 28

def delete_repo(, password, repo_name)
  raise "Don't use this. Use the GitHub V2 API instead. :-("
  cookies = {}
  auth_token = get_with_cookies('https://github.com/login', cookies)
  post_with_cookies('https://github.com/session',
                    {:login => ,
                     :password => password,
                     :commit => 'Log in',
                     :authenticity_token => auth_token},
                    cookies)
  repo_admin_url = "https://github.com/#{login}/#{repo_name}/admin"
  auth_token = get_with_cookies(repo_admin_url, cookies)
  post_with_cookies(repo_admin_url + '/delete',
                    {:_method => 'delete', :authenticity_token => auth_token},
                    cookies)
  return true
end