2016-02-24 22:06:01 +00:00
|
|
|
;;; gh-issues.el --- issues api for github
|
|
|
|
|
2016-08-18 20:01:20 +00:00
|
|
|
;; Copyright (C) 2014-2015 Yann Hodique
|
|
|
|
;; Copyright (C) 2014 Travis Thieman
|
2016-02-24 22:06:01 +00:00
|
|
|
;; Copyright (C) 2012 Raimon Grau
|
|
|
|
|
|
|
|
;; Author: Raimon Grau <raimonster@gmail.com>
|
|
|
|
;; Keywords:
|
|
|
|
|
|
|
|
;; This program 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 program 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 program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;; Basic usage:
|
|
|
|
|
|
|
|
;; (setf api (gh-issues-api "api" :sync nil :cache nil :num-retries 1))
|
|
|
|
;; (setf issues (gh-issues-list api "user" "repo"))
|
|
|
|
;; (last (oref issues data)) ; get one issue
|
|
|
|
;; (setq mi (make-instance 'gh-issues-issue :body "issue body" :title "issue title"))
|
|
|
|
;; (gh-issues-issue-new api "user" "repo" mi)
|
2016-08-18 20:01:20 +00:00
|
|
|
;; (setf comments (gh-issues-comments-list api "user" "repo" "issue id"))
|
|
|
|
;; (setq my-comment (make-instance 'gh-issues-comment :body "This is great!"))
|
|
|
|
;; (gh-issues-comments-new api "user" "repo" "issue id" my-comment)
|
2016-02-24 22:06:01 +00:00
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
(eval-when-compile
|
|
|
|
(require 'cl))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(require 'eieio)
|
|
|
|
|
|
|
|
(require 'gh-api)
|
|
|
|
(require 'gh-auth)
|
2016-08-18 20:01:20 +00:00
|
|
|
(require 'gh-comments)
|
2016-02-24 22:06:01 +00:00
|
|
|
(require 'gh-common)
|
|
|
|
|
|
|
|
(require 'gh-repos)
|
|
|
|
|
2016-08-18 20:01:20 +00:00
|
|
|
;;;###autoload
|
|
|
|
(defclass gh-issues-api (gh-api-v3 gh-comments-api-mixin)
|
2016-02-24 22:06:01 +00:00
|
|
|
((issue-cls :allocation :class :initform gh-issues-issue)
|
|
|
|
(milestone-cls :allocation :class :initform gh-issues-milestone)
|
2016-08-18 20:01:20 +00:00
|
|
|
(label-cls :allocation :class :initform gh-issues-label)
|
|
|
|
(comment-cls :allocation :class :initform gh-issues-comment))
|
2016-02-24 22:06:01 +00:00
|
|
|
"Github Issues api")
|
|
|
|
|
2016-08-18 20:01:20 +00:00
|
|
|
;;;###autoload
|
|
|
|
(gh-defclass gh-issues-issue (gh-ref-object)
|
|
|
|
((number :initarg :number)
|
2016-02-24 22:06:01 +00:00
|
|
|
(state :initarg :state)
|
|
|
|
(title :initarg :title)
|
|
|
|
(body :initarg :body)
|
2016-08-18 20:01:20 +00:00
|
|
|
(user :initarg :user :initform nil :marshal-type gh-user)
|
|
|
|
(labels :initarg :labels :initform nil :marshal-type (list gh-issues-label))
|
|
|
|
(assignee :initarg :assignee :initform nil :marshal-type gh-user)
|
|
|
|
(milestone :initarg :milestone :initform nil :marshal-type gh-issues-milestone)
|
|
|
|
(comments :initarg :comments :initform 0)
|
|
|
|
(pull-request :initarg :pull-request :marshal-type gh-issues-pull-request)
|
|
|
|
(closed-at :initarg :created-at)
|
|
|
|
(created-at :initarg :created-at)
|
|
|
|
(updated-at :initarg :updated-at))
|
2016-02-24 22:06:01 +00:00
|
|
|
"issues request")
|
|
|
|
|
2016-08-18 20:01:20 +00:00
|
|
|
;;;###autoload
|
|
|
|
(gh-defclass gh-issues-pull-request (gh-object)
|
|
|
|
((html-url :initarg :html-url)
|
|
|
|
(diff-url :initarg :diff-url)
|
|
|
|
(patch-url :initarg :patch-url)))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(gh-defclass gh-issues-label (gh-ref-object)
|
|
|
|
((name :initarg :name)
|
2016-02-24 22:06:01 +00:00
|
|
|
(color :initarg :color)))
|
|
|
|
|
2016-08-18 20:01:20 +00:00
|
|
|
(defmethod gh-issues-label-req-to-update ((label gh-issues-label))
|
|
|
|
`(("name" . ,(oref label :name))
|
|
|
|
("color" . ,(oref label :color))))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(gh-defclass gh-issues-milestone (gh-ref-object)
|
|
|
|
((number :initarg :number)
|
2016-02-24 22:06:01 +00:00
|
|
|
(state :initarg :state)
|
|
|
|
(title :initarg :title)
|
|
|
|
(description :initarg :description)
|
2016-08-18 20:01:20 +00:00
|
|
|
(creator :initarg :creator :initform nil :marshal-type gh-user)
|
|
|
|
(open-issues :initarg :open-issues )
|
|
|
|
(closed-issues :initarg :closed-issues)
|
|
|
|
(created-at :initarg :created-at)
|
|
|
|
(due-on :initarg :due-on))
|
2016-02-24 22:06:01 +00:00
|
|
|
"github milestone")
|
|
|
|
|
2016-08-18 20:01:20 +00:00
|
|
|
;;;###autoload
|
|
|
|
(gh-defclass gh-issues-comment (gh-comment)
|
|
|
|
())
|
2016-02-24 22:06:01 +00:00
|
|
|
|
|
|
|
(defmethod gh-issues-issue-list ((api gh-issues-api) user repo)
|
|
|
|
(gh-api-authenticated-request
|
|
|
|
api (gh-object-list-reader (oref api issue-cls)) "GET"
|
|
|
|
(format "/repos/%s/%s/issues" user repo)))
|
|
|
|
|
|
|
|
(defmethod gh-issues-milestone-list ((api gh-issues-api) user repo)
|
|
|
|
(gh-api-authenticated-request
|
|
|
|
api (gh-object-list-reader (oref api milestone-cls)) "GET"
|
|
|
|
(format "/repos/%s/%s/milestones" user repo)))
|
|
|
|
|
|
|
|
(defmethod gh-issues-milestone-get ((api gh-issues-api) user repo id)
|
|
|
|
(gh-api-authenticated-request
|
|
|
|
api (gh-object-reader (oref api milestone-cls)) "GET"
|
|
|
|
(format "/repos/%s/%s/milestones/%s" user repo id)))
|
|
|
|
|
|
|
|
(defmethod gh-issues-milestone-new ((api gh-issues-api) user repo milestone)
|
|
|
|
(gh-api-authenticated-request
|
|
|
|
api (gh-object-reader (oref api milestone-cls)) "POST"
|
|
|
|
(format "/repos/%s/%s/milestones" user repo)
|
|
|
|
(gh-issues-milestone-req-to-update milestone)))
|
|
|
|
|
|
|
|
(defmethod gh-issues-milestone-update ((api gh-issues-api) user repo
|
|
|
|
id milestone)
|
|
|
|
(gh-api-authenticated-request
|
|
|
|
api (gh-object-reader (oref api milestone-cls)) "PATCH"
|
|
|
|
(format "/repos/%s/%s/milestones/%s" user repo id)
|
|
|
|
(gh-issues-milestone-req-to-update milestone)))
|
|
|
|
|
|
|
|
(defmethod gh-issues-milestone-req-to-update ((milestone gh-issues-milestone))
|
2016-06-29 07:21:54 +00:00
|
|
|
(let ((state (oref milestone :state))
|
|
|
|
(description (oref milestone :description))
|
|
|
|
(due-on (oref milestone :due-on))
|
|
|
|
(to-update `(("title" . ,(oref milestone :title)))))
|
2016-02-24 22:06:01 +00:00
|
|
|
(when state (nconc to-update `(("state" . ,state))))
|
|
|
|
(when description (nconc to-update `(("description" . ,description))))
|
2016-06-29 07:21:54 +00:00
|
|
|
(when due-on (nconc to-update `(("due_on" . ,due-on))))
|
2016-02-24 22:06:01 +00:00
|
|
|
to-update))
|
|
|
|
|
|
|
|
(defmethod gh-issues-issue-get ((api gh-issues-api) user repo id)
|
|
|
|
(gh-api-authenticated-request
|
|
|
|
api (gh-object-reader (oref api issue-cls)) "GET"
|
|
|
|
(format "/repos/%s/%s/issues/%s" user repo id)))
|
|
|
|
|
|
|
|
(defmethod gh-issues-issue-req-to-update ((req gh-issues-issue))
|
2016-06-29 07:21:54 +00:00
|
|
|
(let ((assignee (oref req :assignee))
|
2016-02-24 22:06:01 +00:00
|
|
|
;; (labels (oref req labels))
|
2016-06-29 07:21:54 +00:00
|
|
|
(milestone (oref req :milestone))
|
|
|
|
(to-update `(("title" . ,(oref req :title))
|
|
|
|
("state" . ,(oref req :state))
|
|
|
|
("body" . ,(oref req :body)))))
|
2016-02-24 22:06:01 +00:00
|
|
|
|
|
|
|
;; (when labels (nconc to-update `(("labels" . ,(oref req labels) ))))
|
|
|
|
(when milestone
|
2016-06-29 07:21:54 +00:00
|
|
|
(nconc to-update `(("milestone" . ,(oref milestone :number)))))
|
2016-02-24 22:06:01 +00:00
|
|
|
(when assignee
|
2016-06-29 07:21:54 +00:00
|
|
|
(nconc to-update `(("assignee" . ,(oref assignee :login)))))
|
2016-02-24 22:06:01 +00:00
|
|
|
to-update))
|
|
|
|
|
|
|
|
(defmethod gh-issues-issue-update ((api gh-issues-api) user repo id req)
|
|
|
|
(gh-api-authenticated-request
|
|
|
|
api (gh-object-reader (oref api issue-cls)) "PATCH"
|
|
|
|
(format "/repos/%s/%s/issues/%s" user repo id)
|
|
|
|
(gh-issues-issue-req-to-update req)))
|
|
|
|
|
|
|
|
(defmethod gh-issues-issue-new ((api gh-issues-api) user repo issue)
|
|
|
|
(gh-api-authenticated-request
|
|
|
|
api (gh-object-reader (oref api issue-cls)) "POST"
|
|
|
|
(format "/repos/%s/%s/issues" user repo)
|
|
|
|
(gh-issues-issue-req-to-update issue)))
|
|
|
|
|
2016-08-18 20:01:20 +00:00
|
|
|
;;; Labels
|
2016-02-24 22:06:01 +00:00
|
|
|
|
|
|
|
(defmethod gh-issues-label-get ((api gh-issues-api) user repo name)
|
|
|
|
(gh-api-authenticated-request
|
|
|
|
api (gh-object-reader (oref api label-cls)) "GET"
|
|
|
|
(format "/repos/%s/%s/labels/%s" user repo name)))
|
|
|
|
|
|
|
|
(defmethod gh-issues-label-list ((api gh-issues-api) user repo)
|
|
|
|
(gh-api-authenticated-request
|
|
|
|
api (gh-object-list-reader (oref api label-cls)) "GET"
|
|
|
|
(format "/repos/%s/%s/labels" user repo )))
|
|
|
|
|
|
|
|
(defmethod gh-issues-label-new ((api gh-issues-api) user repo req)
|
|
|
|
(gh-api-authenticated-request
|
|
|
|
api (gh-object-reader (oref api label-cls)) "POST"
|
|
|
|
(format "/repos/%s/%s/labels" user repo)
|
|
|
|
(gh-issues-label-req-to-update req)))
|
|
|
|
|
|
|
|
(defmethod gh-issues-label-update ((api gh-issues-api) user repo req)
|
|
|
|
(gh-api-authenticated-request
|
|
|
|
api (gh-object-reader (oref api label-cls)) "POST"
|
2016-06-29 07:21:54 +00:00
|
|
|
(format "/repos/%s/%s/labels/%s" user repo (oref req :name))
|
2016-02-24 22:06:01 +00:00
|
|
|
(gh-issues-label-req-to-update req)))
|
|
|
|
|
|
|
|
(defmethod gh-issues-label-delete ((api gh-issues-api) user repo name)
|
|
|
|
(gh-api-authenticated-request
|
|
|
|
api (gh-object-reader (oref api label-cls)) "DELETE"
|
|
|
|
(format "/repos/%s/%s/labels/%s" user repo name)))
|
|
|
|
|
|
|
|
|
|
|
|
(defmethod gh-issues-labels-in-issue ((api gh-issues-api) user repo
|
|
|
|
issue-or-issue-id)
|
|
|
|
(let ((issue-id (gh-issues--issue-id issue-or-issue-id)))
|
|
|
|
(gh-api-authenticated-request
|
|
|
|
api (gh-object-list-reader (oref api label-cls)) "GET"
|
|
|
|
(format "/repos/%s/%s/issues/%s/labels" user repo issue-id))))
|
|
|
|
|
|
|
|
(defmethod gh-issues-labels-add-to-issue ((api gh-issues-api) user repo
|
|
|
|
issue-or-issue-id labels)
|
|
|
|
(let ((issue-id (gh-issues--issue-id issue-or-issue-id)))
|
|
|
|
(gh-api-authenticated-request
|
|
|
|
api (gh-object-list-reader (oref api label-cls)) "PUT"
|
|
|
|
(format "/repos/%s/%s/issues/%s/labels" user repo issue-id)
|
|
|
|
(mapcar #'gh-issues--label-name labels))))
|
|
|
|
|
|
|
|
(defmethod gh-issues-labels-remove-all-from-issue ((api gh-issues-api) user repo
|
|
|
|
issue-or-issue-id )
|
|
|
|
(let ((issue-id (gh-issues--issue-id issue-or-issue-id)))
|
|
|
|
(gh-api-authenticated-request
|
|
|
|
api (lambda (x) x) "DELETE"
|
|
|
|
(format "/repos/%s/%s/issues/%s/labels" user repo issue-id))))
|
|
|
|
|
|
|
|
(defmethod gh-issues-labels-in-milestone ((api gh-issues-api) user repo
|
|
|
|
milestone-or-milestone-id)
|
|
|
|
(let ((milestone-id (gh-issues--milestone-id milestone-or-milestone-id)))
|
|
|
|
(gh-api-authenticated-request
|
|
|
|
api (gh-object-list-reader (oref api label-cls)) "GET"
|
|
|
|
(format "/repos/%s/%s/milestones/%s/labels" user repo milestone-id))))
|
|
|
|
|
2016-08-18 20:01:20 +00:00
|
|
|
;;; Comments
|
|
|
|
|
|
|
|
(defmethod gh-issues-comments-list ((api gh-issues-api) user repo issue-id)
|
|
|
|
(gh-comments-list api (format "/repos/%s/%s/issues/%s" user repo issue-id)))
|
|
|
|
|
|
|
|
(defmethod gh-issues-comments-get ((api gh-issues-api) user repo comment-id)
|
|
|
|
(gh-comments-get api (format "/repos/%s/%s/issues" user repo) comment-id))
|
|
|
|
|
|
|
|
(defmethod gh-issues-comments-update ((api gh-issues-api)
|
|
|
|
user repo comment-id comment)
|
|
|
|
(gh-comments-update api (format "/repos/%s/%s/issues" user repo)
|
|
|
|
comment-id (gh-comment-req-to-update comment)))
|
|
|
|
|
|
|
|
(defmethod gh-issues-comments-new ((api gh-issues-api)
|
|
|
|
user repo issue-id comment)
|
|
|
|
(gh-comments-new api (format "/repos/%s/%s/issues/%s" user repo issue-id)
|
|
|
|
(gh-comment-req-to-update comment)))
|
|
|
|
|
|
|
|
(defmethod gh-issues-comments-delete ((api gh-issues-api) user repo comment-id)
|
|
|
|
(gh-comments-delete api (format "/repos/%s/%s/issues" user repo) comment-id))
|
2016-02-24 22:06:01 +00:00
|
|
|
|
|
|
|
;;; helpers
|
|
|
|
|
|
|
|
(defun gh-issues--issue-id (issue-or-issue-id)
|
|
|
|
(if (eieio-object-p issue-or-issue-id)
|
2016-06-29 07:21:54 +00:00
|
|
|
(oref issue-or-issue-id :id)
|
2016-02-24 22:06:01 +00:00
|
|
|
issue-or-issue-id))
|
|
|
|
|
|
|
|
(defun gh-issues--milestone-id (milestone-or-milestone-id)
|
|
|
|
(if (eieio-object-p milestone-or-milestone-id)
|
2016-06-29 07:21:54 +00:00
|
|
|
(oref milestone-or-milestone-id :id)
|
2016-02-24 22:06:01 +00:00
|
|
|
milestone-or-milestone-id))
|
|
|
|
|
|
|
|
(defun gh-issues--label-name (label-or-label-name)
|
|
|
|
(if (eieio-object-p label-or-label-name)
|
2016-06-29 07:21:54 +00:00
|
|
|
(oref label-or-label-name :name)
|
2016-02-24 22:06:01 +00:00
|
|
|
label-or-label-name))
|
|
|
|
|
|
|
|
|
|
|
|
(provide 'gh-issues)
|
|
|
|
;;; gh-issues.el ends here
|
|
|
|
|
|
|
|
;; Local Variables:
|
|
|
|
;; indent-tabs-mode: nil
|
|
|
|
;; End:
|