Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: defunkt/github-gem
...
head fork: defunkt/github-gem
compare: organizations
Checking mergeability… Don't worry, you can still create the pull request.
  • 1 commit
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Commits on Mar 23, 2012
@drnic drnic trying out v3 api 69dbcb5
Showing with 63 additions and 8 deletions.
  1. +63 −8 lib/commands/commands.rb
View
71 lib/commands/commands.rb
@@ -225,7 +225,8 @@
current_origin = git "config remote.origin.url"
- output_json = sh "curl -F 'login=#{github_user}' -F 'token=#{github_token}' https://github.com/api/v2/json/repos/fork/#{user}/#{repo}"
+ url = "https://github.com/api/v2/json/repos/fork/#{user}/#{repo}"
+ output_json = sh "curl -F 'login=#{github_user}' -F 'token=#{github_token}' #{url}"
output = JSON.parse(output_json)
if output["error"]
die output["error"]
@@ -243,6 +244,8 @@
end
end
+# TODO organizations
+
desc "Create a new GitHub repository from the current local repository"
usage "github create-from-local [repo_name]"
flags :private => 'Create private repository'
@@ -255,14 +258,66 @@
end
is_repo = !git("status").match(/fatal/)
raise "Not a git repository. Use 'gh create' instead" unless is_repo
- command = "curl -F 'name=#{repo}' -F 'public=#{options[:private] ? 0 : 1}' -F 'login=#{github_user}' -F 'token=#{github_token}' https://github.com/api/v2/json/repos/create"
- output_json = sh command
- output = JSON.parse(output_json)
- if output["error"]
- die output["error"]
+
+ # trying to force the organization
+ organization = nil
+ if organization
+ url = "https://api.github.com/orgs/#{organization}/repos"
+ repo_owner = organization
else
- git "remote add origin git@github.com:#{github_user}/#{repo}.git"
- git_exec "push origin master"
+ url = "https://api.github.com/user/repos"
+ repo_owner = github_user
+ end
+ p url
+ github_password = 'XXX'
+ command = "curl -F 'name=#{repo}' -F 'private=#{options[:private] ? true : false}' -u '#{github_user}:#{github_password}' #{url}"
+ puts command
+ output_json = sh command
+ puts output_json
+ begin
+ output = JSON.parse(output_json)
+ if output["error"] || output["message"]
+ puts output["message"]
+ p output["errors"] if output["errors"]
+ exit 1
+ else
+ git "remote add origin git@github.com:#{github_user}/#{repo}.git"
+ git_exec "push origin master"
+ end
+ rescue JSON::ParserError
+ die "JSON wasn't returned. My guess is the repo wasn't created."
+ end
+end
+
+desc "Delete this fork, or the entire repo if not a fork (with ask for confirm)"
+usage "github delete"
+flags :confirm => "Force config to challenge"
+command :delete do
+ repo_url = git "config remote.origin.url"
+ upstream = git "config remote.upstream.url"
+ repo_type = upstream == "" ? "main" : "fork"
+ if repo_url == ""
+ die "No 'origin' repo url to delete."
+ end
+ if options[:confirm] || highline.agree("Really delete #{repo_type} repo #{repo_url}? [yN]")
+ # delete the repo
+ user, repo = helper.user_and_repo_from repo_url
+ repo.gsub!(/\.git$/, "")
+ url = "https://github.com/api/v2/json/repos/delete/#{user}/#{repo}"
+ command = "curl -F 'login=#{github_user}' -F 'token=#{github_token}' #{url}"
+ p command
+ output_json = sh command
+ output = JSON.parse(output_json)
+ if output["error"]
+ die output["error"]
+ else
+ p output
+ git "remote rm origin"
+ if repo_type == "fork"
+ puts "Restoring upstream #{upstream} to origin"
+ git "config remote.origin.url #{upstream}"
+ end
+ end
end
end

No commit comments for this range

Something went wrong with that request. Please try again.