-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathconsult-gh-embark.el
668 lines (581 loc) · 27.5 KB
/
consult-gh-embark.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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
;;; consult-gh-embark.el --- Embark Actions for consult-gh -*- lexical-binding: t -*-
;; Copyright (C) 2023 Armin Darvish
;; Author: Armin Darvish
;; Maintainer: Armin Darvish
;; Created: 2023
;; Version: 2.0
;; Package-Requires: ((emacs "30.0") (consult-gh "2.0") (embark-consult "1.1"))
;; 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 provides embark actions for consult-gh.
;; (see URL `https://github.com/armindarvish/consult-gh' for more info).
;;; Code:
;;; Requirements
(require 'consult-gh)
(require 'embark-consult)
;;; Define Embark Action Functions
(defun consult-gh-embark-add-repo-to-known-repos (cand)
"Add CAND repo to `consult-gh--known-repos-list'."
(when (stringp cand)
(let* ((repo (get-text-property 0 :repo cand)))
(add-to-list 'consult-gh--known-repos-list repo))))
(defun consult-gh-embark-remove-repo-from-known-repos (cand)
"Remove CAND repo from `consult-gh--known-repos-list'."
(when (stringp cand)
(let* ((repo (get-text-property 0 :repo cand)))
(setq consult-gh--known-repos-list (delete repo consult-gh--known-repos-list)))))
(defun consult-gh-embark-add-org-to-known-orgs (cand)
"Add CAND org to `consult-gh--known-orgs-list'."
(when (stringp cand)
(let* ((org (get-text-property 0 :user cand)))
(add-to-list 'consult-gh--known-orgs-list (format "%s" org)))))
(defun consult-gh-embark-remove-org-from-known-orgs (cand)
"Remove CAND org from `consult-gh--known-orgs-list'."
(when (stringp cand)
(let* ((org (get-text-property 0 :user cand)))
(setq consult-gh--known-orgs-list (delete org consult-gh--known-orgs-list)))))
(defun consult-gh-embark-add-org-to-favorite-list (cand)
"Add CAND org to `consult-gh--known-orgs-list'."
(when (stringp cand)
(let* ((org (get-text-property 0 :user cand)))
(add-to-list 'consult-gh-favorite-orgs-list (format "%s" org)))))
(define-obsolete-function-alias 'consult-gh-embark-add-org-to-default-list #'consult-gh-embark-add-org-to-favorite-list "2.0")
(defun consult-gh-embark-remove-org-from-favorite-list (cand)
"Remove CAND org from `consult-gh--known-orgs-list'."
(when (stringp cand)
(let* ((org (get-text-property 0 :user cand)))
(setq consult-gh-favorite-orgs-list (delete org consult-gh-favorite-orgs-list)))))
(define-obsolete-function-alias 'consult-gh-embark-remove-org-from-default-list #'consult-gh-embark-remove-org-from-favorite-list "2.0")
(defun consult-gh-embark-default-action (cand)
"Open CAND link in an Emacs buffer."
(when (stringp cand)
(let* ((class (get-text-property 0 :class cand)))
(consult-gh-with-host
(consult-gh--auth-account-host)
(pcase class
("code"
(funcall consult-gh-code-action cand))
("issue"
(funcall consult-gh-issue-action cand))
("pr"
(funcall consult-gh-pr-action cand))
("file"
(funcall consult-gh-file-action cand))
("notification"
(funcall consult-gh-notifications-action cand))
("dashboard"
(funcall consult-gh-dashboard-action cand))
(_
(funcall consult-gh-repo-action cand)))))))
(defun consult-gh-embark-show-preview (cand)
"Open preview of CAND."
(when (stringp cand)
(let* ((class (get-text-property 0 :class cand)))
(consult-gh-with-host
(consult-gh--auth-account-host)
(pcase class
("code"
(funcall (consult-gh--code-state) 'preview cand))
("issue"
(funcall (consult-gh--issue-state) 'preview cand))
("pr"
(funcall (consult-gh--pr-state) 'preview cand))
("file"
(funcall (consult-gh--file-state) 'preview cand))
("notification"
(funcall (consult-gh--notifications-state) 'preview cand))
("dashboard"
(funcall (consult-gh--dashboard-state) 'preview cand))
(_
(funcall (consult-gh--repo-state) 'preview cand)))))))
(defun consult-gh-embark-get-title (cand)
"Get the title of CAND.
When `current-prefix-args' is non-nil, add repository's name at the front."
(when (stringp cand)
(let* ((class (get-text-property 0 :class cand))
(repo (get-text-property 0 :repo cand))
(title (get-text-property 0 :title cand))
(number (get-text-property 0 :number cand))
(path (get-text-property 0 :path cand))
(title (pcase class
((or "file" "code")
(if current-prefix-arg
(format "%s/%s" repo path)
(format "%s" path)))
((or "issue" "pr")
(if current-prefix-arg
(format "%s/#%s: %s" repo number title)
(concat "#" (format "%s: %s" number title))))
(_ (format "%s" repo)))))
(string-trim title))))
(defun consult-gh-embark-insert-title (cand)
"Insert the title of CAND at point."
(when (stringp cand)
(if-let* ((title (consult-gh-embark-get-title cand)))
(embark-insert (list (string-trim title))))))
(defun consult-gh-embark-copy-title-as-kill (cand)
"Copy the title of CAND to `kill-ring'."
(when (stringp cand)
(if-let* ((title (consult-gh-embark-get-title cand)))
(kill-new (string-trim title)))))
(defun consult-gh-embark-get-url-link (cand)
"Get url link of CAND.
The candidate can be a repo, issue, PR, file path, or a branch."
(when (stringp cand)
(consult-gh-with-host
(consult-gh--auth-account-host)
(let* ((repo (get-text-property 0 :repo cand))
(class (or (get-text-property 0 :class cand) nil))
(number (or (get-text-property 0 :number cand) nil))
(path (or (get-text-property 0 :path cand) nil))
(branch (or (get-text-property 0 :branch cand) nil)))
(pcase class
("issue"
(string-trim (concat (string-trim (consult-gh--command-to-string "browse" "--repo" (string-trim repo) "--no-browser")) (format "/issues/%s" number))))
((or "file" "code")
(string-trim (concat (string-trim (consult-gh--command-to-string "browse" "--repo" (string-trim repo) "--no-browser")) (format "/blob/%s/%s" (or branch "HEAD") path))))
("pr"
(string-trim (concat (string-trim (consult-gh--command-to-string "browse" "--repo" (string-trim repo) "--no-browser")) (format "/pull/%s" number))))
(_
(string-trim (string-trim (consult-gh--command-to-string "browse" "--repo" (string-trim repo) "--no-browser")))))))))
(defun consult-gh-embark-open-in-system-browser (cand)
"Open the url link of CAND in the system's default browser."
(when (stringp cand)
(let* ((repo (get-text-property 0 :repo cand))
(class (or (get-text-property 0 :class cand) nil))
(number (or (get-text-property 0 :number cand) nil))
(path (or (get-text-property 0 :path cand) nil)))
(consult-gh-with-host
(consult-gh--auth-account-host)
(pcase class
("issue"
(consult-gh--call-process "issue" "view" "--web" "--repo" (substring-no-properties repo) (substring-no-properties number)))
("file"
(funcall (or consult-gh-browse-url-func #'browse-url) (concat (string-trim (consult-gh--command-to-string "browse" "--repo" repo "--no-browser")) "/blob/HEAD/" path)))
("pr"
(consult-gh--call-process "pr" "view" "--web" "--repo" (substring-no-properties repo) (substring-no-properties number)))
(_
(consult-gh--call-process "repo" "view" "--web" (substring repo))))))))
(defun consult-gh-embark-open-in-default-browser (cand)
"Open the url link of CAND with `consult-gh-browse-url-func'."
(when (stringp cand)
(let* ((url (consult-gh-embark-get-url-link cand)))
(funcall consult-gh-browse-url-func url))))
(defun consult-gh-embark-copy-url-link-as-kill (cand)
"Copy url link of CAND to `kill-ring'.
CAND can be a repo, issue, PR, file path, ..."
(when (stringp cand)
(let* ((link (consult-gh-embark-get-url-link cand)))
(kill-new link))))
(defun consult-gh-embark-copy-url-org-link-as-kill (cand)
"Copy the org-format url link of CAND to `kill-ring'."
(when (stringp cand)
(let* ((class (get-text-property 0 :class cand))
(repo (get-text-property 0 :repo cand))
(url (consult-gh-embark-get-url-link cand))
(title (consult-gh-embark-get-title cand))
(path (or (get-text-property 0 :path cand) nil))
(branch (or (get-text-property 0 :branch cand) nil))
(str nil))
(pcase class
((or "issue" "pr")
(when (not current-prefix-arg) (setq title (concat repo "/" title))))
((or "file" "code")
(when (not current-prefix-arg) (setq title (concat repo "/" branch "/" path)))))
(when url
(setq str
(cond
((and url title) (format " [[%s][%s]] " url title))
(url (format " [[%s]] " url))
(t nil))))
(when (stringp str)
(kill-new str)))))
(defun consult-gh-embark-insert-url-link (cand)
"Insert the url of CAND at point."
(when (stringp cand)
(let* ((class (get-text-property 0 :class cand))
(repo (get-text-property 0 :repo cand))
(url (consult-gh-embark-get-url-link cand))
(title (consult-gh-embark-get-title cand))
(path (or (get-text-property 0 :path cand) nil))
(branch (or (get-text-property 0 :branch cand) nil)))
(pcase class
((or "issue" "pr")
(when (not current-prefix-arg) (setq title (concat repo "/" title))))
((or "file" "code")
(when (not current-prefix-arg) (setq title (concat repo "/" branch "/" path)))))
(when url
(cond
((derived-mode-p 'org-mode)
(insert (cond
((and url title) (format " [[%s][%s]] " url title))
(url (format " [[%s]] " url))
(t ""))))
((derived-mode-p 'markdown-mode)
(insert (cond
((and url title) (format " [%s](%s) " url title))
(url (format " <%s> " url))
(t ""))))
(t
(insert (cond
((and url title) (format " %s (%s) " title url))
(url (format " %s " url))
(t "")))))))))
(defun consult-gh-embark-copy-https-link-as-kill (cand)
"Copy http link of CAND to `kill-ring'."
(when (stringp cand)
(consult-gh-with-host
(consult-gh--auth-account-host)
(let ((repo (get-text-property 0 :repo cand)))
(kill-new (concat (string-trim (consult-gh--command-to-string "browse" "--repo" (string-trim repo) "--no-browser")) ".git"))))))
(defun consult-gh-embark-copy-ssh-link-as-kill (cand)
"Copy shh link of CAND to `kill-ring'."
(when (stringp cand)
(consult-gh-with-host
(consult-gh--auth-account-host)
(let* ((repo (get-text-property 0 :repo cand)))
(kill-new (consult-gh--json-to-hashtable (consult-gh--command-to-string "repo" "view" (string-trim repo) "--json" "sshUrl") :sshUrl))))))
(defun consult-gh-embark-copy-straight-usepackage-link-as-kill (cand)
"Copy a drop-in straight use-package script of CAND to `kill-ring'."
(when (stringp cand)
(let* ((repo (get-text-property 0 :repo cand))
(package (car (last (split-string repo "\/")))))
(kill-new (concat "(use-package " package "\n\t:straight (" package " :type git :host github :repo \"" repo "\")\n)")))))
(defun consult-gh-embark-copy-usepackage-link-as-kill (cand)
"Copy a drop-in use-package script of CAND to `kill-ring'."
(when (stringp cand)
(let* ((repo (get-text-property 0 :repo cand))
(package (car (last (split-string repo "\/")))))
(kill-new (concat "(use-package " package)))))
(defun consult-gh-embark-get-other-repos-by-same-user (cand)
"List other repos by the same user/organization as CAND at point."
(when (stringp cand)
(let* ((repo (get-text-property 0 :repo cand))
(user (car (split-string repo "\/"))))
(consult-gh-repo-list user))))
(defun consult-gh-embark-view-issues-of-repo (cand)
"Browse issues of CAND repo at point."
(when (stringp cand)
(let ((repo (or (get-text-property 0 :repo cand))))
(consult-gh-issue-list repo))))
(defun consult-gh-embark-view-prs-of-repo (cand)
"Browse PRs of CAND repo at point."
(when (stringp cand)
(let ((repo (or (get-text-property 0 :repo cand))))
(consult-gh-pr-list repo))))
(defun consult-gh-embark-view-files-of-repo (cand)
"Browse files of CAND at point."
(when (stringp cand)
(let ((repo (or (get-text-property 0 :repo cand) (consult-gh--nonutf-cleanup cand))))
(consult-gh-find-file repo))))
(defun consult-gh-embark-clone-repo (cand)
"Clone the CAND repo at point."
(when (stringp cand)
(consult-gh-with-host
(consult-gh--auth-account-host)
(funcall #'consult-gh--repo-clone-action cand))))
(defun consult-gh-embark-fork-repo (cand)
"Fork the CAND repo at point."
(when (stringp cand)
(consult-gh-with-host
(consult-gh--auth-account-host)
(funcall #'consult-gh--repo-fork-action cand))))
(defun consult-gh-embark-save-file (cand)
"Save the CAND file at point."
(when (stringp cand)
(consult-gh-with-host
(consult-gh--auth-account-host)
(funcall #'consult-gh--files-save-file-action cand))))
(defun consult-gh-embark-create-issue (cand)
"Create an issue in repo of CAND"
(when (stringp cand)
(consult-gh-with-host
(consult-gh--auth-account-host)
(let ((repo (get-text-property 0 :repo cand)))
(funcall #'consult-gh-issue-create repo)))))
(defun consult-gh-embark-create-pr (cand)
"Create a pull request in repo of CAND"
(when (stringp cand)
(consult-gh-with-host
(consult-gh--auth-account-host)
(let ((repo (get-text-property 0 :repo cand)))
(funcall #'consult-gh-pr-create repo)))))
(defun consult-gh-embark-toggle-issue-open (cand)
"Close/Re-open the issue in CAND"
(when (stringp cand)
(consult-gh-with-host
(consult-gh--auth-account-host)
(let* ((state (get-text-property 0 :state cand)))
(if (equal state "OPEN")
(funcall #'consult-gh-issue-close cand)
(funcall #'consult-gh-issue-reopen cand))))))
(defun consult-gh-embark-toggle-issue-pin (cand)
"Pin/Unpin the issue in CAND"
(when (stringp cand)
(consult-gh-with-host
(consult-gh--auth-account-host)
(when-let* ((repo (get-text-property 0 :repo cand))
(number (get-text-property 0 :number cand))
(state (when (and repo number)
(consult-gh--json-to-hashtable (consult-gh--command-to-string "issue" "view" number "--repo" repo "--json" "isPinned") :isPinned))))
(if (eq state 't)
(funcall #'consult-gh-issue-unpin cand)
(funcall #'consult-gh-issue-pin cand))))))
(defun consult-gh-embark-toggle-issue-lock (cand)
"Lock/Unlock the issue in CAND"
(when (stringp cand)
(consult-gh-with-host
(consult-gh--auth-account-host)
(when-let* ((repo (get-text-property 0 :repo cand))
(number (get-text-property 0 :number cand))
(state (when (and repo number)
(consult-gh--json-to-hashtable (consult-gh--api-command-string (format "/repos/%s/issues/%s" repo number)) :locked))))
(if (eq state 't)
(funcall #'consult-gh-issue-unlock cand)
(funcall #'consult-gh-issue-lock cand))))))
(defun consult-gh-embark-transfer-issue (cand)
"Transfer the issue in CAND"
(when (stringp cand)
(consult-gh-with-host
(consult-gh--auth-account-host)
(funcall #'consult-gh-issue-transfer cand))))
(defun consult-gh-embark-delete-issue (cand)
"Delete the issue in CAND"
(when (stringp cand)
(consult-gh-with-host
(consult-gh--auth-account-host)
(funcall #'consult-gh-issue-delete cand))))
(defun consult-gh-embark-develop-issue (cand)
"Make a linked branch for the issue in CAND"
(when (stringp cand)
(consult-gh-with-host
(consult-gh--auth-account-host)
(funcall #'consult-gh-issue-develop cand))))
(defun consult-gh-embark-edit-issue (cand)
"Make a linked branch for the issue in CAND"
(when (stringp cand)
(consult-gh-with-host
(consult-gh--auth-account-host)
(funcall #'consult-gh-issue-edit cand))))
(defun consult-gh-embark-comment-on-issue (cand)
"Edit the issue in CAND"
(when (stringp cand)
(consult-gh-with-host
(consult-gh--auth-account-host)
(let ((repo (get-text-property 0 :repo cand))
(number (get-text-property 0 :number cand)))
(with-current-buffer (funcall #'consult-gh--issue-view repo number)
(consult-gh-topics-comment-create))))))
(defun consult-gh-embark-edit-pr (cand)
"Edit the pull request in CAND"
(when (stringp cand)
(consult-gh-with-host
(consult-gh--auth-account-host)
(funcall #'consult-gh-pr-edit cand))))
(defun consult-gh-embark-merge-pr (cand)
"Merge the pull request in CAND"
(when (stringp cand)
(consult-gh-with-host
(consult-gh--auth-account-host)
(funcall #'consult-gh-pr-merge cand))))
(defun consult-gh-embark-review-pr (cand)
"Review the pull request in CAND"
(when (stringp cand)
(consult-gh-with-host
(consult-gh--auth-account-host)
(funcall #'consult-gh-pr-review cand))))
(defun consult-gh-embark-comment-on-pr (cand)
"Make a linked branch for the issue in CAND"
(when (stringp cand)
(consult-gh-with-host
(consult-gh--auth-account-host)
(let ((repo (get-text-property 0 :repo cand))
(number (get-text-property 0 :number cand)))
(with-current-buffer (funcall #'consult-gh--pr-view repo number)
(consult-gh-topics-comment-create))))))
(defun consult-gh-embark-toggle-pr-open (cand)
"Close/Re-open the pull request in CAND"
(when (stringp cand)
(consult-gh-with-host
(consult-gh--auth-account-host)
(let* ((state (get-text-property 0 :state cand)))
(if (equal state "OPEN")
(funcall #'consult-gh-pr-close cand)
(funcall #'consult-gh-pr-reopen cand))))))
(defun consult-gh-embark-toggle-pr-lock (cand)
"Lock/Unlock the pull request in CAND"
(when (stringp cand)
(consult-gh-with-host
(consult-gh--auth-account-host)
(when-let* ((repo (get-text-property 0 :repo cand))
(number (get-text-property 0 :number cand))
(state (when (and repo number)
(consult-gh--json-to-hashtable (consult-gh--api-command-string (format "/repos/%s/pulls/%s" repo number)) :locked))))
(if (eq state 't)
(funcall #'consult-gh-pr-unlock cand)
(funcall #'consult-gh-pr-lock cand))))))
(defun consult-gh-embark-toggle-pr-draft (cand)
"Toggle the pull request in CAND as draft/ready"
(when (stringp cand)
(consult-gh-with-host
(consult-gh--auth-account-host)
(when-let* ((repo (get-text-property 0 :repo cand))
(number (get-text-property 0 :number cand))
(state (when (and repo number)
(consult-gh--json-to-hashtable (consult-gh--command-to-string "pr" "view" number "--repo" repo "--json" "isDraft") :isDraft))))
(if (eq state 't)
(funcall #'consult-gh-pr-mark-ready cand)
(funcall #'consult-gh-pr-mark-draft cand))))))
(defun consult-gh-embark-toggle-notification-read (cand)
"Mark the notification in CAND as read/unread"
(when (stringp cand)
(consult-gh-with-host
(consult-gh--auth-account-host)
(let ((state (get-text-property 0 :state cand)))
(if (equal state "Unread")
(consult-gh--notifications-mark-as-read cand))))))
(defun consult-gh-embark-notification-toggle-subscription (cand)
"Mark the notification in CAND as read/unread"
(when (stringp cand)
(consult-gh-with-host
(consult-gh--auth-account-host)
(let* ((thread (get-text-property 0 :thread cand))
(subscription (consult-gh--json-to-hashtable (consult-gh--api-command-string (format "/notifications/threads/%s/subscription" thread)) :subscribed)))
(if (eq subscription 't)
(consult-gh--notifications-unsubscribe cand)
(consult-gh--notifications-subscribe cand))))))
;;; Define Embark Keymaps
(defvar-keymap consult-gh-embark-general-actions-map
:doc "Keymap for consult-gh-embark"
:parent embark-general-map
"b r r" #'consult-gh-embark-add-repo-to-known-repos
"b r k" #'consult-gh-embark-remove-repo-from-known-repos
"b o o" #'consult-gh-embark-add-org-to-known-orgs
"b o k" #'consult-gh-embark-remove-org-from-known-orgs
"b o d" #'consult-gh-embark-add-org-to-favorite-list
"b o D" #'consult-gh-embark-remove-org-from-favorite-list
"c i" #'consult-gh-embark-create-issue
"c p" #'consult-gh-embark-create-pr
"f f" #'consult-gh-embark-view-files-of-repo
"i t" #'consult-gh-embark-insert-title
"i u" #'consult-gh-embark-insert-url-link
"l h" #'consult-gh-embark-copy-https-link-as-kill
"l s" #'consult-gh-embark-copy-ssh-link-as-kill
"l l" #'consult-gh-embark-copy-url-link-as-kill
"l o" #'consult-gh-embark-copy-url-org-link-as-kill
"l u" #'consult-gh-embark-copy-straight-usepackage-link-as-kill
"o o" #'consult-gh-embark-open-in-system-browser
"o O" #'consult-gh-embark-open-in-default-browser
"o p" #'consult-gh-embark-show-preview
"r c" #'consult-gh-embark-clone-repo
"r f" #'consult-gh-embark-fork-repo
"r r" #'consult-gh-embark-get-other-repos-by-same-user
"r i" #'consult-gh-embark-view-issues-of-repo
"r p" #'consult-gh-embark-view-prs-of-repo
"w t" #'consult-gh-embark-copy-title-as-kill
"w u" #'consult-gh-embark-copy-url-link-as-kill
"w h" #'consult-gh-embark-copy-https-link-as-kill
"w s" #'consult-gh-embark-copy-ssh-link-as-kill
"w o" #'consult-gh-embark-copy-url-org-link-as-kill)
(defvar-keymap consult-gh-embark-orgs-actions-map
:doc "Keymap for consult-gh-embark-orgs"
:parent consult-gh-embark-general-actions-map)
(defvar-keymap consult-gh-embark-repos-actions-map
:doc "Keymap for consult-gh-embark-repos"
:parent consult-gh-embark-general-actions-map)
(defvar-keymap consult-gh-embark-files-actions-map
:doc "Keymap for consult-gh-embark-files"
:parent consult-gh-embark-general-actions-map
"s" #'consult-gh-embark-save-file)
(defvar-keymap consult-gh-embark-issues-actions-map
:doc "Keymap for consult-gh-embark-repos"
:parent consult-gh-embark-general-actions-map
"c c" #'consult-gh-embark-comment-on-issue
"g D" #'consult-gh-embark-delete-issue
"g e" #'consult-gh-embark-edit-issue
"g g" #'consult-gh-embark-develop-issue
"g L" #'consult-gh-embark-toggle-issue-lock
"g O" #'consult-gh-embark-toggle-issue-open
"g P" #'consult-gh-embark-toggle-issue-pin
"g T" #'consult-gh-embark-transfer-issue)
(defvar-keymap consult-gh-embark-prs-actions-map
:doc "Keymap for consult-gh-embark-repos"
:parent consult-gh-embark-general-actions-map
"c c" #'consult-gh-embark-comment-on-pr
"c r" #'consult-gh-embark-review-pr
"g e" #'consult-gh-embark-edit-pr
"g D" #'consult-gh-embark-toggle-pr-draft
"g L" #'consult-gh-embark-toggle-pr-lock
"g m" #'consult-gh-embark-merge-pr
"g O" #'consult-gh-embark-toggle-pr-open)
(defvar-keymap consult-gh-embark-codes-actions-map
:doc "Keymap for consult-gh-embark-codes"
:parent consult-gh-embark-general-actions-map)
(defvar-keymap consult-gh-embark-notifications-actions-map
:doc "Keymap for consult-gh-embark-notifications"
:parent consult-gh-embark-general-actions-map
"g r" #'consult-gh-embark-toggle-notification-read
"g s" #'consult-gh-embark-notification-toggle-subscription)
;;; Define consult-gh-embark minor-mode
(defun consult-gh-embark--mode-on ()
"Enable `consult-gh-embark-mode'."
(add-to-list 'embark-keymap-alist '(consult-gh . consult-gh-embark-general-actions-map))
(add-to-list 'embark-keymap-alist '(consult-gh-orgs . consult-gh-embark-orgs-actions-map))
(add-to-list 'embark-keymap-alist '(consult-gh-repos . consult-gh-embark-repos-actions-map))
(add-to-list 'embark-keymap-alist '(consult-gh-files . consult-gh-embark-files-actions-map))
(add-to-list 'embark-keymap-alist '(consult-gh-issues . consult-gh-embark-issues-actions-map))
(add-to-list 'embark-keymap-alist '(consult-gh-prs . consult-gh-embark-prs-actions-map))
(add-to-list 'embark-keymap-alist '(consult-gh-codes . consult-gh-embark-codes-actions-map))
(add-to-list 'embark-keymap-alist '(consult-gh-notifications . consult-gh-embark-notifications-actions-map))
(add-to-list 'embark-keymap-alist '(consult-gh-codes . consult-gh-embark-codes-actions-map))
(add-to-list 'embark-default-action-overrides '(consult-gh-repos . consult-gh-embark-default-action))
(add-to-list 'embark-default-action-overrides '(consult-gh-issues . consult-gh-embark-default-action))
(add-to-list 'embark-default-action-overrides '(consult-gh-prs . consult-gh-embark-default-action))
(add-to-list 'embark-default-action-overrides '(consult-gh-files . consult-gh-embark-default-action))
(add-to-list 'embark-default-action-overrides '(consult-gh-codes . consult-gh-embark-default-action))
(add-to-list 'embark-default-action-overrides '(consult-gh-notifications . consult-gh-embark-default-action)))
(defun consult-gh-embark--mode-off ()
"Disable `consult-gh-embark-mode'."
(setq embark-keymap-alist (seq-difference embark-keymap-alist '((consult-gh . consult-gh-embark-general-actions-map)
(consult-gh-orgs . consult-gh-embark-orgs-actions-map)
(consult-gh-repos . consult-gh-embark-repos-actions-map)
(consult-gh-files . consult-gh-embark-files-actions-map)
(consult-gh-issues . consult-gh-embark-issues-actions-map)
(consult-gh-prs . consult-gh-embark-prs-actions-map))))
(setq embark-default-action-overrides (seq-difference embark-default-action-overrides
'((consult-gh-repos . consult-gh-embark-default-action)
(consult-gh-issues . consult-gh-embark-default-action)
(consult-gh-prs . consult-gh-embark-default-action)
(consult-gh-files . consult-gh-embark-default-action)
(consult-gh-codes . consult-gh-embark-default-action)
(consult-gh-notifications . consult-gh-embark-default-action)))))
(defun consult-gh-embark-unload-function ()
"Unload function for `consult-gh-embark'."
(consult-gh-embark--mode-off))
;;;###autoload
(define-minor-mode consult-gh-embark-mode
"Use embark with `consult-gh' for extra actions."
:init-value nil
:global t
:group 'consult-gh
:lighter " consult-gh-embark"
(if consult-gh-embark-mode
(consult-gh-embark--mode-on)
(consult-gh-embark--mode-off)))
;;; Provide `consul-gh-embark' module
(provide 'consult-gh-embark)
;;; consult-gh-embark.el ends here