-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathconsult-gh-transient.el
261 lines (219 loc) · 8.63 KB
/
consult-gh-transient.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
;;; consult-gh-transient.el --- Emabrk Actions for consult-gh -*- lexical-binding: t -*-
;; Copyright (C) 2023 Armin Darvish
;; Author: Armin Darvish
;; Maintainer: Armin Darvish
;; Created: 2023
;; Version: 2.0
;; Homepage: https://github.com/armindarvish/consult-gh
;; Keywords: matching, git, repositories, forges, completion
;; SPDX-License-Identifier: GPL-3.0-or-later
;; This file is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published
;; by the Free Software Foundation, either version 3 of the License,
;; or (at your option) any later version.
;;
;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this file. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; This package providesa transient menu for consult-gh.
;; (see URL `https://github.com/armindarvish/consult-gh' for more info).
;;; Code:
;; Requirements
(require 'consult-gh)
(require 'transient)
;; Prefixes
(transient-define-prefix consult-gh-transient ()
"Main transient menu for `consult-gh'."
[:description
(lambda ()
(let ((username (consult-gh--get-current-username))
(repo (consult-gh--get-repo-from-directory)))
(concat
(propertize "*consult-gh: Consulting GitHub Client* \n" 'face 'transient-heading)
(if username (concat (propertize "Current User: " 'face 'consult-gh-date-face) (propertize username 'face 'consult-gh-user-face) "\n"))
(if repo (concat (propertize "Current Repo: " 'face 'consult-gh-date-face) (propertize repo 'face 'consult-gh-user-face) "\n")))))
""]
[:description "--Quick Access--"
(consult-gh-transient--suffix-switch-account)
(consult-gh-transient--suffix-dashboard)
(consult-gh-transient--suffix-notifications)]
[:description "--Actions--"
["Search"
(consult-gh-transient--suffix-search-issues)
(consult-gh-transient--suffix-search-repos)
(consult-gh-transient--suffix-search-prs)
(consult-gh-transient--suffix-search-code)]
["Repos"
(consult-gh-transient--suffix-repo-list)
(consult-gh-transient--suffix-repo-create)
(consult-gh-transient--suffix-repo-clone)
(consult-gh-transient--suffix-repo-fork)]
["Issues"
(consult-gh-transient--suffix-issue-list)]
["Pull Requests"
(consult-gh-transient--suffix-pr-list)]]
[:description
"--Settings--"
["Limits"
(consult-gh-transient--infix-repo-maxnum)
(consult-gh-transient--infix-issue-maxnum)
(consult-gh-transient--infix-pr-maxnum)
(consult-gh-transient--infix-code-maxnum)]
["States"
(consult-gh-transient--infix-issue-state)
(consult-gh-transient--infix-prs-state)]])
(defun consult-gh-transient-read-variable (prompt initial-input history)
"Read value from minibuffer for `consult-gh' transient menu.
PROMPT, INITIAL-INPUT, and HISTORY are passed to `read-from-minibffer'."
(read-from-minibuffer prompt initial-input read-expression-map t history))
;; Infixes
(transient-define-infix consult-gh-transient--infix-repo-maxnum ()
"Set `consult-gh-repo-maxnum' in `consult-gh' transient menu."
:description "Max Number of Repos: "
:class 'transient-lisp-variable
:variable 'consult-gh-repo-maxnum
:key "r -L"
:reader 'consult-gh-transient-read-variable)
(transient-define-infix consult-gh-transient--infix-issue-maxnum ()
"Set `consult-gh-issue-maxnum' in `consult-gh' transient menu."
:description "Max Number of Issues: "
:class 'transient-lisp-variable
:variable 'consult-gh-issue-maxnum
:key "i -L"
:reader 'consult-gh-transient-read-variable)
(transient-define-infix consult-gh-transient--infix-pr-maxnum ()
"Set `consult-gh-pr-maxnum' in `consult-gh' transient menu."
:description "Max Number of PRs: "
:class 'transient-lisp-variable
:variable 'consult-gh-pr-maxnum
:key "p -L"
:reader 'consult-gh-transient-read-variable)
(transient-define-infix consult-gh-transient--infix-code-maxnum ()
"Set `consult-gh-code-maxnum' in `consult-gh' transient menu."
:description "Max Number of Codes: "
:class 'transient-lisp-variable
:variable 'consult-gh-code-maxnum
:key "c -L"
:reader 'consult-gh-transient-read-variable)
(transient-define-infix consult-gh-transient--infix-issue-state ()
"Set `consult-gh-issues-state-to-show' in `consult-gh' transient menu."
:description "State of Issues to Show "
:class 'transient-lisp-variable
:variable 'consult-gh-issues-state-to-show
:key "i -s"
:choices '("all" "open" "closed")
:reader (lambda (prompt &rest _)
(completing-read
prompt
'("all" "open" "closed"))))
(transient-define-infix consult-gh-transient--infix-prs-state ()
"Set `consult-gh-prs-state-to-show' in `consult-gh' transient menu."
:description "State of PRs to Show: "
:class 'transient-lisp-variable
:variable 'consult-gh-prs-state-to-show
:key "p -s"
:choices '("all" "open" "closed" "merged")
:reader (lambda (prompt &rest _)
(completing-read
prompt
'("all" "open" "closed" "merged"))))
;; Suffixes
(transient-define-suffix consult-gh-transient--suffix-switch-account ()
"Call `consult-gh-dashbaord' in `consult-gh' transient menu."
:transient nil
:description "Switch Account"
:key "a"
(interactive)
(consult-gh-auth-switch))
(transient-define-suffix consult-gh-transient--suffix-dashboard ()
"Call `consult-gh-dashbaord' in `consult-gh' transient menu."
:transient nil
:description "User's Dashbaord"
:key "d"
(interactive)
(consult-gh-dashboard))
(transient-define-suffix consult-gh-transient--suffix-notifications ()
"Call `consult-gh-notifications' in `consult-gh' transient menu."
:transient nil
:description "User's Notifications"
:key "n"
(interactive)
(consult-gh-notifications))
(transient-define-suffix consult-gh-transient--suffix-repo-create ()
"Call `consult-gh-repo-list' in `consult-gh' transient menu."
:transient nil
:description "Create a New Repo"
:key "r n"
(interactive)
(consult-gh-repo-create))
(transient-define-suffix consult-gh-transient--suffix-repo-list ()
"Call `consult-gh-repo-list' in `consult-gh' transient menu."
:transient nil
:description "List Repos of a User"
:key "r l"
(interactive)
(consult-gh-repo-list))
(transient-define-suffix consult-gh-transient--suffix-repo-clone ()
"Call `consult-gh-repo-clone' in `consult-gh' transient menu."
:transient nil
:description "Clone a Repo"
:key "r c"
(interactive)
(consult-gh-repo-clone))
(transient-define-suffix consult-gh-transient--suffix-repo-fork ()
"Call `consult-gh-repo-fork' in `consult-gh' transient menu."
:transient nil
:description "Fork a Repo"
:key "r f"
(interactive)
(consult-gh-repo-fork))
(transient-define-suffix consult-gh-transient--suffix-issue-list ()
"Call `consult-gh-issue-list' in `consult-gh' transient menu."
:transient nil
:description "List Issues of a Repo"
:key "i l"
(interactive)
(consult-gh-issue-list))
(transient-define-suffix consult-gh-transient--suffix-pr-list ()
"Call `consult-gh-pr-list' in `consult-gh' transient menu."
:transient nil
:description "List PRs of a Repo"
:key "p l"
(interactive)
(consult-gh-pr-list))
(transient-define-suffix consult-gh-transient--suffix-search-repos ()
"Call `consult-gh-search-repos' in `consult-gh' transient menu."
:transient nil
:description "Search Repos"
:key "s r"
(interactive)
(consult-gh-search-repos))
(transient-define-suffix consult-gh-transient--suffix-search-issues ()
"Call `consult-gh-search-issues' in `consult-gh' transient menu."
:transient nil
:description "Search Issues"
:key "s i"
(interactive)
(consult-gh-search-issues))
(transient-define-suffix consult-gh-transient--suffix-search-prs ()
"Call `consult-gh-search-prs' in `consult-gh' transient menu."
:transient nil
:description "Search Pull Requests"
:key "s p"
(interactive)
(consult-gh-search-prs))
(transient-define-suffix consult-gh-transient--suffix-search-code ()
"Call `consult-gh-search-code' in `consult-gh' transient menu."
:transient nil
:description "Search Code"
:key "s c"
(interactive)
(consult-gh-search-code))
;;; Provide `consul-gh-transient' module
(provide 'consult-gh-transient)
;;; consult-gh-transient.el ends here