-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathgh-pulls.el
157 lines (125 loc) · 5.52 KB
/
gh-pulls.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
;;; gh-pulls.el --- pull requests module for gh.el -*- lexical-binding: t; -*-
;; Copyright (C) 2011 Yann Hodique
;; Author: Yann Hodique <yann.hodique@gmail.com>
;; Keywords:
;; 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 2, 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 GNU Emacs; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;;
;;; Code:
(require 'eieio)
(require 'gh-api)
(require 'gh-auth)
(require 'gh-comments)
(require 'gh-common)
(require 'gh-repos)
(defclass gh-pulls-cache (gh-cache)
((invalidation-chain :allocation :class
:initform '(("^/repos/.*/.*/pulls$" . "\0")
("^/repos/.*/.*/pulls/.*$" . "\0")))))
(defclass gh-pulls-api (gh-api-v3 gh-comments-api-mixin)
((cache-cls :allocation :class :initform gh-pulls-cache)
(req-cls :allocation :class :initform gh-pulls-request)
(comment-cls :allocation :class :initform gh-pulls-comment))
"Git pull requests API")
(gh-defclass gh-pulls-comment (gh-comment)
((path :initarg :path)
(diff-hunk :initarg :diff-hunk)
(position :initarg :position)
(original-position :initarg :original-position)
(commit-id :initarg :commit-id)
(original-commit-id :initarg :original-commit-id)
(in-reply-to :initarg :in-reply-to :initform nil)))
(cl-defmethod gh-pulls-comment-req-to-create ((req gh-pulls-comment))
(let ((in-reply-to (oref req in-reply-to))
(to-update `(("body" . ,(oref req body)))))
(if in-reply-to
(nconc to-update `(("in_reply_to" . ,in-reply-to)))
(nconc to-update `(("commit_id" . ,(oref req commit-id))
("path" . ,(oref req path))
("position" . ,(oref req position)))))
to-update))
(gh-defclass gh-pulls-request-stub (gh-ref-object)
((diff-url :initarg :diff-url)
(patch-url :initarg :patch-url)
(issue-url :initarg :issue-url)
(number :initarg :number)
(state :initarg :state)
(title :initarg :title)
(body :initarg :body)
(created-at :initarg :created-at)
(updated-at :initarg :updated-at)
(closed-at :initarg :closed-at)
(merged-at :initarg :merged-at)
(head :initarg :head :initform nil :marshal-type gh-repos-ref)
(base :initarg :base :initform nil :marshal-type gh-repos-ref)))
(gh-defclass gh-pulls-request (gh-pulls-request-stub)
((merged :initarg :merged)
(mergeable :initarg :mergeable)
(merged-by :initarg :merged-by)
(comments :initarg :comments)
(user :initarg :user :initform nil :marshal-type gh-user)
(commits :initarg :commits)
(additions :initarg :additions)
(deletions :initarg :deletions)
(changed-files :initarg :changed-files))
"Git pull requests API")
(cl-defmethod gh-pulls-req-to-new ((req gh-pulls-request))
(let ((head (oref req :head))
(base (oref req :base)))
`(("title" . ,(oref req :title))
("body" . ,(oref req :body))
("head" . ,(or (oref head :ref) (oref head :sha)))
("base" . ,(or (oref base :ref) (oref base :sha))))))
(cl-defmethod gh-pulls-req-to-update ((req gh-pulls-request-stub))
`(("title" . ,(oref req :title))
("body" . ,(oref req :body))
("state" . ,(oref req :state))))
(cl-defmethod gh-pulls-list ((api gh-pulls-api) user repo)
(gh-api-authenticated-request
api (gh-object-list-reader (oref api req-cls)) "GET"
(format "/repos/%s/%s/pulls" user repo)))
(cl-defmethod gh-pulls-get ((api gh-pulls-api) user repo id)
(gh-api-authenticated-request
api (gh-object-reader (oref api req-cls)) "GET"
(format "/repos/%s/%s/pulls/%s" user repo id)))
(cl-defmethod gh-pulls-new ((api gh-pulls-api) user repo req)
(gh-api-authenticated-request
api (gh-object-reader (oref api req-cls)) "POST"
(format "/repos/%s/%s/pulls" user repo)
(gh-pulls-req-to-new req)))
(cl-defmethod gh-pulls-update ((api gh-pulls-api) user repo id req)
(gh-api-authenticated-request
api (gh-object-reader (oref api req-cls)) "PATCH"
(format "/repos/%s/%s/pulls/%s" user repo id)
(gh-pulls-req-to-update req)))
;;; Comments
(cl-defmethod gh-pulls-comments-list ((api gh-pulls-api) user repo pull-id)
(gh-comments-list api (format "/repos/%s/%s/pulls/%s" user repo pull-id)))
(cl-defmethod gh-pulls-comments-get ((api gh-pulls-api) user repo comment-id)
(gh-comments-get api (format "/repos/%s/%s/pulls" user repo) comment-id))
(cl-defmethod gh-pulls-comments-update ((api gh-pulls-api)
user repo comment-id comment)
(gh-comments-update api (format "/repos/%s/%s/pulls" user repo)
comment-id (gh-comment-req-to-update comment)))
(cl-defmethod gh-pulls-comments-new ((api gh-pulls-api)
user repo pull-id comment)
(gh-comments-new api (format "/repos/%s/%s/pulls/%s" user repo pull-id)
(gh-pulls-comment-req-to-create comment)))
(cl-defmethod gh-pulls-comments-delete ((api gh-pulls-api) user repo comment-id)
(gh-comments-delete api (format "/repos/%s/%s/pulls" user repo) comment-id))
(provide 'gh-pulls)
;;; gh-pulls.el ends here
;; Local Variables:
;; indent-tabs-mode: nil
;; End: