commit | author | age
|
5cb5f7
|
1 |
;;; buck.el --- minuscule client library for the Bitbucket 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 |
;; Buck is a library that provides basic support for using the Bitbucket 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, Buck does |
|
30 |
;; not support the guided creation of tokens because Bitbucket 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 buck-default-host "api.bitbucket.org/2.0" |
|
39 |
"The default host that is used if `buck.host' is not set.") |
|
40 |
|
|
41 |
;; HEAD and PATCH are not supported according to |
|
42 |
;; https://developer.atlassian.com/bitbucket/api/2/reference/meta/uri-uuid |
|
43 |
|
|
44 |
(cl-defun buck-get (resource &optional params |
|
45 |
&key query payload headers |
|
46 |
silent unpaginate noerror reader |
|
47 |
username auth host |
|
48 |
callback errorback extra) |
|
49 |
"Make a `GET' request for RESOURCE, with optional query PARAMS. |
|
50 |
Like calling `ghub-request' (which see) with \"GET\" as METHOD |
|
51 |
and `bitbucket' as FORGE." |
|
52 |
(ghub-request "GET" resource params :forge 'bitbucket |
|
53 |
:query query :payload payload :headers headers |
|
54 |
:silent silent :unpaginate unpaginate |
|
55 |
:noerror noerror :reader reader |
|
56 |
:username username :auth auth :host host |
|
57 |
:callback callback :errorback errorback :extra extra)) |
|
58 |
|
|
59 |
(cl-defun buck-put (resource &optional params |
|
60 |
&key query payload headers |
|
61 |
silent unpaginate noerror reader |
|
62 |
username auth host |
|
63 |
callback errorback extra) |
|
64 |
"Make a `PUT' request for RESOURCE, with optional payload PARAMS. |
|
65 |
Like calling `ghub-request' (which see) with \"PUT\" as METHOD |
|
66 |
and `bitbucket' as FORGE." |
|
67 |
(ghub-request "PUT" resource params :forge 'bitbucket |
|
68 |
:query query :payload payload :headers headers |
|
69 |
:silent silent :unpaginate unpaginate |
|
70 |
:noerror noerror :reader reader |
|
71 |
:username username :auth auth :host host |
|
72 |
:callback callback :errorback errorback :extra extra)) |
|
73 |
|
|
74 |
(cl-defun buck-post (resource &optional params |
|
75 |
&key query payload headers |
|
76 |
silent unpaginate noerror reader |
|
77 |
username auth host |
|
78 |
callback errorback extra) |
|
79 |
"Make a `POST' request for RESOURCE, with optional payload PARAMS. |
|
80 |
Like calling `ghub-request' (which see) with \"POST\" as METHOD |
|
81 |
and `bitbucket' as FORGE." |
|
82 |
(ghub-request "POST" resource params :forge 'bitbucket |
|
83 |
:query query :payload payload :headers headers |
|
84 |
:silent silent :unpaginate unpaginate |
|
85 |
:noerror noerror :reader reader |
|
86 |
:username username :auth auth :host host |
|
87 |
:callback callback :errorback errorback :extra extra)) |
|
88 |
|
|
89 |
(cl-defun buck-delete (resource &optional params |
|
90 |
&key query payload headers |
|
91 |
silent unpaginate noerror reader |
|
92 |
username auth host |
|
93 |
callback errorback extra) |
|
94 |
"Make a `DELETE' request for RESOURCE, with optional payload PARAMS. |
|
95 |
Like calling `ghub-request' (which see) with \"DELETE\" as METHOD |
|
96 |
and `bitbucket' as FORGE." |
|
97 |
(ghub-request "DELETE" resource params :forge 'bitbucket |
|
98 |
:query query :payload payload :headers headers |
|
99 |
:silent silent :unpaginate unpaginate |
|
100 |
:noerror noerror :reader reader |
|
101 |
:username username :auth auth :host host |
|
102 |
:callback callback :errorback errorback :extra extra)) |
|
103 |
|
|
104 |
(cl-defun buck-request (method resource &optional params |
|
105 |
&key query payload headers |
|
106 |
silent unpaginate noerror reader |
|
107 |
username auth host |
|
108 |
callback errorback extra) |
|
109 |
"Make a request for RESOURCE and return the response body. |
|
110 |
Like calling `ghub-request' (which see) with `bitbucket' as FORGE." |
|
111 |
(ghub-request method resource params :forge 'bitbucket |
|
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 buck-repository-id (owner name &key username auth host) |
|
119 |
"Return the id of the repository specified by OWNER, NAME and HOST." |
|
120 |
(substring (cdr (assq 'uuid |
|
121 |
(buck-get (format "/repositories/%s/%s" owner name) |
|
122 |
nil |
|
123 |
:username username :auth auth :host host))) |
|
124 |
1 -1)) |
|
125 |
|
|
126 |
;;; _ |
|
127 |
(provide 'buck) |
|
128 |
;;; buck.el ends here |