-
Notifications
You must be signed in to change notification settings - Fork 1
/
yandex-arc-revision.el
127 lines (98 loc) · 4.79 KB
/
yandex-arc-revision.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
;; -*- lexical-binding: t; -*-
(provide 'yandex-arc-revision)
(require 'yandex-arc-actions)
(require 'yandex-arc-properties)
(require 'yandex-arc-shell)
(require 'yandex-arc-util)
(require 'eieio)
(defclass yandex-arc/revision/summary-section (magit-section) ())
(defclass yandex-arc/revision/message-section (magit-section) ())
(defvar-local yandex-arc/revision/commit nil
"Commit the revision buffer shows information about.")
(defvar-keymap yandex-arc-revision-mode-map
:doc "Keymap for `yandex-arc-revision-mode'."
"<return>" 'yandex-arc/actions/visit-at-point)
(define-derived-mode yandex-arc-revision-mode magit-section-mode "arc-revision"
"Yandex Arc Revision Major Mode."
(setq-local revert-buffer-function
(lambda (ignore-auto noconfirm)
(ignore ignore-auto noconfirm)
(yandex-arc/revision/redraw-buffer))))
(defun yandex-arc/revision/show-revision (commit)
(let ((buffer (get-buffer-create (concat "arc-revision: " (file-name-nondirectory default-directory)))))
(set-buffer buffer)
(yandex-arc-revision-mode)
(setq-local yandex-arc/revision/commit commit)
(yandex-arc/revision/redraw-buffer)
(switch-to-buffer buffer)))
(defun yandex-arc/revision/redraw-buffer ()
(yandex-arc/util/save-line-and-column
(let ((inhibit-read-only t))
(erase-buffer)
(setq-local header-line-format yandex-arc/revision/commit)
(magit-insert-section (yandex-arc/root-section)
(when (not (yandex-arc/revision/is-stash yandex-arc/revision/commit))
(let ((description (yandex-arc/revision/get-commit-description yandex-arc/revision/commit)))
(yandex-arc/revision/insert-summary-section description)
(yandex-arc/revision/insert-message-section description)))
(yandex-arc/insert-files-section
:changes
(yandex-arc/revision/diff-commits-file-names-only yandex-arc/revision/commit)
:commit
yandex-arc/revision/commit)))))
(defun yandex-arc/revision/is-stash (commit)
(string-match-p "^stash@{[[:digit:]]+}" commit))
(defun yandex-arc/revision/get-commit-description (commit)
(let ((description (yandex-arc/shell/log-describe-commit commit)))
(cond ((/= (slot-value description 'return-code) 0)
(user-error "%s" (slot-value description 'value)))
((= (length (slot-value description 'value)) 0)
(user-error "There is no information about commit \'%s\'." commit))
(t ; No errors
(elt (slot-value description 'value) 0)))))
(defun yandex-arc/revision/diff-commits-file-names-only (commit)
(let ((result (yandex-arc/shell/diff-commits-file-names-only (concat commit "^") commit)))
(cond ((/= (slot-value result 'return-code) 0)
(user-error "%s" (slot-value result 'value)))
(t ; No errors
(seq-map
(lambda (file-name) (yandex-arc/shell/normalize-string file-name))
(split-string (slot-value result 'value)))))))
(defun yandex-arc/revision/insert-summary-section (description)
(magit-insert-section (yandex-arc/revision/summary-section)
(yandex-arc/revision/print-local-branches description)
(let ((commit (gethash "commit" description))
(author (gethash "author" description))
(date (gethash "date" description))
(revision (gethash "revision" description)))
(insert (yandex-arc/properties/hash commit) ?\n)
(insert "Author: "
(yandex-arc/properties/link author "https://staff.yandex-team.ru/%s" author)
?\n)
(insert "Date: " date ?\n)
(when revision
(setq revision (number-to-string revision))
(insert "SVN Revision: "
(yandex-arc/properties/link revision "https://a.yandex-team.ru/arcadia/commit/r%s" revision)
?\n)))
(yandex-arc/revision/print-attributes description)
(insert ?\n)))
(defun yandex-arc/revision/print-local-branches (description)
(let ((branches (gethash "branches" description)))
(when branches
(when (gethash "head" branches)
(insert (yandex-arc/properties/branch-name "HEAD") " "))
(seq-doseq (branch (gethash "local" branches))
(insert (yandex-arc/properties/branch-name branch) " ")))))
(defun yandex-arc/revision/print-attributes (description)
(let ((attributes (gethash "attributes" description)))
(when attributes
(let ((pull-request-id (gethash "pr.id" attributes)))
(when pull-request-id
(insert "Pull request: "
(yandex-arc/properties/link pull-request-id "https://a.yandex-team.ru/review/%s" pull-request-id)
?\n))))))
(defun yandex-arc/revision/insert-message-section (description)
(magit-insert-section (yandex-arc/revision/message-section)
(insert (gethash "message" description) ?\n)
(insert ?\n)))