-
-
Notifications
You must be signed in to change notification settings - Fork 271
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Finalizing getting Code Scanning * Get back mistakelly deleted files * remove unused import * lint * remove legacy test * remove legacy test * Update Code Scanning alert (#3) * Update Code Scanning alert * Fix * Update Code Scanning alert
- Loading branch information
1 parent
ac28279
commit 8527406
Showing
4 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use super::*; | ||
|
||
#[derive(serde::Serialize)] | ||
pub struct UpdateCodeScanningBuilder<'octo, 'a> { | ||
#[serde(skip)] | ||
handler: &'a CodeScanningHandler<'octo>, | ||
#[serde(skip)] | ||
number: u64, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
state: Option<params::AlertState>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
dismissed_reason: Option<String>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
dismissed_comment: Option<String>, | ||
} | ||
|
||
impl<'octo, 'a, 'b, 'c> UpdateCodeScanningBuilder<'octo, 'a> { | ||
pub(crate) fn new(handler: &'a CodeScanningHandler<'octo>, number: u64) -> Self { | ||
Self { | ||
handler, | ||
number, | ||
state: None, | ||
dismissed_reason: None, | ||
dismissed_comment: None, | ||
} | ||
} | ||
|
||
/// The title of the code scanning. | ||
pub fn state(mut self, state: impl Into<params::AlertState>) -> Self { | ||
self.state = Some(state.into()); | ||
self | ||
} | ||
|
||
pub fn dismissed_reason(mut self, dismissed_reason: impl Into<String>) -> Self { | ||
self.dismissed_reason = Some(dismissed_reason.into()); | ||
self | ||
} | ||
|
||
pub fn dismissed_comment(mut self, dismissed_comment: impl Into<String>) -> Self { | ||
self.dismissed_comment = Some(dismissed_comment.into()); | ||
self | ||
} | ||
|
||
pub async fn send(self) -> Result<models::code_scannings::CodeScanningAlert> { | ||
let route = format!( | ||
"/repos/{owner}/{repo}/code-scanning/alerts/{code_scanning}", | ||
owner = self.handler.owner, | ||
repo = self.handler.repo.as_ref().expect("Repository is required"), | ||
code_scanning = self.number, | ||
); | ||
|
||
self.handler.crab.patch(route, Some(&self)).await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use wiremock::{ | ||
matchers::{method, path}, | ||
Mock, MockServer, ResponseTemplate, | ||
}; | ||
|
||
use mock_error::setup_error_handler; | ||
use octocrab::models::code_scannings::CodeScanningAlert; | ||
use octocrab::params::AlertState; | ||
use octocrab::Octocrab; | ||
|
||
mod mock_error; | ||
|
||
async fn setup_issue_check_assignee_api(template: ResponseTemplate) -> MockServer { | ||
let owner: &str = "org"; | ||
let repo: &str = "some-repo"; | ||
let number: &str = "1"; | ||
|
||
let mock_server = MockServer::start().await; | ||
|
||
Mock::given(method("PATCH")) | ||
.and(path(format!( | ||
"/repos/{owner}/{repo}/code-scanning/alerts/{number}", | ||
owner = owner, | ||
repo = repo | ||
))) | ||
.respond_with(template.clone()) | ||
.mount(&mock_server) | ||
.await; | ||
|
||
setup_error_handler( | ||
&mock_server, | ||
&format!("GET on /repos/{owner}/{repo}/code-scanning/alerts was not received"), | ||
) | ||
.await; | ||
mock_server | ||
} | ||
|
||
fn setup_octocrab(uri: &str) -> Octocrab { | ||
Octocrab::builder().base_uri(uri).unwrap().build().unwrap() | ||
} | ||
|
||
const OWNER: &str = "org"; | ||
const REPO: &str = "some-repo"; | ||
|
||
#[tokio::test] | ||
async fn check_patch_200() { | ||
let s = include_str!("resources/codescanning_alert_single.json"); | ||
let alert: CodeScanningAlert = serde_json::from_str(s).unwrap(); | ||
let template = ResponseTemplate::new(200).set_body_json(&alert); | ||
let mock_server = setup_issue_check_assignee_api(template).await; | ||
let client = setup_octocrab(&mock_server.uri()); | ||
|
||
let result = client | ||
.code_scannings(OWNER.to_owned(), REPO.to_owned()) | ||
.update(1) | ||
.state(AlertState::Open) | ||
.send() | ||
.await; | ||
|
||
assert!( | ||
result.is_ok(), | ||
"expected successful result, got error: {:#?}", | ||
result | ||
); | ||
} |