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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
use crate::models::actions::{HostedRunnersResponse, RunnerGroup, RunnerGroupsResponse};
use crate::models::RunnerGroupId;
use crate::{Octocrab, Result};
use serde::Serialize;
/// Handler for GitHub Actions Runner Groups for an organization.
pub struct OrgRunnerGroupsHandler<'octo> {
crab: &'octo Octocrab,
org: String,
}
impl<'octo> OrgRunnerGroupsHandler<'octo> {
pub(crate) fn new(crab: &'octo Octocrab, org: String) -> Self {
Self { crab, org }
}
/// List self-hosted runner groups for an organization.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/actions/self-hosted-runner-groups?apiVersion=2022-11-28#list-self-hosted-runner-groups-for-an-organization)
pub async fn list(&self) -> Result<RunnerGroupsResponse> {
let route = format!("/orgs/{}/actions/runner-groups", self.org);
self.crab.get(route, None::<&()>).await
}
/// Create a self-hosted runner group for an organization.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/actions/self-hosted-runner-groups?apiVersion=2022-11-28#create-a-self-hosted-runner-group-for-an-organization)
pub async fn create(&self, body: &impl Serialize) -> Result<RunnerGroup> {
let route = format!("/orgs/{}/actions/runner-groups", self.org);
self.crab.post(route, Some(body)).await
}
/// Get a self-hosted runner group for an organization.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/actions/self-hosted-runner-groups?apiVersion=2022-11-28#get-a-self-hosted-runner-group-for-an-organization)
pub async fn get(&self, runner_group_id: impl Into<RunnerGroupId>) -> Result<RunnerGroup> {
let route = format!(
"/orgs/{}/actions/runner-groups/{}",
self.org,
runner_group_id.into()
);
self.crab.get(route, None::<&()>).await
}
/// Update a self-hosted runner group for an organization.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/actions/self-hosted-runner-groups?apiVersion=2022-11-28#update-a-self-hosted-runner-group-for-an-organization)
pub async fn update(
&self,
runner_group_id: impl Into<RunnerGroupId>,
body: &impl Serialize,
) -> Result<RunnerGroup> {
let route = format!(
"/orgs/{}/actions/runner-groups/{}",
self.org,
runner_group_id.into()
);
self.crab.patch(route, Some(body)).await
}
/// Delete a self-hosted runner group from an organization.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/actions/self-hosted-runner-groups?apiVersion=2022-11-28#delete-a-self-hosted-runner-group-from-an-organization)
pub async fn delete(&self, runner_group_id: impl Into<RunnerGroupId>) -> Result<()> {
let route = format!(
"/orgs/{}/actions/runner-groups/{}",
self.org,
runner_group_id.into()
);
let response = self.crab._delete(route, None::<&()>).await?;
if !response.status().is_success() {
return Err(crate::map_github_error(response).await.unwrap_err());
}
Ok(())
}
/// List GitHub-hosted runners in a group for an organization.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/actions/self-hosted-runner-groups?apiVersion=2022-11-28#list-github-hosted-runners-in-a-group-for-an-organization)
pub async fn list_hosted_runners(
&self,
runner_group_id: impl Into<RunnerGroupId>,
) -> Result<HostedRunnersResponse> {
let route = format!(
"/orgs/{}/actions/runner-groups/{}/hosted-runners",
self.org,
runner_group_id.into()
);
self.crab.get(route, None::<&()>).await
}
/// List repository access to a self-hosted runner group in an organization.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/actions/self-hosted-runner-groups?apiVersion=2022-11-28#list-repository-access-to-a-self-hosted-runner-group-in-an-organization)
pub async fn list_repositories(
&self,
runner_group_id: impl Into<RunnerGroupId>,
) -> Result<serde_json::Value> {
let route = format!(
"/orgs/{}/actions/runner-groups/{}/repositories",
self.org,
runner_group_id.into()
);
self.crab.get(route, None::<&()>).await
}
/// Set repository access for a self-hosted runner group in an organization.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/actions/self-hosted-runner-groups?apiVersion=2022-11-28#set-repository-access-for-a-self-hosted-runner-group-in-an-organization)
pub async fn set_repositories(
&self,
runner_group_id: impl Into<RunnerGroupId>,
body: &impl Serialize,
) -> Result<()> {
let route = format!(
"/orgs/{}/actions/runner-groups/{}/repositories",
self.org,
runner_group_id.into()
);
let response = self.crab._put(route, Some(body)).await?;
if !response.status().is_success() {
return Err(crate::map_github_error(response).await.unwrap_err());
}
Ok(())
}
/// Add repository access to a self-hosted runner group in an organization.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/actions/self-hosted-runner-groups?apiVersion=2022-11-28#add-repository-access-to-a-self-hosted-runner-group-in-an-organization)
pub async fn add_repository(
&self,
runner_group_id: impl Into<RunnerGroupId>,
repository_id: u64,
) -> Result<()> {
let route = format!(
"/orgs/{}/actions/runner-groups/{}/repositories/{}",
self.org,
runner_group_id.into(),
repository_id
);
let response = self.crab._put(route, None::<&()>).await?;
if !response.status().is_success() {
return Err(crate::map_github_error(response).await.unwrap_err());
}
Ok(())
}
/// Remove repository access to a self-hosted runner group in an organization.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/actions/self-hosted-runner-groups?apiVersion=2022-11-28#remove-repository-access-to-a-self-hosted-runner-group-in-an-organization)
pub async fn remove_repository(
&self,
runner_group_id: impl Into<RunnerGroupId>,
repository_id: u64,
) -> Result<()> {
let route = format!(
"/orgs/{}/actions/runner-groups/{}/repositories/{}",
self.org,
runner_group_id.into(),
repository_id
);
let response = self.crab._delete(route, None::<&()>).await?;
if !response.status().is_success() {
return Err(crate::map_github_error(response).await.unwrap_err());
}
Ok(())
}
/// List self-hosted runners in a group for an organization.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/actions/self-hosted-runner-groups?apiVersion=2022-11-28#list-self-hosted-runners-in-a-group-for-an-organization)
pub async fn list_runners(
&self,
runner_group_id: impl Into<RunnerGroupId>,
) -> Result<serde_json::Value> {
let route = format!(
"/orgs/{}/actions/runner-groups/{}/runners",
self.org,
runner_group_id.into()
);
self.crab.get(route, None::<&()>).await
}
/// Set self-hosted runners in a group for an organization.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/actions/self-hosted-runner-groups?apiVersion=2022-11-28#set-self-hosted-runners-in-a-group-for-an-organization)
pub async fn set_runners(
&self,
runner_group_id: impl Into<RunnerGroupId>,
body: &impl Serialize,
) -> Result<()> {
let route = format!(
"/orgs/{}/actions/runner-groups/{}/runners",
self.org,
runner_group_id.into()
);
let response = self.crab._put(route, Some(body)).await?;
if !response.status().is_success() {
return Err(crate::map_github_error(response).await.unwrap_err());
}
Ok(())
}
/// Add a self-hosted runner to a group for an organization.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/actions/self-hosted-runner-groups?apiVersion=2022-11-28#add-a-self-hosted-runner-to-a-group-for-an-organization)
pub async fn add_runner(
&self,
runner_group_id: impl Into<RunnerGroupId>,
runner_id: u64,
) -> Result<()> {
let route = format!(
"/orgs/{}/actions/runner-groups/{}/runners/{}",
self.org,
runner_group_id.into(),
runner_id
);
let response = self.crab._put(route, None::<&()>).await?;
if !response.status().is_success() {
return Err(crate::map_github_error(response).await.unwrap_err());
}
Ok(())
}
/// Remove a self-hosted runner from a group for an organization.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/actions/self-hosted-runner-groups?apiVersion=2022-11-28#remove-a-self-hosted-runner-from-a-group-for-an-organization)
pub async fn remove_runner(
&self,
runner_group_id: impl Into<RunnerGroupId>,
runner_id: u64,
) -> Result<()> {
let route = format!(
"/orgs/{}/actions/runner-groups/{}/runners/{}",
self.org,
runner_group_id.into(),
runner_id
);
let response = self.crab._delete(route, None::<&()>).await?;
if !response.status().is_success() {
return Err(crate::map_github_error(response).await.unwrap_err());
}
Ok(())
}
}