-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathconsult-gh.el
9881 lines (8568 loc) · 495 KB
/
consult-gh.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
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; consult-gh.el --- Consulting GitHub Client -*- 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 "1.0") (markdown-mode "2.6") (ox-gfm "1.0"))
;; Keywords: convenience, matching, tools, vc
;; Homepage: https://github.com/armindarvish/consult-gh
;; 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 an interactive interface to GitHub command-line
;; client (see URL `https://cli.github.com/'). It uses a consult-based minibuffer
;; completion for searching and selecting GitHub repositories, issues,
;; pull erquests, codes, and etc.
;;; Code:
;;; Requirements
(eval-when-compile
(require 'json))
(require 'consult) ;; core dependency
(require 'markdown-mode) ;; markdown-mode for viewing issues,prs, ...
(require 'ox-gfm) ;; for exporting org-mode to github flavored markdown
(require 'org) ;; for its awesomeness!
;;; Group
(defgroup consult-gh nil
"Consult-based interface for GitHub CLI."
:group 'convenience
:group 'minibuffer
:group 'consult
:group 'magit
:prefix "consult-gh-"
:link '(url-link :tag "GitHub" "https://github.com/armindarvish/consult-gh"))
;;; Customization Variables
(defcustom consult-gh-args '("gh")
"Command line arguments to call GitHub CLI.
The dynamically computed arguments are appended.
Can be either a string, or a list of strings or expressions."
:group 'consult-gh
:type '(choice string (repeat (choice string sexp))))
(defcustom consult-gh-repo-list-args '("repo" "list")
"Additional arguments for `consult-gh-repo-list'.
The dynamically computed arguments are appended.
Can be either a string, or a list of strings or expressions."
:group 'consult-gh
:type '(choice string (repeat (choice string sexp))))
(defcustom consult-gh-issue-list-args '("issue" "list" "--repo")
"Additional arguments for `consult-gh-issue-list'.
The dynamically computed arguments are appended.
Can be either a string, or a list of strings or expressions."
:group 'consult-gh
:type '(choice string (repeat (choice string sexp))))
(defcustom consult-gh-search-issues-args '("search" "issues")
"Additional arguments for `consult-gh-search-issues'.
The dynamically computed arguments are appended.
Can be either a string, or a list of strings or expressions."
:group 'consult-gh
:type '(choice string (repeat (choice string sexp))))
(defcustom consult-gh-search-repos-args '("search" "repos" "--include-forks" "true")
"Additional arguments for `consult-gh-search-repos'.
The dynamically computed arguments are appended.
Can be either a string, or a list of strings or expressions."
:group 'consult-gh
:type '(choice string (repeat (choice string sexp))))
(defcustom consult-gh-pr-list-args '("pr" "list" "--repo")
"Additional arguments for `consult-gh-pr-list'.
The dynamically computed arguments are appended.
Can be either a string, or a list of strings or expressions."
:group 'consult-gh
:type '(choice string (repeat (choice string sexp))))
(defcustom consult-gh-search-prs-args '("search" "prs")
"Additional arguments for `consult-gh-search-prs'.
The dynamically computed arguments are appended.
Can be either a string, or a list of strings or expressions."
:group 'consult-gh
:type '(choice string (repeat (choice string sexp))))
(defcustom consult-gh-search-code-args '("search" "code")
"Additional arguments for `consult-gh-search-code'.
The dynamically computed arguments are appended.
Can be either a string, or a list of strings or expressions."
:group 'consult-gh
:type '(choice string (repeat (choice string sexp))))
(defcustom consult-gh-notifications-show-unread-only t
"Whether to hide reacd notifications?"
:group 'consult-gh
:type 'boolean)
(defcustom consult-gh-notifications-args-func #'consult-gh-notifications-make-args
"Additional arguments for `consult-gh-notifications'.
Common options include:
- `consult-gh-notifications-make-args' Make args to see unread notifications
- A custom function A function that takes
no input argument."
:group 'consult-gh
:type '(choice (const :tag "Default Funciton" consult-gh-notifications-make-args)
(function :tag "Custom Function")))
(defcustom consult-gh-browse-url-func #'browse-url
"What function to call browsing a url?
The function should take at least one argument for url similar to
`browse-url'.
Common options include:
- `browse-url' Opens url in default browser
- `eww-browse-url' Open url in eww
- `browse-url-firefox' Open url in firefox
- `browse-url-chrome' Open url in chrome"
:group 'consult-gh
:type '(choice (function :tag "Browse URL in default browser" browse-url)
(function :tag "Browse URL in EWW" eww-browse-url)
(function :tag "Browse URL in Firefox" browse-url-firefox)
(function :tag "Browse URL in Chrome" browse-url-chrome)
(function :tag "Custom Function")))
(defcustom consult-gh-switch-to-buffer-func #'switch-to-buffer
"What function to call when switching buffers?
The function should take at least one argument for buffer similar to
`switch-to-buffer'.
Common options include:
- `switch-to-buffer' Switch to buffer in current window
- `switch-to-buffer-other-window' Switch to buffer in other window
- `switch-to-buffer-other-frame' Switch to buffer in other frame
- `switch-to-buffer-other-tab' Switch to buffer in other tab"
:group 'consult-gh
:type '(choice (function :tag "(Default) Switch to buffer in current window" switch-to-buffer)
(function :tag "Switch to buffer in other window" switch-to-buffer-other-window)
(function :tag "Switch to buffer in other frame" switch-to-buffer-other-frame)
(function :tag "Switch to buffer in other tab" switch-to-buffer-other-tab)
(function :tag "Custom Function")))
(defcustom consult-gh-pop-to-buffer-func #'pop-to-buffer
"What function to call when popping to buffers?
The function should take at least one argument for buffer similar to
`pop-to-buffer'.
Common options include:
- `pop-to-buffer' Switch to buffer in current window
- `switch-to-buffer-other-window' Switch to buffer in other window
- `switch-to-buffer-other-frame' Switch to buffer in other frame
- `switch-to-buffer-other-tab' Switch to buffer in other tab"
:group 'consult-gh
:type '(choice (function :tag "(Default) Pop to buffer in another" pop-to-buffer)
(function :tag "Switch to buffer in other window" switch-to-buffer-other-window)
(function :tag "Switch to buffer in other frame" switch-to-buffer-other-frame)
(function :tag "Switch to buffer in other tab" switch-to-buffer-other-tab)
(function :tag "Custom Function")))
(defcustom consult-gh-quit-window-func #'consult-gh-quit-window
"What function to call when quitting windows?
The function should take two arguments similar to
`consult-gh-quit-window'.
Common options include:
- `consult-gh-quit-window' Quit or delete window
- `quit-window' Quit window"
:group 'consult-gh
:type '(choice (function :tag "(Default) Quite or delete window" consult-gh-quit-window)
(function :tag "Quit window" quit-window)
(function :tag "Custom Function")))
(defcustom consult-gh-dashboard-items-functions (list #'consult-gh--dashboard-collect-author #'consult-gh--dashboard-collect-assigned #'consult-gh--dashboard-collect-mentions #'consult-gh--dashboard-collect-involves)
"A list of functions for collecting items in `consult-gh-dashboard'.
Each function in this list gets called in `consult-gh--dashboard-items'.
The function should accept an optional arg for user and
should return a list of candidates (relevant issues/pr for the user) to be
used in `consult-gh-dashboard'. For an example see
`consult-gh--dashboard-collect-author'."
:group 'consult-gh
:type '(repeat function))
(defcustom consult-gh-tempdir (expand-file-name "consult-gh" temporary-file-directory)
"Temporary file directory for the `consult-gh' package.
This directory is used for storing temporary files when
pulling files for viewing."
:group 'consult-gh
:type 'directory)
(make-obsolete-variable 'consult-gh-crm-separator nil "1.0")
(defcustom consult-gh-temp-tempdir-time-format "%Y%m%d%I%H%M"
"Tme FORMAT-STRING for temporary directories.
This is passed as FORMAT-STRING to `format-time-string' for naming
temporary diretories."
:group 'consult-gh
:type 'string)
(defcustom consult-gh-temp-tempdir-cache 300
"Time in seconds before making a new temp directory."
:group 'consult-gh
:type 'string)
(defcustom consult-gh-repo-maxnum 30
"Maximum number of repos to show for list and search operations.
This is the value passed to “--limit” in the command line.
The default is set to gh's default config, 30."
:group 'consult-gh
:type 'integer)
(defcustom consult-gh-issue-maxnum 30
"Maximum number of issues to show for list and search operations.
This is the value passed to “--limit” in the command line.
The default is set to gh's default config, 30"
:group 'consult-gh
:type 'integer)
(defcustom consult-gh-pr-maxnum 30
"Maximum number of PRs to show for list and search operations.
This is the value passed to “--limit” in the command line.
The default is set to gh's default config, 30"
:group 'consult-gh
:type 'integer)
(defcustom consult-gh-code-maxnum 30
"Maximum number of codes to show for list and search operations.
This is the value passed to “--limit” in the command line.
The default is set to gh's default config, 30"
:group 'consult-gh
:type 'integer)
(defcustom consult-gh-comments-maxnum 30
"Maximum number of comments to show when viewing issues or prs.
If there are more than this many comments, the user is queried about
whether to filer comments or not."
:group 'consult-gh
:type 'integer)
(defcustom consult-gh-issues-state-to-show "open"
"Which type of issues should be listed by `consult-gh-issue-list'?
This is what is passed to “--state” argument in the command line
when running `gh issue list`.
The possible options are “open”, “closed” or “all”."
:group 'consult-gh
:type '(choice (const :tag "Show open issues only" "open")
(const :tag "Show closed issues only" "closed")
(const :tag "Show all issues" "all")))
(defcustom consult-gh-prs-state-to-show "open"
"Which type of PRs should be listed by `consult-gh-pr-list'?
This is what is passed to “--state” argument in the command line
when running `gh pr list`.
The possible options are “open”, “closed”, “merged”, or “all”."
:group 'consult-gh
:type '(choice (const :tag "Show open pull requests only" "open")
(const :tag "Show closed pull requests only" "closed")
(const :tag "Show all pull requests" "all")))
(defcustom consult-gh-prs-show-commits-in-view t
"Whether to include all commits in `consult-gh--pr-view'?
Not including all commits make viewing long PRs faster."
:group 'consult-gh
:type 'boolean)
(defcustom consult-gh-large-file-warning-threshold large-file-warning-threshold
"Threshold for size of file to require confirmation for preview/open/save.
Files larger than this value in size will require user confirmation
before previewing, opening or saving the file.
Default value is set by `large-file-warning-threshold'.
If nil, no cofnirmation is required."
:group 'consult-gh
:type '(choice integer (const :tag "Never request confirmation" nil)))
(defcustom consult-gh-prioritize-local-folder 'suggest
"How to use the local repository for completion?
There are three options, \='suggest, nil or t.
When set to \='suggest, the git repository from the local folder
\(i.e. `default-directory')\ is added to the future history list
so it can quickly be accessed by `next-history-element' \(bound to
'\\[next-history-element]'\) when running commands such as
`consult-gh-issue-list' or `consult-gh-find-file'.
When set to t, the git repository from the local folder is used
as initial-input value for commands such as `consult-gh-issue-list'
or `consult-gh-find-file'. The entry can still be changed by user input.
If there is no GitHub repository in the `default-directory',
it falls back to no initial input.
When set to nil, the git repository from the local folder is ignored and
no initial input is provided."
:group 'consult-gh
:type '(choice (const :tag "Current repository is in future history" suggest)
(const :tag "Current repository is default input" t)
(const :tag "Current repository is ignored" nil)))
(defcustom consult-gh-repo-preview-major-mode nil
"Major mode to preview repository READMEs.
Choices are:
- \='nil Use major-mode associated with orginal file extension
- \='gfm-mode Use `gfm-mode'
- \='markdown-mode Use `markdown-mode'
- \='org-mode Use `org-mode'"
:group 'consult-gh
:type '(choice (const :tag "(Default) Guess major mode based on file format " nil)
(const :tag "Use GitHub flavor markdown mode" gfm-mode)
(const :tag "Use markdown mode" markdown-mode)
(const :tag "Use org mode" org-mode)))
(defcustom consult-gh-issue-preview-major-mode 'gfm-mode
"Major mode to preview issues and pull requests.
Choices are:
- \='nil Use `fundamental-mode'
- \='gfm-mode Use `gfm-mode'
- \='markdown-mode Use `markdown-mode'
- \='org-mode Use `org-mode'"
:group 'consult-gh
:type '(choice (const :tag "(Default) Use GitHub flavor markdown mode" gfm-mode)
(const :tag "Use markdown mode" markdown-mode)
(const :tag "Use org mode" org-mode)
(const :tag "Use fundamental-mode" nil)))
(defcustom consult-gh-topic-major-mode 'gfm-mode
"Major mode for editing comments on issues or pull requests.
Choices are:
- \='nil Use `text-mode'
- \='gfm-mode Use `gfm-mode'
- \='markdown-mode Use `markdown-mode'
- \='org-mode Use `org-mode'"
:group 'consult-gh
:type '(choice (const :tag "(Default) Use GitHub flavor markdown mode" gfm-mode)
(const :tag "Use markdown mode" markdown-mode)
(const :tag "Use org mode" org-mode)
(const :tag "Use text-mode" nil)))
(defcustom consult-gh-topic-use-capf t
"Use `consult-gh--topics-edit-capf' for `completion-at-point'.
When non-nil, `consult-gh--topics-edit-capf' ia used in
`consult-gh-topic-major-mode' buffer for autocompleting
issue/pr numbers or user names."
:group 'consult-gh
:type '(choice (const :tag "Use autocompletion" t)
(const :tag "Do not use autocompletion" nil)))
(make-obsolete-variable 'consult-gh-preview-buffer-mode "Use `consult-gh-repo-preview-major-mode', or `consult-gh-issue-preview-major-mode' instead." "1.1")
(defcustom consult-gh-favorite-orgs-list (list)
"List of default GitHub orgs.
This can be a list of orgs or a function returning a list"
:group 'consult-gh
:type '(repeat (string :tag "GitHub Organization (i.e. Username)")))
(make-obsolete 'consult-gh-default-orgs-list 'consult-gh-favorite-orgs-list "2.0")
(defcustom consult-gh-preview-buffer-name "*consult-gh-preview*"
"Default name for preview buffers."
:group 'consult-gh
:type 'string)
(defcustom consult-gh-completion-user-prefix "user "
"Prefix label to use for users in `consult-gh--topics-edit-capf'."
:group 'consult-gh
:type 'string)
(defcustom consult-gh-completion-issue-prefix "issue "
"Prefix label to use for issues in `consult-gh--topics-edit-capf'."
:group 'consult-gh
:type 'string)
(defcustom consult-gh-completion-pullrequest-prefix "pr "
"Prefix label to use for pull requests in `consult-gh--topics-edit-capf'."
:group 'consult-gh
:type 'string)
(defcustom consult-gh-completion-branch-prefix "branch "
"Prefix label to use for milestones in `consult-gh--topics-edit-capf'."
:group 'consult-gh
:type 'string)
(defcustom consult-gh-completion-label-prefix "label "
"Prefix label to use for labels in `consult-gh--topics-edit-capf'."
:group 'consult-gh
:type 'string)
(defcustom consult-gh-completion-project-prefix "project "
"Prefix label to use for projects in `consult-gh--topics-edit-capf'."
:group 'consult-gh
:type 'string)
(defcustom consult-gh-completion-milestone-prefix "milestone "
"Prefix label to use for milestones in `consult-gh--topics-edit-capf'."
:group 'consult-gh
:type 'string)
(defcustom consult-gh-completion-max-items "2000"
"Maximum number of items to load for autocomplete suggestions.
This is used in `consult-gh--topics-edit-capf'."
:group 'consult-gh
:type 'string)
(defcustom consult-gh-show-preview nil
"Should `consult-gh' show previews?
It turns previews on/off globally for all categories
\(repos, issues, prs, codes, files,...\)"
:group 'consult-gh
:type 'boolean)
(defcustom consult-gh-preview-key consult-preview-key
"What key to use to show preview for `consult-gh'?
This key is bound in minibuffer, and is similar to `consult-preview-key'
\(the default\) but explicitly for `consult-gh'.
This is used for all categories \(issues, prs, codes, files, etc.\)"
:group 'consult-gh
:type '(choice (const :tag "Any key" any)
(list :tag "Debounced"
(const :debounce)
(float :tag "Seconds" 0.1)
(const any))
(const :tag "No preview" nil)
(key :tag "Key")
(repeat :tag "List of keys" key)))
(defcustom consult-gh-group-by t
"What field to use to group the results in the minibuffer?
By default it is set to t, but can be any of:
t Use headers for marginalia info
nil Do not group
:user Group by repository owner
:type Group by candidate's type (e.g. issue, pr, ....)
:url Group by URL
:date Group by the last updated date
:visibility Group by visibility (e.g. public or private)
symbol Group by another property of the candidate"
:group 'consult-gh
:type '(choice (const :tag "(Default) Use Headers of Marginalia Info" t)
(const :tag "Do Not Group" nil)
(const :tag "Repository's full name" :repo)
(const :tag "Repository's owner" :user)
(const :tag "Repository's package name" :package)
(const :tag "Type of Item" :type)))
(defcustom consult-gh-group-repos-by consult-gh-group-by
"What field to use to group results in repo search?
This is used in `consult-gh-search-repos'.
By default it is set to t, but can be any of:
t Use headers for marginalia info
nil Do not group
:user Group by repository owner
:package Group by package name
:date Group by the last updated date
:visibility Group by visibility (e.g. public or private)
symbol Group by another property of the candidate"
:group 'consult-gh
:type '(choice (const :tag "(Default) Use Headers of Marginalia Info" t)
(const :tag "Do Not Group" nil)
(const :tag "Repository's owner" :user)
(const :tag "Repository's package name" :package)
(const :tag "Date the repo was last updated" :date)
(const :tag "Visibility (i.e. public, private,...)" :visibility)))
(defcustom consult-gh-group-issues-by consult-gh-group-by
"What field to use to group results in issue search?
This is used in `consult-gh-search-issues'.
By default it is set to t, but can be any of:
t Use headers for marginalia info
nil Do not group
:repo Group by repository full name
:state Group by status og issue (i.e. open or closed)
:user Group by repository owner
:package Group by package name
:date Group by the last updated date
symbol Group by another property of the candidate"
:group 'consult-gh
:type '(choice (const :tag "(Default) Use Headers of Marginalia Info" t)
(const :tag "Do Not Group" nil)
(const :tag "Repository's full name" :repo)
(const :tag "State of issue (e.g. open or closes)" :state)
(const :tag "Repository's owner" :user)
(const :tag "Repository's package name" :package)
(const :tag "Date the repo was last updated" :date)))
(defcustom consult-gh-group-prs-by consult-gh-group-by
"What field to use to group results in pull request search?
This is used in `consult-gh-search-prs'.
By default it is set to t, but can be any of:
t Use headers for marginalia info
nil Do not group
:repo Group by repository full name
:state Group by status og issue (i.e. open or closed)
:user Group by repository owner
:package Group by package name
:date Group by the last updated date
symbol Group by another property of the candidate"
:group 'consult-gh
:type '(choice (const :tag "(Default) Use Headers of Marginalia Info" t)
(const :tag "Do Not Group" nil)
(const :tag "Repository's full name" :repo)
(const :tag "State of issue (e.g. open or closes)" :state)
(const :tag "Repository's owner" :user)
(const :tag "Repository's package name" :package)
(const :tag "Date the repo was last updated" :date)))
(defcustom consult-gh-group-files-by consult-gh-group-by
"What field to use to group results in file search?
This is used in `consult-gh-search-codes'.
By default it is set to t, but can be any of:
t Use headers for marginalia info
nil Do not group
:repo Group by repository full name
:user Group by repository owner
:package Group by package name
:path Group by the file path
symbol Group by another property of the candidate"
:group 'consult-gh
:type '(choice (const :tag "(Default) Use Headers of Marginalia Info" t)
(const :tag "Do Not Group" nil)
(const :tag "Repository's full name" :repo)
(const :tag "Repository's owner" :user)
(const :tag "Repository's package name" :package)
(const :tag "File path relative to repo's root" :path)))
(defcustom consult-gh-group-code-by consult-gh-group-by
"What field to use to group results in code search?
This is used in `consult-gh-search-codes'.
By default it is set to t, but can be any of:
t Use headers for marginalia info
nil Do not group
:repo Group by repository full name
:user Group by repository owner
:package Group by package name
:path Group by the file path
symbol Group by another property of the candidate"
:group 'consult-gh
:type '(choice (const :tag "(Default) Use Headers of Marginalia Info" t)
(const :tag "Do Not Group" nil)
(const :tag "Repository's full name" :repo)
(const :tag "Repository's owner" :user)
(const :tag "Repository's package name" :package)
(const :tag "File path relative to repo's root" :path)))
(defcustom consult-gh-group-dashboard-by consult-gh-group-by
"What field to use to group results in code search?
This is used in `consult-gh-dashboard'.
By default it is set to t, but can be any of:
t Use headers for marginalia info
nil Do not group
:repo Group by repository full name
:reason Group by the reason (e.g. mentions)
:date Group by the last updated date
:type Group by candidate's type (e.g. issue, pr, ....)
symbol Group by another property of the candidate"
:group 'consult-gh
:type '(choice (const :tag "(Default) Use Headers of Marginalia Info" t)
(const :tag "Do Not Group" nil)
(const :tag "Repository's full name" :repo)
(const :tag "The reason (e.g. mentions)" :reason)
(const :tag "Date the repo was last updated" :date)
(const :tag "Type of Item" :type)))
(defcustom consult-gh-group-notifications-by consult-gh-group-by
"What field to use to group results in notifications?
This is used in `consult-gh-notifications'.
By default it is set to t, but can be any of:
t Use headers for marginalia info
nil Do not group
:repo Group by repository full name
:reason Group by the reason (e.g. mentions, comment, ...)
:date Group by the last updated date
:type Group by candidate's type (e.g. issue, pr, ....)
:state Group by status of issue (i.e. unread or read)
symbol Group by another property of the candidate"
:group 'consult-gh
:type '(choice (const :tag "(Default) Use Headers of Marginalia Info" t)
(const :tag "Do Not Group" nil)
(const :tag "Repository's full name" :repo)
(const :tag "The reason (e.g. mentions)" :reason)
(const :tag "Date the repo was last updated" :date)
(const :tag "State of issue (e.g. unread or read)" :state)
(const :tag "Type of Item" :type)))
(defcustom consult-gh-default-clone-directory "~/"
"Where should GitHub repos be cloned to by default?"
:group 'consult-gh
:type 'directory)
(defcustom consult-gh-default-save-directory "~/Downloads/"
"Where should single files be saved by default?
Note that this is used for saving individual files
\(see `consult-gh--files-save-file-action'\),
and not cloning entire repositories."
:group 'consult-gh
:type 'directory)
(defcustom consult-gh-confirm-before-clone t
"Should confirmation of path and name be requested before cloning?
When set to nil, the default directory
`consult-gh-default-clone-directory' and package name are used
without confirmation."
:group 'consult-gh
:type 'boolean)
(defcustom consult-gh-confirm-name-before-fork nil
"Should the new repository name be confirmed when forking a repository?
When set to nil \(default\), the original repo's name will be used,
otherwise request a name."
:group 'consult-gh
:type 'boolean)
(defcustom consult-gh-ask-for-path-before-save t
"Should file path be confirmed when saving files?
When set to nil, the default directory \(`consult-gh-default-save-directory'\),
and the buffer file name \(variable `buffer-file-name'\) are used,
otherwise a file path is requested."
:group 'consult-gh
:type 'boolean)
(defcustom consult-gh-default-branch-to-load 'ask
"Which branch of repository to load by default in `consult-gh-find-file'?
Possible values are:
- \='confirm: Ask for confirmation if “HEAD” branch should be loaded.
If not, then the user can choose a different branch.
- \='ask: Asks the user to select a branch.
- \='nil: load the “HEAD” branch, no questions asked.
- A symbol: loads the branch naemd in this variable.
Note that when this is set to a specific branch,
it is used for any repository that is fetched and if the branch does not exist,
it will cause an error. Therefore, using a specific branch is not recommended
as a general case but in temporary settings where one is sure the branch exists
on the repositories being fetched."
:group 'consult-gh
:type '(choice (const :tag "Ask for a branch name" ask)
(const :tag "Ask user to confirm loading HEAD, and if \"No\", ask for a branch name" confirm)
(const :tag "Loads the HEAD Branch, without confirmation"
nil)
(symbol :tag "Loads Specific Branch")))
(defcustom consult-gh-repo-action #'consult-gh--repo-browse-url-action
"What function to call when a repo is selected?
Common options include:
- `consult-gh--repo-browse-url-action' Opens url in default browser
- `consult-gh--repo-browse-files-action' Open files in Emacs
- `consult-gh--repo-view-action' Open repository's READMEe in Emacs
- `consult-gh--repo-clone-action' Clone the repository
- `consult-gh--repo-fork-action' Fork the repository
- A custom function: A function that takes
only 1 input argument,
the repo candidate."
:group 'consult-gh
:type '(choice (function :tag "Browse the Repository URL in default browser" #'consult-gh--repo-browse-url-action)
(function :tag "Open the Repository's README in an Emacs buffer" #'consult-gh--repo-view-action)
(function :tag "Browse Brnaches and Files inside Emacs" #'consult-gh--repo-browse-files-action)
(function :tag "Clone Repository to local folder" #'consult-gh--repo-clone-action)
(function :tag "Fork Repository" #'consult-gh--repo-fork-action)
(function :tag "Custom Function")))
(defcustom consult-gh-issue-action #'consult-gh--issue-browse-url-action
"What function to call when an issue is selected?
Common options include:
- `consult-gh--issue-browse-url-action' Opens the issue url in default browser
- `consult-gh--issue-view-action' Opens issue in Emacs
- `consult-gh-forge--issue-view-action' Opens issue in `magit-forge'.
\(requires `consult-gh-forge' library\)
- A custom function A function that takes
only 1 input argument,
the issue candidate."
:group 'consult-gh
:type (if (featurep 'consult-gh-forge) '(choice (const :tag "Browse the Issue URL in default browser" #'consult-gh--issue-browse-url-action)
(const :tag "Open the Issue in an Emacs buffer" #'consult-gh--issue-view-action)
(const :tag "Open the Issue in a Magit/Forge buffer" #'consult-gh-forge--issue-view-action)
(function :tag "Custom Function"))
'(choice (const :tag "Open the Issue URL in default browser" #'consult-gh--issue-browse-url-action)
(const :tag "Open the Issue in an Emacs buffer" #'consult-gh--issue-view-action)
(const :tag "Open the Issue in a Magit/Forge buffer" #'consult-gh-forge--issue-view-action)
(function :tag "Custom Function"))))
(defcustom consult-gh-pr-action #'consult-gh--pr-browse-url-action
"What function to call when a pull request is selected?
Common options include:
- `consult-gh--pr-browse-url-action' opens the PR url in default browser
- `consult-gh--pr-view-action' opens PR in Emacs
- `consult-gh-forge--pr-view-action' Open PR in a `magit-forge'
\(requires `consult-gh-forge' library\)
- A custom function A function that takes only
1 input argument,
the PR candidate."
:group 'consult-gh
:type (if (featurep 'consult-gh-forge) '(choice (const :tag "Browse the PR URL in default browser" #'consult-gh--pr-browse-url-action)
(const :tag "Open the PR in an Emacs buffer" #'consult-gh--pr-view-action)
(const :tag "Open the PR in a Magit/Forge buffer" #'consult-gh-forge--pr-view-action)
(function :tag "Custom Function"))
'(choice (const :tag "Open the PR URL in default browser" #'consult-gh--pr-browse-url-action)
(const :tag "Open the PR in an Emacs buffer" #'consult-gh--pr-view-action)
(function :tag "Custom Function"))))
(defcustom consult-gh-code-action #'consult-gh--code-browse-url-action
"What function to call when a code is selected?
Common options include:
- `consult-gh--code-browse-url-action' Opens the code in default browser
- `consult-gh--pr-view-action' Opens the codein Emacs
- A custom function A function that takes
only 1 input argument,
the code candidate."
:group 'consult-gh
:type '(choice (const :tag "Browse the Code (target file) URL in default browser" consult-gh--code-browse-url-action)
(const :tag "Open code (target file) in an Emacs buffer" consult-gh--code-view-action)
(function :tag "Custom Function")))
(defcustom consult-gh-file-action #'consult-gh--files-browse-url-action
"What function to call when a file is selected?
Common options include:
- `consult-gh--files-browse-url-action' Opens the file url in default browser
- `consult-gh--files-view-action' Opens the file in Emacs
- A custom function A function that takes
only 1 input argument,
the file candidate."
:group 'consult-gh
:type '(choice (const :tag "Browse the File URL" consult-gh--files-browse-url-action)
(const :tag "Save the File to local folder" consult-gh--files-view-action)
(function :tag "Custom Function")))
(defcustom consult-gh-discussion-action #'consult-gh--discussion-browse-url-action
"What function to call when a discussion is selected?
Common options include:
- `consult-gh--discussion-browse-url-action' Opens the notification url
in default browser
- A custom function A function that takes
only 1 input argument,
the notification candidate."
:group 'consult-gh
:type '(choice (const :tag "Browse the Discussion URL" consult-gh--discussion-browse-url-actionn)
(function :tag "Custom Function")))
(defcustom consult-gh-notifications-action #'consult-gh--notifications-action
"What function to call when a notification is selected?
Common options include:
- `consult-gh--notifications-action' Uses default action of
item type (e.g. issue,
pr, discussion,...)
- `consult-gh--notifications-browse-url-action' Open relevant
notifications in external
browser
- A custom function A function that takes
only 1 input argument,
the notification
candidate."
:group 'consult-gh
:type '(choice (const :tag "Use Default Action of Item Type (e.g. issue, pr, ...)" consult-gh--notifications-action)
(const :tag "Open relevant notifications in the browser)" consult-gh--notifications-browse-url-action)
(function :tag "Custom Function")))
(defcustom consult-gh-dashboard-action #'consult-gh--dashboard-action
"What function to call when a dashboard item is selected?
Common options include:
- `consult-gh--dashboard-action' Uses default action of item type
(e.g. issue or pr)
- `consult-gh--dashboard-browse-url-action' Opens the link in an external
browser
- A custom function A function that takes
only 1 input argument,
the dashboard candidate."
:group 'consult-gh
:type '(choice (const :tag "Use Default Action of Item Type (e.g. issue, pr, ...)" consult-gh--dashboard-action)
(const :tag "Open Issue/PR in external browser" consult-gh--dashboard-browse-url-action)
(function :tag "Custom Function")))
(defcustom consult-gh-highlight-matches t
"Should queries or code snippets be highlighted in preview buffers?"
:group 'consult-gh
:type 'boolean)
(defcustom consult-gh-default-interactive-command #'consult-gh-search-repos
"Which command should `consult-gh' call?"
:group 'consult-gh
:type '(choice (function :tag "(Default) Search Rpositories" consult-gh-search-repos)
(function :tag "List default repos of user" consult-gh-favorite-repos)
(function :tag "Open transient menu" consult-gh-transient)
(function :tag "Other custom interactive command")))
(defcustom consult-gh-use-search-to-find-name nil
"Whether to use `consult-gh-search-repos' to find repo name.
If this is set to non-nil, consult-gh calls `cosnult-gh-search-repos'
to get the repo name before runing `consult-gh-issue-list',
`consult-gh-pr-list', etc.
This is useful if you do not remember package names and want to do a
search first."
:group 'consult-gh
:type 'boolean)
;;; Other Variables
(defvar consult-gh-category 'consult-gh
"Category symbol for the `consult-gh' package.")
(defvar consult-gh-repos-category 'consult-gh-repos
"Category symbol for repos in `consult-gh' package.")
(defvar consult-gh-issues-category 'consult-gh-issues
"Category symbol for issues in `consult-gh' package.")
(defvar consult-gh-prs-category 'consult-gh-prs
"Category symbol for pull requests in `consult-gh' package.")
(defvar consult-gh-codes-category 'consult-gh-codes
"Category symbol for codes in `consult-gh' package.")
(defvar consult-gh-notifications-category 'consult-gh-notifications
"Category symbol for notifications in `consult-gh' package.")
(defvar consult-gh-orgs-category 'consult-gh-orgs
"Category symbol for orgs in `consult-gh' package.")
(defvar consult-gh-files-category 'consult-gh-files
"Category symbol for files in `consult-gh' package.")
(defvar consult-gh--preview-buffers-list (list)
"List of currently open preview buffers.")
(defvar consult-gh--orgs-history nil
"History variable for orgs used in `consult-gh-repo-list'.")
(defvar consult-gh--repos-history nil
"History variable for repos.
This is used in `consult-gh-issue-list' and `consult-gh-pr-list'.")
(defvar consult-gh--notifications-history nil
"History variable for notifications.
This is used in `consult-gh-notifications'.")
(defvar consult-gh--search-repos-history nil
"History variable for searching repos in `consult-gh-search-repos'.")
(defvar consult-gh--search-issues-history nil
"History variable for issues used in `consult-gh-search-issues'.")
(defvar consult-gh--search-prs-history nil
"History variable for pull requests used in `consult-gh-search-prs'.")
(defvar consult-gh--search-code-history nil
"History variable for codes used in `consult-gh-search-code'.")
(defvar consult-gh--files-history nil
"History variable for files used in `consult-gh-find-file'.")
(defvar consult-gh--current-user-orgs nil
"List of repos of current user.")
(defvar consult-gh--known-orgs-list nil
"List of previously visited orgs.")
(defvar consult-gh--known-repos-list nil
"List of previously visited repos.")
(defvar consult-gh--open-files-list nil
"List of currently open files.")
(defvar consult-gh--current-tempdir nil
"Current temporary directory.")
(defvar consult-gh--async-process-buffer-name " *consult-gh-async*"
"Name of buffer for async processes.")
(defvar consult-gh--async-log-buffer " *consult-gh-async-log*"
"Name of buffer for logging async process errors.")
(defvar consult-gh--current-input nil
"Current input of user query.")
(defvar consult-gh--auth-current-account nil
"Current logged-in and active account.
This is a list of \='(USERNAME HOST IF-ACTIVE)")
(defvar consult-gh-default-host "github.com"