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 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
//! GitHub Actions use snafu::ResultExt; use crate::{params, Octocrab}; /// Handler for GitHub's actions API. /// /// Created with [`Octocrab::actions`]. pub struct ActionsHandler<'octo> { crab: &'octo Octocrab, } impl<'octo> ActionsHandler<'octo> { pub(crate) fn new(crab: &'octo Octocrab) -> Self { Self { crab } } /// Adds a repository to an organization secret when the visibility for /// repository access is set to selected. The visibility is set when you /// create or update an organization secret. You must authenticate using an /// access token with the admin:org scope to use this endpoint. GitHub Apps /// must have the secrets organization permission to use this endpoint. /// ```no_run /// # async fn run() -> octocrab::Result<()> { /// octocrab::instance() /// .actions() /// .add_selected_repo_to_org_secret("org", "secret_name", 1234) /// .await?; /// # Ok(()) /// # } /// ``` pub async fn add_selected_repo_to_org_secret( &self, org: impl AsRef<str>, secret_name: impl AsRef<str>, repository_id: u64, ) -> crate::Result<()> { let route = format!( "/orgs/{org}/actions/secrets/{secret_name}/repositories/{repository_id}", org = org.as_ref(), secret_name = secret_name.as_ref(), repository_id = repository_id, ); crate::map_github_error(self.crab._put(&route, None::<&()>).await?) .await .map(drop) } /// Removes a repository from an organization secret when the visibility for /// repository access is set to selected. The visibility is set when you /// create or update an organization secret. You must authenticate using an /// access token with the admin:org scope to use this endpoint. GitHub Apps /// must have the secrets organization permission to use this endpoint. /// ```no_run /// # async fn run() -> octocrab::Result<()> { /// octocrab::instance() /// .actions() /// .remove_selected_repo_from_org_secret("org", "secret_name", 1234) /// .await?; /// # Ok(()) /// # } /// ``` pub async fn remove_selected_repo_from_org_secret( &self, org: impl AsRef<str>, secret_name: impl AsRef<str>, repository_id: u64, ) -> crate::Result<()> { let route = format!( "/orgs/{org}/actions/secrets/{secret_name}/repositories/{repository_id}", org = org.as_ref(), secret_name = secret_name.as_ref(), repository_id = repository_id, ); crate::map_github_error(self.crab._delete(&route, None::<&()>).await?) .await .map(drop) } /// Cancels a workflow run using its id. You must authenticate using an /// access token with the `repo` scope to use this endpoint. GitHub Apps /// must have the `actions:write` permission to use this endpoint. /// ```no_run /// # async fn run() -> octocrab::Result<()> { /// octocrab::instance() /// .actions() /// .cancel_workflow_run("owner", "repo", 1234) /// .await?; /// # Ok(()) /// # } /// ``` pub async fn cancel_workflow_run( &self, owner: impl AsRef<str>, repo: impl AsRef<str>, run_id: u64, ) -> crate::Result<()> { let route = format!( "/repos/{owner}/{repo}/actions/runs/{run_id}/cancel", owner = owner.as_ref(), repo = repo.as_ref(), run_id = run_id, ); crate::map_github_error(self.crab._post(&route, None::<&()>).await?) .await .map(drop) } async fn follow_location_to_data( &self, response: reqwest::Response, ) -> crate::Result<bytes::Bytes> { let location = response .headers() .get(reqwest::header::LOCATION) .expect("No Location header found in download_workflow_run_logs") .to_str() .expect("Location URL not valid str"); self.crab ._get(location, None::<&()>) .await? .bytes() .await .context(crate::error::Http) } /// Downloads and returns the raw data representing a zip of the logs from /// the workflow run specified by `run_id`. /// ```no_run /// # async fn run() -> octocrab::Result<()> { /// octocrab::instance() /// .actions() /// .download_workflow_run_logs("owner", "repo", 1234) /// .await?; /// # Ok(()) /// # } /// ``` pub async fn download_workflow_run_logs( &self, owner: impl AsRef<str>, repo: impl AsRef<str>, run_id: u64, ) -> crate::Result<bytes::Bytes> { let route = format!( "/repos/{owner}/{repo}/actions/runs/{run_id}/logs", owner = owner.as_ref(), repo = repo.as_ref(), run_id = run_id, ); self.follow_location_to_data(self.crab._get(&route, None::<&()>).await?) .await } /// Downloads and returns the raw data representing an artifact from a /// repository. /// ```no_run /// # async fn run() -> octocrab::Result<()> { /// use octocrab::params::actions::ArchiveFormat; /// /// octocrab::instance() /// .actions() /// .download_artifact("owner", "repo", 1234, ArchiveFormat::Zip) /// .await?; /// # Ok(()) /// # } /// ``` pub async fn download_artifact( &self, owner: impl AsRef<str>, repo: impl AsRef<str>, artifact_id: u64, archive_format: params::actions::ArchiveFormat, ) -> crate::Result<bytes::Bytes> { let route = format!( "/repos/{owner}/{repo}/actions/artifacts/{artifact_id}/{archive_format}", owner = owner.as_ref(), repo = repo.as_ref(), artifact_id = artifact_id, archive_format = archive_format, ); self.follow_location_to_data(self.crab._get(&route, None::<&()>).await?) .await } /// Deletes all logs for a workflow run. You must authenticate using an /// access token with the `repo` scope to use this endpoint. GitHub Apps /// must have the `actions:write` permission to use this endpoint. /// ```no_run /// # async fn run() -> octocrab::Result<()> { /// octocrab::instance() /// .actions() /// .delete_workflow_run_logs("owner", "repo", 1234) /// .await?; /// # Ok(()) /// # } /// ``` pub async fn delete_workflow_run_logs( &self, owner: impl AsRef<str>, repo: impl AsRef<str>, run_id: u64, ) -> crate::Result<()> { let route = format!( "/repos/{owner}/{repo}/actions/runs/{run_id}/logs", owner = owner.as_ref(), repo = repo.as_ref(), run_id = run_id, ); crate::map_github_error(self.crab._delete(&route, None::<&()>).await?) .await .map(drop) } /// Get an organization's public key, which you need to encrypt secrets. /// You need to encrypt a secret before you can create or update secrets. /// You must authenticate using an access token with the `admin:org` scope /// to use this endpoint. GitHub Apps must have the secrets organization /// permission to use this endpoint. /// /// ```no_run /// # async fn run() -> octocrab::Result<()> { /// # let octocrab = octocrab::Octocrab::default(); /// let org = octocrab.actions().get_org_public_key("org").await?; /// # Ok(()) /// # } /// ``` pub async fn get_org_public_key( &self, org: impl AsRef<str>, ) -> crate::Result<crate::models::PublicKey> { let route = format!("/orgs/{org}/actions/secrets/public-key", org = org.as_ref()); self.crab.get(route, None::<&()>).await } } /* #[derive(serde::Serialize)] pub struct RenderMarkdownBuilder<'octo, 'r, 'text> { #[serde(skip)] handler: &'r ActionsHandler<'octo>, text: &'text str, mode: Option<crate::params::markdown::Mode>, context: Option<String>, } impl<'octo, 'r, 'text> RenderMarkdownBuilder<'octo, 'r, 'text> { pub(crate) fn new(handler: &'r ActionsHandler<'octo>, text: &'text str) -> Self { Self { handler, text, mode: None, context: None, } } /// The repository context to use when creating references in `Mode::Gfm`. /// Omit this parameter when using markdown mode. pub fn context<A: Into<String>>(mut self, context: impl Into<Option<A>>) -> Self { self.context = context.into().map(A::into); self } /// The rendering mode. pub fn mode(mut self, mode: impl Into<Option<crate::params::markdown::Mode>>) -> Self { self.mode = mode.into(); self } /// Send the actual request. pub async fn send(self) -> crate::Result<String> { self.handler .crab ._post(self.handler.crab.absolute_url("/markdown")?, Some(&self)) .await? .text() .await .context(crate::error::Http) } } #[cfg(test)] mod tests { #[test] fn serialize() { let octocrab = crate::instance(); let handler = octocrab.markdown(); let render = handler .render("**Markdown**") .mode(crate::params::markdown::Mode::Gfm) .context("owner/repo"); assert_eq!( serde_json::to_value(render).unwrap(), serde_json::json!({ "text": "**Markdown**", "mode": "gfm", "context": "owner/repo", }) ) } } */