Skip to content

Commit

Permalink
forge-merge: New command
Browse files Browse the repository at this point in the history
  • Loading branch information
tarsius committed Jun 19, 2021
1 parent ddb4357 commit 3112ade
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lisp/forge-commands.el
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,36 @@ This may take a while. Only Github is supported at the moment."
(read-string "Organization: ")))
(forge--add-organization-repos 'forge-github-repository host organization))

;;;###autoload
(defun forge-merge (n method)
"Merge the current pull-request using METHOD using the forge's API.
If there is no current pull-request or with a prefix argument,
then read pull-request N to visit instead.
Use of this command is discouraged. Unless the remote repository

This comment has been minimized.

Copy link
@nickanderson

nickanderson May 12, 2022

Is there some reference as to why use of this command is discouraged?

This comment has been minimized.

Copy link
@tarsius

tarsius May 12, 2022

Author Member

Github does not offer "fast-forward merge". You could try to fake it using a "rebase merge", but unlike git rebase that also does not fast-forward when that would be possible. The effect is that a "Github merge" is not actually a merge. I.e., the commits in a pull-request do not become reachable from the branch into which they are being merged.

Github is a bad "Git client". Don't do any Git work using Github.

This comment has been minimized.

Copy link
@tarsius

tarsius May 12, 2022

Author Member

It does all kinds of stupid (such as not ending commit messages with a newline as the are supposed to, which I reported numerous times over the years and any self respecting foss developer would fix in a few days) and insulting (it changes the committer email to something containing github.com) things.

is configured to disallow that, you should instead merge locally
and then push the target branch. Forges detect that you have
done that and respond by automatically marking the pull-request
as merged."
(interactive
(list (forge-read-pullreq "Merge pull-request" t)
(if (forge--childp (forge-get-repository t) 'forge-gitlab-repository)
(magit-read-char-case "Merge method " t
(?m "[m]erge" 'merge)
(?s "[s]quash" 'squash))
(magit-read-char-case "Merge method " t
(?m "[m]erge" 'merge)
(?s "[s]quash" 'squash)
(?r "[r]ebase" 'rebase)))))
(forge--merge-pullreq (forge-get-repository t)
(forge-get-pullreq n)
(magit-rev-hash
(forge--pullreq-branch-internal
(forge-get-pullreq n)))
method)
(forge-pull))

;;;###autoload
(defun forge-remove-repository (host owner name)
"Remove a repository from the database."
Expand Down
7 changes: 7 additions & 0 deletions lisp/forge-github.el
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,13 @@
`((organization . ,fork))))
(ghub-wait (format "/repos/%s/%s" fork name) nil :auth 'forge)))

(cl-defmethod forge--merge-pullreq ((_repo forge-github-repository)
topic hash method)
(forge--ghub-put topic
"/repos/:owner/:repo/pulls/:number/merge"
`((merge_method . ,(symbol-name method))
,@(and hash `((sha . ,hash))))))

;;; Utilities

(cl-defun forge--ghub-get (obj resource
Expand Down
7 changes: 7 additions & 0 deletions lisp/forge-gitlab.el
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,13 @@
(ghub-wait (format "/projects/%s%%2F%s" fork name)
nil :auth 'forge :forge 'gitlab)))

(cl-defmethod forge--merge-pullreq ((_repo forge-gitlab-repository)
topic hash method)
(forge--glab-put topic
"/projects/:project/merge_requests/:number/merge"
`((squash . ,(if (eq method 'squash) "true" "false"))
,@(and hash `((sha . ,hash))))))

;;; Utilities

(cl-defmethod forge--topic-type-prefix ((_repo forge-gitlab-repository) type)
Expand Down
3 changes: 3 additions & 0 deletions lisp/forge.el
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@
(transient-append-suffix 'magit-status-jump "'p"
'("'i" "issues" forge-jump-to-issues))

(transient-append-suffix 'magit-merge "a"
'(7 "f" "Merge using API" forge-merge))

;;; Startup Asserts

(defconst forge--minimal-git "2.7.0")
Expand Down

0 comments on commit 3112ade

Please sign in to comment.