consult-gh-transient.el (7475B)
1 ;;; consult-gh-transient.el --- Emabrk Actions for consult-gh -*- lexical-binding: t -*- 2 3 ;; Copyright (C) 2021-2023 Free Software Foundation, Inc. 4 5 ;; Author: Armin Darvish 6 ;; Maintainer: Armin Darvish 7 ;; Created: 2023 8 ;; Version: 1.0.0 9 ;; Package-Requires: ((emacs "27.1") (consult "0.34")) 10 ;; Homepage: https://github.com/armindarvish/consult-gh 11 ;; Keywords: matching, git, repositories, forges, completion 12 13 ;;; Commentary: 14 15 ;;; Code: 16 17 ;; Requirements 18 (require 'transient) 19 20 ;; Prefixes 21 (transient-define-prefix consult-gh () 22 "Main transient menu for consult-gh" 23 [:description 24 (lambda () 25 (let ((username (consult-gh--get-current-username)) 26 (repo (consult-gh--get-repo-from-directory))) 27 (concat 28 (propertize "*CONSULT-GH* \n" 'face 'transient-heading) 29 (if username (concat (propertize "user: " 'face 'consult-gh-date-face) (propertize username 'face 'consult-gh-user-face) "\t")) 30 (if repo (concat (propertize "current repo: " 'face 'consult-gh-date-face) (propertize repo 'face 'consult-gh-user-face) "\t")) 31 ))) 32 ""] 33 34 [:description "--Actions--" 35 ["Search" 36 (consult-gh-transient--suffix-search-issues) 37 (consult-gh-transient--suffix-search-repos) 38 (consult-gh-transient--suffix-search-prs) 39 (consult-gh-transient--suffix-search-code) 40 ] 41 42 ["Repos" 43 (consult-gh-transient--suffix-repo-list) 44 (consult-gh-transient--suffix-repo-clone) 45 (consult-gh-transient--suffix-repo-fork) 46 ] 47 48 ["Issues" 49 (consult-gh-transient--suffix-issue-list) 50 ] 51 52 ["Pull Requests" 53 (consult-gh-transient--suffix-pr-list) 54 ] 55 ] 56 57 [:description 58 "--Settings--" 59 ["Limits" 60 (consult-gh-transient--infix-repo-maxnum) 61 (consult-gh-transient--infix-issue-maxnum) 62 (consult-gh-transient--infix-pr-maxnum) 63 (consult-gh-transient--infix-code-maxnum)] 64 65 ["States" 66 (consult-gh-transient--infix-issue-state) 67 (consult-gh-transient--infix-prs-state) 68 ]]) 69 70 71 (defun consult-gh--transient-read-variable (prompt initial-input history) 72 "Read value from minibuffer for `consult-gh' transient menu." 73 (read-from-minibuffer prompt initial-input read-expression-map t history)) 74 75 76 ;; Prefixes 77 (transient-define-prefix consult-gh--transient-repos () 78 "Repo section for `consult-gh' transient menu." 79 [:description "Repos"] 80 [["Actions" 81 (consult-gh-transient--suffix-search-repos) 82 (consult-gh-transient--suffix-repo-list) 83 ] 84 ["Parameters" 85 (consult-gh-transient--infix-repo-maxnum) 86 ] 87 ] 88 ) 89 90 (transient-define-prefix consult-gh--transient-issues () 91 "Issue section for `consult-gh' transient menu." 92 [:description "Issues"] 93 [["Actions" 94 (consult-gh-transient--suffix-search-issues) 95 (consult-gh-transient--suffix-issue-list) 96 ] 97 ["Parameters" 98 (consult-gh-transient--infix-issue-maxnum) 99 ] 100 ]) 101 102 ;; Infixes 103 (transient-define-infix consult-gh-transient--infix-repo-maxnum () 104 "Set `consult-gh-repo-maxnum' in `consult-gh' transient menu." 105 :description "Max Number of Repos: " 106 :class 'transient-lisp-variable 107 :variable 'consult-gh-repo-maxnum 108 :key "r -L" 109 :reader 'consult-gh--transient-read-variable) 110 111 (transient-define-infix consult-gh-transient--infix-issue-maxnum () 112 "Set `consult-gh-issue-maxnum' in `consult-gh' transient menu." 113 :description "Max Number of Issues: " 114 :class 'transient-lisp-variable 115 :variable 'consult-gh-issue-maxnum 116 :key "i -L" 117 :reader 'consult-gh--transient-read-variable) 118 119 (transient-define-infix consult-gh-transient--infix-pr-maxnum () 120 "Set `consult-gh-pr-maxnum' in `consult-gh' transient menu." 121 :description "Max Number of PRs: " 122 :class 'transient-lisp-variable 123 :variable 'consult-gh-pr-maxnum 124 :key "p -L" 125 :reader 'consult-gh--transient-read-variable) 126 127 (transient-define-infix consult-gh-transient--infix-code-maxnum () 128 "Set `consult-gh-code-maxnum' in `consult-gh' transient menu." 129 :description "Max Number of Codes: " 130 :class 'transient-lisp-variable 131 :variable 'consult-gh-code-maxnum 132 :key "c -L" 133 :reader 'consult-gh--transient-read-variable) 134 135 (transient-define-infix consult-gh-transient--infix-issue-state () 136 "Set `consult-gh-issues-state-to-show' in `consult-gh' transient menu." 137 :description "State of Issues to Show " 138 :class 'transient-lisp-variable 139 :variable 'consult-gh-issues-state-to-show 140 :key "i -s" 141 :choices '("all" "open" "closed") 142 :reader (lambda (prompt &rest _) 143 (completing-read 144 prompt 145 '("all" "open" "closed")))) 146 147 148 (transient-define-infix consult-gh-transient--infix-prs-state () 149 "Set `consult-gh-prs-state-to-show' in `consult-gh' transient menu." 150 :description "State of PRs to Show: " 151 :class 'transient-lisp-variable 152 :variable 'consult-gh-prs-state-to-show 153 :key "p -s" 154 :choices '("all" "open" "closed" "merged") 155 :reader (lambda (prompt &rest _) 156 (completing-read 157 prompt 158 '("all" "open" "closed" "merged")))) 159 160 ;; Suffixes 161 162 (transient-define-suffix consult-gh-transient--suffix-repo-clone () 163 "Call `consult-gh-repo-clone' in `consult-gh' transient menu." 164 :transient nil 165 :description "clone a repo" 166 :key "r c" 167 (interactive) 168 (consult-gh-repo-clone)) 169 170 (transient-define-suffix consult-gh-transient--suffix-repo-fork () 171 "Call `consult-gh-repo-fork' in `consult-gh' transient menu." 172 :transient nil 173 :description "fork a repo" 174 :key "r f" 175 (interactive) 176 (consult-gh-repo-fork)) 177 178 (transient-define-suffix consult-gh-transient--suffix-repo-list () 179 "Call `consult-gh-repo-list' in `consult-gh' transient menu." 180 :transient nil 181 :description "list repos of a user" 182 :key "r l" 183 (interactive) 184 (consult-gh-repo-list)) 185 186 (transient-define-suffix consult-gh-transient--suffix-issue-list () 187 "Call `consult-gh-issue-list' in `consult-gh' transient menu." 188 :transient nil 189 :description "list issues of a repo" 190 :key "i l" 191 (interactive) 192 (consult-gh-issue-list)) 193 194 (transient-define-suffix consult-gh-transient--suffix-pr-list () 195 "Call `consult-gh-pr-list' in `consult-gh' transient menu." 196 :transient nil 197 :description "list prs of a repo" 198 :key "p l" 199 (interactive) 200 (consult-gh-pr-list)) 201 202 (transient-define-suffix consult-gh-transient--suffix-search-repos () 203 "Call `consult-gh-search-repos' in `consult-gh' transient menu." 204 :transient nil 205 :description "search repos" 206 :key "s r" 207 (interactive) 208 (consult-gh-search-repos)) 209 210 (transient-define-suffix consult-gh-transient--suffix-search-issues () 211 "Call `consult-gh-search-issues' in `consult-gh' transient menu." 212 :transient nil 213 :description "search issues" 214 :key "s i" 215 (interactive) 216 (consult-gh-search-issues)) 217 218 (transient-define-suffix consult-gh-transient--suffix-search-prs () 219 "Call `consult-gh-search-prs' in `consult-gh' transient menu." 220 :transient nil 221 :description "search pull requests" 222 :key "s p" 223 (interactive) 224 (consult-gh-search-prs)) 225 226 (transient-define-suffix consult-gh-transient--suffix-search-code () 227 "Call `consult-gh-search-code' in `consult-gh' transient menu." 228 :transient nil 229 :description "search code" 230 :key "s c" 231 (interactive) 232 (consult-gh-search-code)) 233 234 ;;; Provide `consul-gh-transient' module 235 236 (provide 'consult-gh-transient) 237 238 ;;; consult-gh-transient.el ends here