Repository navigation
feat: Phase 5 full-repo review mode, revue integration, and dashboard actions #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| pub mod github; | ||
| pub mod ntfy; | ||
| pub mod revue; |
This file contains hidden or 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,75 @@ | ||
| use anyhow::{Context, Result}; | ||
| use reqwest::Url; | ||
| use std::sync::Arc; | ||
| use std::time::Duration; | ||
| use tokio::sync::Semaphore; | ||
| use tracing::{info, warn}; | ||
|
|
||
| const MAX_INFLIGHT_TRIGGERS: usize = 16; | ||
|
|
||
| #[derive(Clone)] | ||
| pub struct RevueClient { | ||
| client: reqwest::Client, | ||
| base_url: String, | ||
| token: Option<String>, | ||
| permits: Arc<Semaphore>, | ||
| } | ||
|
|
||
| fn is_loopback_host(host: &str) -> bool { | ||
| matches!(host, "localhost" | "127.0.0.1" | "::1" | "[::1]") | ||
| } | ||
|
|
||
| impl RevueClient { | ||
| pub fn new(base_url: String, token: Option<String>) -> Result<Self> { | ||
| let parsed = Url::parse(&base_url) | ||
| .with_context(|| format!("invalid CR_STEWARD_REVUE_URL: {base_url}"))?; | ||
| let host = parsed.host_str().unwrap_or(""); | ||
| match parsed.scheme() { | ||
| "https" => {} | ||
| "http" if is_loopback_host(host) => {} | ||
| scheme => anyhow::bail!( | ||
| "refusing non-HTTPS revue URL ({scheme}://{host}); HTTP is allowed only for loopback hosts" | ||
| ), | ||
| } | ||
| let client = reqwest::Client::builder() | ||
| .timeout(Duration::from_secs(15)) | ||
| .build()?; | ||
| Ok(Self { | ||
| client, | ||
| base_url: base_url.trim_end_matches('/').to_string(), | ||
| token, | ||
| permits: Arc::new(Semaphore::new(MAX_INFLIGHT_TRIGGERS)), | ||
| }) | ||
| } | ||
|
|
||
| /// Dispatch a non-blocking advisory review request to `revue` (`POST /api/trigger`). | ||
| /// Returns `true` if accepted for dispatch, `false` if dropped due to backpressure. | ||
| pub fn trigger_advisory_review(&self, repo: &str, pr_number: u64, reason: &str) -> bool { | ||
| let Ok(permit) = self.permits.clone().try_acquire_owned() else { | ||
| warn!(repo, pr_number, "dropping revue trigger: too many in-flight requests"); | ||
| return false; | ||
| }; | ||
| let client = self.client.clone(); | ||
| let url = format!("{}/api/trigger", self.base_url); | ||
| let token = self.token.clone(); | ||
| let repo = repo.to_string(); | ||
| let reason = reason.to_string(); | ||
|
|
||
| tokio::spawn(async move { | ||
| let _permit = permit; | ||
| let mut req = client.post(&url).json(&serde_json::json!({ | ||
| "repo": repo, | ||
| "pr": pr_number, | ||
| "reason": reason, | ||
| })); | ||
| if let Some(tok) = &token { | ||
| req = req.bearer_auth(tok); | ||
| } | ||
| match req.send().await.and_then(|r| r.error_for_status()) { | ||
| Ok(_) => info!(repo, pr_number, reason, "triggered advisory revue review"), | ||
| Err(err) => warn!(error = %err, repo, pr_number, reason, "failed to trigger revue"), | ||
| } | ||
| }); | ||
| true | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.