aboutsummaryrefslogtreecommitdiff
path: root/buildbot-client.el
blob: a681583dd4ebb8bbe4db1b587aac547530ae822f (plain) (blame)
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
;;; buildbot-client.el --- Client code using buildbot api -*- lexical-binding: t; -*-

;; Copyright (C) 2023  Free Software Foundation, Inc.
;;
;; This file is part of buildbot.el.
;;
;; buildbot.el is free software: you can redistribute it and/or modify
;; it under the terms of the GNU Affero General Public License as
;; published by the Free Software Foundation, either version 3 of the
;; License, or (at your option) any later version.
;;
;; buildbot.el 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
;; Affero General Public License for more details.
;;
;; You should have received a copy of the GNU Affero General Public
;; License along with buildbot.el. If not, see
;; <https://www.gnu.org/licenses/>.

;;; Commentary:

;; buildbot-client provides functions for buildbot.el to get stuff
;; from a buildbot server.

;;; Code:
(require 'buildbot-utils)

(defvar buildbot-host nil "Buildbot instance host")
(defvar buildbot-builders nil
  "Buildbot builders. Can be generated with (buildbot-get-all-builders)")

(defun buildbot-api-change (attr)
  (buildbot-url-fetch-json
   (format
    "%s/api/v2/changes?%s"
    buildbot-host (buildbot-format-attr attr))))

(defun buildbot-api-logs (stepid)
  (buildbot-url-fetch-json
   (format
    "%s/api/v2/steps/%d/logs"
    buildbot-host stepid)))

(defun buildbot-api-builders ()
  (buildbot-url-fetch-json
   (format
    "%s/api/v2/builders"
    buildbot-host)))

(defun buildbot-api-builders-builds (builder-id attr)
  (buildbot-url-fetch-json
   (format
    "%s/api/v2/builders/%d/builds?%s"
    buildbot-host builder-id (buildbot-format-attr attr))))

(defun buildbot-api-build (attr)
  (buildbot-url-fetch-json
   (format
    "%s/api/v2/builds?%s"
    buildbot-host (buildbot-format-attr attr))))

(defun buildbot-api-step (buildid)
  (buildbot-url-fetch-json
   (format
    "%s/api/v2/builds/%s/steps"
    buildbot-host buildid)))

(defun buildbot-api-log-raw (logid)
  (buildbot-url-fetch-raw
   (format "%s/api/v2/logs/%d/raw" buildbot-host logid)))

(defun buildbot-get-recent-builds-by-builder (builder-id limit)
  (alist-get 'builds
             (buildbot-api-builders-builds
              builder-id
              `((limit . ,limit) (order . "-number") (property . "revision")))))

(defun buildbot-get-recent-changes (limit)
  (buildbot-api-change (list (cons 'order "-changeid") (cons 'limit limit))))

(defun buildbot-get-all-builders ()
  (alist-get 'builders (buildbot-api-builders)))

(defun buildbot-builder-by-id (builderid)
  (cl-find-if
   (lambda (builder)
     (= (alist-get 'builderid builder) builderid))
   buildbot-builders))

(defun buildbot-builder-by-name (name)
  (cl-find-if
   (lambda (builder)
     (equal (alist-get 'name builder) name))
   buildbot-builders))

(defun buildbot-get-logs-by-stepid (stepid)
  (alist-get 'logs (buildbot-api-logs stepid)))

(defun buildbot-get-builder-name-by-id (id)
  (alist-get 'name (buildbot-builder-by-id id)))

(defun buildbot-get-changes-by-revision (revision)
  (alist-get 'changes
             (buildbot-api-change (list (cons 'revision revision)))))

(defun buildbot-get-build-by-buildid (buildid)
  (buildbot-api-build (list (cons 'buildid buildid))))

(defun buildbot-get-steps-by-buildid (buildid)
  (alist-get 'steps (buildbot-api-step buildid)))

(defun buildbot-get-changes-by-branch (branch-name limit)
  (alist-get 'changes
             (buildbot-api-change
              (cons `(branch . ,branch-name)
                    (when limit `((limit . ,limit)))))))

(provide 'buildbot-client)