Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge pull request just by number #186

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 28 additions & 13 deletions lib/hub/commands.rb
Expand Up @@ -363,28 +363,43 @@ def checkout(args)
end

# $ git merge https://github.com/defunkt/hub/pull/73
# or
# $ git merge PR173
# $ git merge pr173
# $ git merge pull173
# $ git merge pull/173
# > git fetch git://github.com/mislav/hub.git +refs/heads/feature:refs/remotes/mislav/feature
# > git merge mislav/feature --no-ff -m 'Merge pull request #73 from mislav/feature...'
def merge(args)
_, url_arg = args.words
if url = resolve_github_url(url_arg) and url.project_path =~ /^pull\/(\d+)/
pull_id = nil
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all the rest of the diff is only dedent, and remove of the final end.

project_url = nil
if url_arg =~ /(pr|pull)(-|\/)?(\d+)/i
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could also match on number only by adding ? here : /(pr|pull)?(-|\/)?(\d+)/i

pull_id = $3
url = resolve_github_url(local_repo.main_project.web_url)
elsif url = resolve_github_url(url_arg) and url.project_path =~ /^pull\/(\d+)/
pull_id = $1
pull_data = api_client.pullrequest_info(url.project, pull_id)
else
abort "Error : don't understand what #{url_arg} mean"
end

user, branch = pull_data['head']['label'].split(':', 2)
abort "Error: #{user}'s fork is not available anymore" unless pull_data['head']['repo']
project_url = url.project
pull_data = api_client.pullrequest_info(project_url, pull_id)

url = github_project(url.project_name, user).git_url(:private => pull_data['head']['repo']['private'],
:https => https_protocol?)
user, branch = pull_data['head']['label'].split(':', 2)
abort "Error: #{user}'s fork is not available anymore" unless pull_data['head']['repo']

merge_head = "#{user}/#{branch}"
args.before ['fetch', url, "+refs/heads/#{branch}:refs/remotes/#{merge_head}"]
url = github_project(url.project_name, user).git_url(:private => pull_data['head']['repo']['private'],
:https => https_protocol?)

merge_head = "#{user}/#{branch}"
args.before ['fetch', url, "+refs/heads/#{branch}:refs/remotes/#{merge_head}"]

idx = args.index url_arg
args.delete_at idx
args.insert idx, merge_head, '--no-ff', '-m',
"Merge pull request ##{pull_id} from #{merge_head}\n\n#{pull_data['title']}"

idx = args.index url_arg
args.delete_at idx
args.insert idx, merge_head, '--no-ff', '-m',
"Merge pull request ##{pull_id} from #{merge_head}\n\n#{pull_data['title']}"
end
end

# $ git cherry-pick http://github.com/mislav/hub/commit/a319d88#comments
Expand Down