dotemacs

My Emacs configuration
git clone git://git.entf.net/dotemacs
Log | Files | Refs | LICENSE

forge.el (5380B)


      1 ;;; forge.el --- Access Git forges from Magit     -*- lexical-binding: t -*-
      2 
      3 ;; Copyright (C) 2018-2022  Jonas Bernoulli
      4 
      5 ;; Author: Jonas Bernoulli <jonas@bernoul.li>
      6 ;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
      7 ;; Homepage: https://github.com/magit/forge
      8 ;; Keywords: git tools vc
      9 ;; SPDX-License-Identifier: GPL-3.0-or-later
     10 
     11 ;; This file is not part of GNU Emacs.
     12 
     13 ;; Forge is free software; you can redistribute it and/or modify it
     14 ;; under the terms of the GNU General Public License as published by
     15 ;; the Free Software Foundation; either version 3, or (at your option)
     16 ;; any later version.
     17 ;;
     18 ;; Forge is distributed in the hope that it will be useful, but WITHOUT
     19 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
     20 ;; or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
     21 ;; License for more details.
     22 ;;
     23 ;; You should have received a copy of the GNU General Public License
     24 ;; along with Forge.  If not, see http://www.gnu.org/licenses.
     25 
     26 ;;; Commentary:
     27 
     28 ;; Work with Git forges, such as Github and Gitlab, from the comfort
     29 ;; of Magit and the rest of Emacs.
     30 
     31 ;; The schema of the database has not been finalized yet.  Until that
     32 ;; has happened it will occasionally have to be discarded.  For now
     33 ;; the database does not contain any information that cannot simply
     34 ;; be fetched again.
     35 
     36 ;;; Code:
     37 
     38 (require 'magit)
     39 
     40 (require 'forge-db)
     41 (require 'forge-core)
     42 
     43 (provide 'forge)
     44 
     45 (require 'forge-repo)
     46 (require 'forge-post)
     47 (require 'forge-topic)
     48 (require 'forge-issue)
     49 (require 'forge-pullreq)
     50 (require 'forge-revnote)
     51 (require 'forge-notify)
     52 
     53 (require 'forge-github)
     54 (require 'forge-gitlab)
     55 (require 'forge-gitea)
     56 (require 'forge-gogs)
     57 (require 'forge-bitbucket)
     58 (require 'forge-semi)
     59 
     60 (require 'forge-commands)
     61 (require 'forge-list)
     62 
     63 ;;; Add Sections
     64 
     65 (defvar forge-add-default-sections t
     66   "Whether to add Forge's sections to `magit-status-sections-hook'.
     67 If you want to disable this, then you must set this to nil before
     68 `forge' is loaded.")
     69 
     70 (when (and forge-add-default-sections forge--sqlite-available-p)
     71   (magit-add-section-hook 'magit-status-sections-hook 'forge-insert-pullreqs nil t)
     72   (magit-add-section-hook 'magit-status-sections-hook 'forge-insert-issues   nil t))
     73 
     74 ;;; Add Bindings
     75 
     76 ;;;###autoload
     77 (defvar forge-add-default-bindings t
     78   "Whether to add Forge's bindings to various Magit keymaps.
     79 If you want to disable this, then you must set this to nil before
     80 `magit' is loaded.  If you do it before `forge' but after `magit'
     81 is loaded, then `magit-mode-map' ends up being modified anyway.")
     82 
     83 ;;;###autoload
     84 (with-eval-after-load 'magit-mode
     85   (when forge-add-default-bindings
     86     (define-key magit-mode-map "'" 'forge-dispatch)
     87     (define-key magit-mode-map "N" 'forge-dispatch)))
     88 
     89 (when forge-add-default-bindings
     90   (define-key magit-commit-section-map [remap magit-browse-thing] 'forge-browse-dwim)
     91   (define-key magit-remote-section-map [remap magit-browse-thing] 'forge-browse-remote)
     92   (define-key magit-branch-section-map [remap magit-browse-thing] 'forge-browse-branch)
     93 
     94   (define-key magit-commit-section-map (kbd "C-c C-v") 'forge-visit-topic)
     95   (define-key magit-branch-section-map (kbd "C-c C-v") 'forge-visit-topic)
     96 
     97   (transient-insert-suffix 'magit-dispatch "o"
     98     '("N" "Forge" forge-dispatch))
     99 
    100   (transient-append-suffix 'magit-fetch "m"
    101     '("n" "forge topics" forge-pull))
    102   (transient-append-suffix 'magit-fetch "n"
    103     '("N" "forge notifications" forge-pull-notifications))
    104 
    105   (transient-append-suffix 'magit-pull "m"
    106     '("n" "forge topics" forge-pull))
    107   (transient-append-suffix 'magit-pull "n"
    108     '("N" "forge notifications" forge-pull-notifications))
    109 
    110   (transient-append-suffix 'magit-branch "w"
    111     '("f" "pull-request" forge-checkout-pullreq))
    112   (transient-append-suffix 'magit-branch "W"
    113     '("F" "from pull-request" forge-branch-pullreq))
    114 
    115   (transient-append-suffix 'magit-worktree "c"
    116     '("n" "pull-request worktree" forge-checkout-worktree))
    117 
    118   (transient-append-suffix 'magit-status-jump "w"
    119     '("Np" "Pull requests" forge-jump-to-pullreqs))
    120   (transient-append-suffix 'magit-status-jump "Np"
    121     '("Ni" "Issues" forge-jump-to-issues))
    122 
    123   (transient-append-suffix 'magit-merge "a"
    124     '(7 "M" "Merge using API" forge-merge)))
    125 
    126 ;;; Startup Asserts
    127 
    128 (defconst forge--minimal-git "2.7.0")
    129 
    130 (defun forge-startup-asserts ()
    131   (let ((version (magit-git-version)))
    132     (when (and version
    133                (version< version forge--minimal-git)
    134                (not (equal (getenv "TRAVIS") "true")))
    135       (display-warning 'magit (format "\
    136 Forge requires Git >= %s, you are using %s.
    137 
    138 If this comes as a surprise to you, because you do actually have
    139 a newer version installed, then that probably means that the
    140 older version happens to appear earlier on the `$PATH'.  If you
    141 always start Emacs from a shell, then that can be fixed in the
    142 shell's init file.  If you start Emacs by clicking on an icon,
    143 or using some sort of application launcher, then you probably
    144 have to adjust the environment as seen by graphical interface.
    145 For X11 something like ~/.xinitrc should work.
    146 
    147 If you use Tramp to work inside remote Git repositories, then you
    148 have to make sure a suitable Git is used on the remote machines
    149 too.\n" forge--minimal-git version) :error))))
    150 
    151 (if after-init-time
    152     (forge-startup-asserts)
    153   (add-hook 'after-init-hook #'forge-startup-asserts t))
    154 
    155 ;;; forge.el ends here