Making sure that github/gitlab works with forge

To use this correctly, create entries in ~/.authinfo.gpg that contains
the API passwords from Github and Gitlab:

    machine api.github.com login howardabrams^forge password redacted
    machine gitlab.com/api/v4 login howardabrams^forge password redacted

Also, this change prompts us for comfirmation before pushing to the
main upstream branch (since you should want to use a pull request).
This commit is contained in:
Howard Abrams 2021-12-27 10:15:07 -08:00
parent 4ed8572a77
commit 414b56eb5f

View file

@ -1046,10 +1046,35 @@ Can not live without [[https://magit.vc/][Magit]], a Git porcelain for Emacs. I
"g c b" '("Branch" . magit-branch-and-checkout)))
#+END_SRC
The [[https://github.com/emacsmirror/git-timemachine][git-timemachine]] project is cool:
#+BEGIN_SRC emacs-lisp
(use-package git-timemachine
:config
(ha-leader "g t" '("git timemachine" . git-timemachine)))
#+END_SRC
*** Gist
Using the [[https://github.com/emacsmirror/gist][gist package]] to write code snippets on [[https://gist.github.com/][Github]] seems like it can be useful, but I'm not sure how often.
#+BEGIN_SRC emacs-lisp
(use-package gist
:config
(ha-leader
"g G" '(:ignore t :which-key "gists")
"g l g" '("gists" . gist-list)
"g G l" '("list" . gist-list) ; Lists your gists in a new buffer.
"g G r" '("region" . gist-region) ; Copies Gist URL into the kill ring.
"g G R" '("private region" . gist-region-private) ; Explicitly create a private gist.
"g G b" '("buffer" . gist-buffer) ; Copies Gist URL into the kill ring.
"g G B" '("private buffer" . gist-buffer-private) ; Explicitly create a private gist.
"g c g" '("gist" . gist-region-or-buffer) ; Post either the current region, or buffer
"g c G" '("private gist" . gist-region-or-buffer-private))) ; create private gist from region or buffer
#+END_SRC
*** Forge
Let's extend Magit with [[https://github.com/magit/forge][Magit Forge]] for working with Github and Gitlab:
#+BEGIN_SRC emacs-lisp
(use-package forge
:after magit
:init
(setq )
:config
(ha-leader
"g '" '("Forge dispatch" . forge-dispatch)
@ -1071,27 +1096,34 @@ Let's extend Magit with [[https://github.com/magit/forge][Magit Forge]] for work
"g c p" '("Pull request" . forge-create-pullreq)))
#+END_SRC
The [[https://github.com/emacsmirror/git-timemachine][git-timemachine]] project is cool:
#+BEGIN_SRC emacs-lisp
(use-package git-timemachine
:config
(ha-leader "g t" '("git timemachine" . git-timemachine)))
#+END_SRC
Every /so often/, pop over to the following URLs and generate a new
token where the *Note* is =forge=, and then copy that into the
[[file:~/.authinfo.gpg][~/.authinfo.gpg]]:
- [[https://gitlab.com/-/profile/personal_access_tokens][Gitlab]]
- [[https://github.com/settings/tokens][Github]]
and make sure this works:
Using the [[https://github.com/emacsmirror/gist][gist package]] to write code snippets on [[https://gist.github.com/][Github]] seems like it can be useful, but I'm not sure how often.
#+BEGIN_SRC emacs-lisp
(use-package gist
:config
(ha-leader
"g G" '(:ignore t :which-key "gists")
"g l g" '("gists" . gist-list)
"g G l" '("list" . gist-list) ; Lists your gists in a new buffer.
"g G r" '("region" . gist-region) ; Copies Gist URL into the kill ring.
"g G R" '("private region" . gist-region-private) ; Explicitly create a private gist.
"g G b" '("buffer" . gist-buffer) ; Copies Gist URL into the kill ring.
"g G B" '("private buffer" . gist-buffer-private) ; Explicitly create a private gist.
"g c g" '("gist" . gist-region-or-buffer) ; Post either the current region, or buffer
"g c G" '("private gist" . gist-region-or-buffer-private))) ; create private gist from region or buffer
(ghub-request "GET" "/user" nil
:forge 'github
:host "api.github.com"
:username "howardabrams"
:auth 'forge)
#+END_SRC
*** Pushing is Bad
Pushing directly to the upstream branch is /bad form/, as one should create a pull request, etc. To prevent an accidental push, we /double-check/ first:
#+BEGIN_SRC emacs-lisp
(define-advice magit-push-current-to-upstream (:before (args) query-yes-or-no)
"Prompt for confirmation before permitting a push to upstream."
(when-let ((branch (magit-get-current-branch)))
(unless (yes-or-no-p (format "Push %s branch upstream to %s? "
branch
(or (magit-get-upstream-branch branch)
(magit-get "branch" branch "remote"))))
(user-error "Push to upstream aborted by user"))))
#+END_SRC
** Web Browsing
*** EWW