commit | author | age
|
5cb5f7
|
1 |
;;; gogs.el --- minuscule client library for the Gogs API -*- lexical-binding: t -*- |
C |
2 |
|
|
3 |
;; Copyright (C) 2016-2018 Jonas Bernoulli |
|
4 |
|
|
5 |
;; Author: Jonas Bernoulli <jonas@bernoul.li> |
|
6 |
;; Homepage: https://github.com/magit/ghub |
|
7 |
;; Keywords: tools |
|
8 |
|
|
9 |
;; This file is not part of GNU Emacs. |
|
10 |
|
|
11 |
;; This file is free software; you can redistribute it and/or modify |
|
12 |
;; it under the terms of the GNU General Public License as published by |
|
13 |
;; the Free Software Foundation; either version 3, or (at your option) |
|
14 |
;; any later version. |
|
15 |
|
|
16 |
;; This file is distributed in the hope that it will be useful, |
|
17 |
;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 |
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19 |
;; GNU General Public License for more details. |
|
20 |
|
|
21 |
;; For a copy of the GPL see https://www.gnu.org/licenses/gpl.txt. |
|
22 |
|
|
23 |
;;; Commentary: |
|
24 |
|
|
25 |
;; Gogs is a library that provides basic support for using the Gogs API |
|
26 |
;; from Emacs packages. It abstracts access to API resources using only |
|
27 |
;; a handful of functions that are not resource-specific. |
|
28 |
|
|
29 |
;; This library is implemented on top of Ghub. Unlike Ghub, Gogs does |
|
30 |
;; not support the guided creation of tokens because Gogs lacks the |
|
31 |
;; features that would be necessary to implement that. Users have to |
|
32 |
;; create tokens through the web interface. |
|
33 |
|
|
34 |
;;; Code: |
|
35 |
|
|
36 |
(require 'ghub) |
|
37 |
|
|
38 |
(defconst gogs-default-host "localhost:3000/api/v1" |
|
39 |
"The default host that is used if `gogs.host' is not set.") |
|
40 |
|
|
41 |
;; HEAD does not appear to be supported. |
|
42 |
|
|
43 |
(cl-defun gogs-get (resource &optional params |
|
44 |
&key query payload headers |
|
45 |
silent unpaginate noerror reader |
|
46 |
username auth host |
|
47 |
callback errorback extra) |
|
48 |
"Make a `GET' request for RESOURCE, with optional query PARAMS. |
|
49 |
Like calling `ghub-request' (which see) with \"GET\" as METHOD |
|
50 |
and `gogs' as FORGE." |
|
51 |
(ghub-request "GET" resource params :forge 'gogs |
|
52 |
:query query :payload payload :headers headers |
|
53 |
:silent silent :unpaginate unpaginate |
|
54 |
:noerror noerror :reader reader |
|
55 |
:username username :auth auth :host host |
|
56 |
:callback callback :errorback errorback :extra extra)) |
|
57 |
|
|
58 |
(cl-defun gogs-put (resource &optional params |
|
59 |
&key query payload headers |
|
60 |
silent unpaginate noerror reader |
|
61 |
username auth host |
|
62 |
callback errorback extra) |
|
63 |
"Make a `PUT' request for RESOURCE, with optional payload PARAMS. |
|
64 |
Like calling `ghub-request' (which see) with \"PUT\" as METHOD |
|
65 |
and `gogs' as FORGE." |
|
66 |
(ghub-request "PUT" resource params :forge 'gogs |
|
67 |
:query query :payload payload :headers headers |
|
68 |
:silent silent :unpaginate unpaginate |
|
69 |
:noerror noerror :reader reader |
|
70 |
:username username :auth auth :host host |
|
71 |
:callback callback :errorback errorback :extra extra)) |
|
72 |
|
|
73 |
(cl-defun gogs-post (resource &optional params |
|
74 |
&key query payload headers |
|
75 |
silent unpaginate noerror reader |
|
76 |
username auth host |
|
77 |
callback errorback extra) |
|
78 |
"Make a `POST' request for RESOURCE, with optional payload PARAMS. |
|
79 |
Like calling `ghub-request' (which see) with \"POST\" as METHOD |
|
80 |
and `gogs' as FORGE." |
|
81 |
(ghub-request "POST" resource params :forge 'gogs |
|
82 |
:query query :payload payload :headers headers |
|
83 |
:silent silent :unpaginate unpaginate |
|
84 |
:noerror noerror :reader reader |
|
85 |
:username username :auth auth :host host |
|
86 |
:callback callback :errorback errorback :extra extra)) |
|
87 |
|
|
88 |
(cl-defun gogs-patch (resource &optional params |
|
89 |
&key query payload headers |
|
90 |
silent unpaginate noerror reader |
|
91 |
username auth host |
|
92 |
callback errorback extra) |
|
93 |
"Make a `PATCH' request for RESOURCE, with optional payload PARAMS. |
|
94 |
Like calling `ghub-request' (which see) with \"PATCH\" as METHOD |
|
95 |
and `gogs' as FORGE." |
|
96 |
(ghub-request "PATCH" resource params :forge 'gogs |
|
97 |
:query query :payload payload :headers headers |
|
98 |
:silent silent :unpaginate unpaginate |
|
99 |
:noerror noerror :reader reader |
|
100 |
:username username :auth auth :host host |
|
101 |
:callback callback :errorback errorback :extra extra)) |
|
102 |
|
|
103 |
(cl-defun gogs-delete (resource &optional params |
|
104 |
&key query payload headers |
|
105 |
silent unpaginate noerror reader |
|
106 |
username auth host |
|
107 |
callback errorback extra) |
|
108 |
"Make a `DELETE' request for RESOURCE, with optional payload PARAMS. |
|
109 |
Like calling `ghub-request' (which see) with \"DELETE\" as METHOD |
|
110 |
and `gogs' as FORGE." |
|
111 |
(ghub-request "DELETE" resource params :forge 'gogs |
|
112 |
:query query :payload payload :headers headers |
|
113 |
:silent silent :unpaginate unpaginate |
|
114 |
:noerror noerror :reader reader |
|
115 |
:username username :auth auth :host host |
|
116 |
:callback callback :errorback errorback :extra extra)) |
|
117 |
|
|
118 |
(cl-defun gogs-request (method resource &optional params |
|
119 |
&key query payload headers |
|
120 |
silent unpaginate noerror reader |
|
121 |
username auth host |
|
122 |
callback errorback extra) |
|
123 |
"Make a request for RESOURCE and return the response body. |
|
124 |
Like calling `ghub-request' (which see) with `gogs' as FORGE." |
|
125 |
(ghub-request method resource params :forge 'gogs |
|
126 |
:query query :payload payload :headers headers |
|
127 |
:silent silent :unpaginate unpaginate |
|
128 |
:noerror noerror :reader reader |
|
129 |
:username username :auth auth :host host |
|
130 |
:callback callback :errorback errorback :extra extra)) |
|
131 |
|
|
132 |
(cl-defun gogs-repository-id (owner name &key username auth host) |
|
133 |
"Return the id of the repository specified by OWNER, NAME and HOST." |
|
134 |
(number-to-string |
|
135 |
(cdr (assq 'id (gogs-get (format "/repos/%s/%s" owner name) |
|
136 |
nil :username username :auth auth :host host))))) |
|
137 |
|
|
138 |
;;; _ |
|
139 |
(provide 'gogs) |
|
140 |
;;; gogs.el ends here |