Skip to content

Commit

Permalink
github testing
Browse files Browse the repository at this point in the history
  • Loading branch information
TroyKomodo committed Dec 21, 2024
1 parent d22a5bd commit e48e299
Show file tree
Hide file tree
Showing 38 changed files with 2,994 additions and 498 deletions.
71 changes: 69 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ toml = "0.8.19"
thiserror = "2.0.6"
uuid = "1.5.0"
bon = "3.3"
arc-swap = "1.6.0"

[dev-dependencies]
insta = "1.2.0"
insta = { version = "1.41.1", features = ["filters"] }
sqlformat = "0.3.3"
tower-test = "0.4.0"
http = "1.0.0"
rand = "0.8.5"
http-body-util = "0.1.0"
bytes = "1.8.0"
5 changes: 3 additions & 2 deletions server/src/auto_start.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::collections::HashMap;
use std::ops::DerefMut;
use std::sync::Arc;

use anyhow::Context;
use diesel_async::{AsyncPgConnection, RunQueryDsl};
Expand All @@ -19,7 +20,7 @@ pub trait AutoStartConfig: Send + Sync + 'static {
fn repo_client(
&self,
repo_id: RepositoryId,
) -> impl std::future::Future<Output = anyhow::Result<Option<Self::RepoClient>>> + Send;
) -> impl std::future::Future<Output = anyhow::Result<Option<Arc<Self::RepoClient>>>> + Send;

fn database(
&self,
Expand Down Expand Up @@ -65,7 +66,7 @@ impl<C: AutoStartConfig> scuffle_bootstrap::Service<C> for AutoStartSvc {
continue;
};

if let Err(e) = handle_run(run, &repo_client, &mut conn).await {
if let Err(e) = handle_run(run, repo_client.as_ref(), &mut conn).await {
tracing::error!(
"error handling run (repo id: {}, pr number: {}, run id: {}): {}",
run.github_repo_id,
Expand Down
10 changes: 4 additions & 6 deletions server/src/bin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use scuffle_bootstrap_telemetry::opentelemetry_sdk::metrics::SdkMeterProvider;
use scuffle_bootstrap_telemetry::opentelemetry_sdk::Resource;
use scuffle_bootstrap_telemetry::prometheus_client::registry::Registry;
use scuffle_brawl::database::schema::health_check;
use scuffle_brawl::github::installation::{GitHubInstallationClient, InstallationClient};
use scuffle_brawl::github::installation::InstallationClient;
use scuffle_brawl::github::repo::RepoClient;
use scuffle_brawl::github::GitHubService;
use scuffle_metrics::opentelemetry::KeyValue;
Expand Down Expand Up @@ -164,8 +164,6 @@ impl scuffle_bootstrap_telemetry::TelemetryConfig for Global {
}

impl scuffle_brawl::webhook::WebhookConfig for Global {
type InstallationClient = Arc<InstallationClient>;

fn bind_address(&self) -> Option<SocketAddr> {
Some(self.config.github.webhook_bind)
}
Expand All @@ -174,7 +172,7 @@ impl scuffle_brawl::webhook::WebhookConfig for Global {
&self.config.github.webhook_secret
}

fn installation_client(&self, installation_id: InstallationId) -> Option<Self::InstallationClient> {
fn installation_client(&self, installation_id: InstallationId) -> Option<Arc<InstallationClient>> {
self.github_service.get_client(installation_id)
}

Expand Down Expand Up @@ -210,12 +208,12 @@ impl scuffle_brawl::auto_start::AutoStartConfig for Global {
Ok(conn)
}

async fn repo_client(&self, repo_id: octocrab::models::RepositoryId) -> anyhow::Result<Option<Self::RepoClient>> {
async fn repo_client(&self, repo_id: octocrab::models::RepositoryId) -> anyhow::Result<Option<Arc<RepoClient>>> {
let Some(client) = self.github_service.get_client_by_repo(repo_id) else {
return Ok(None);
};

let Some(repo) = client.get_repository(repo_id).await? else {
let Some(repo) = client.get_repo_client(repo_id) else {
return Ok(None);
};

Expand Down
11 changes: 4 additions & 7 deletions server/src/command/cancel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ pub mod tests {
&mut conn,
BrawlCommandContext {
repo: &client,
pr: Arc::new(pr),
pr,
user: User {
id: UserId(1),
login: "test".to_string(),
Expand Down Expand Up @@ -239,10 +239,7 @@ pub mod tests {
&mut conn,
BrawlCommandContext {
repo: &client,
pr: Arc::new(PullRequest {
number: 2,
..Default::default()
}),
pr,
user: User {
id: UserId(2),
login: "test".to_string(),
Expand Down Expand Up @@ -338,7 +335,7 @@ pub mod tests {
&mut conn,
BrawlCommandContext {
repo: &client,
pr: Arc::new(pr),
pr,
user: User {
id: UserId(3),
login: "test".to_string(),
Expand Down Expand Up @@ -389,7 +386,7 @@ pub mod tests {
&mut conn,
BrawlCommandContext {
repo: &client,
pr: Arc::new(pr),
pr,
user: User {
id: UserId(4),
login: "test".to_string(),
Expand Down
31 changes: 16 additions & 15 deletions server/src/command/dry_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::database::pr::Pr;
use crate::github::merge_workflow::GitHubMergeWorkflow;
use crate::github::messages;
use crate::github::repo::GitHubRepoClient;
use crate::utils::format_fn;

#[derive(Debug, PartialEq, Eq)]
pub struct DryRunCommand {
Expand All @@ -31,7 +32,7 @@ pub async fn handle<R: GitHubRepoClient>(
}

if let Some(base_sha) = &mut command.base_sha {
let Some(base_commit) = context.repo.get_commit_by_sha(base_sha).await.context("get base commit")? else {
let Some(base_commit) = context.repo.get_commit(base_sha).await.context("get base commit")? else {
context
.repo
.send_message(
Expand All @@ -46,7 +47,7 @@ pub async fn handle<R: GitHubRepoClient>(
}

if let Some(head_sha) = &mut command.head_sha {
let Some(head_commit) = context.repo.get_commit_by_sha(head_sha).await.context("get head commit")? else {
let Some(head_commit) = context.repo.get_commit(head_sha).await.context("get head commit")? else {
context
.repo
.send_message(
Expand Down Expand Up @@ -86,7 +87,7 @@ pub async fn handle<R: GitHubRepoClient>(
.repo
.send_message(
context.pr.number,
&messages::error_no_body(messages::format_fn(|f| {
&messages::error_no_body(format_fn(|f| {
write!(
f,
"This PR already has a active merge {}",
Expand Down Expand Up @@ -252,7 +253,7 @@ mod tests {
&mut conn,
BrawlCommandContext {
repo: &client,
pr: Arc::new(pr),
pr,
user: User {
id: UserId(3),
login: "test".to_string(),
Expand Down Expand Up @@ -341,7 +342,7 @@ mod tests {
&mut conn,
BrawlCommandContext {
repo: &client,
pr: Arc::new(pr),
pr,
user: User {
id: UserId(3),
login: "test".to_string(),
Expand Down Expand Up @@ -443,7 +444,7 @@ mod tests {
&mut conn,
BrawlCommandContext {
repo: &client,
pr: Arc::new(pr),
pr,
user: User {
id: UserId(3),
login: "test".to_string(),
Expand Down Expand Up @@ -530,7 +531,7 @@ mod tests {
&mut conn,
BrawlCommandContext {
repo: &client,
pr: Arc::new(pr),
pr,
user: User {
id: UserId(3),
login: "test".to_string(),
Expand Down Expand Up @@ -561,7 +562,7 @@ mod tests {
}

match rx.recv().await.unwrap() {
MockRepoAction::GetCommitBySha { sha, result } => {
MockRepoAction::GetCommit { sha, result } => {
assert_eq!(sha, "base");
result
.send(Ok(Some(Commit {
Expand All @@ -574,7 +575,7 @@ mod tests {
}

match rx.recv().await.unwrap() {
MockRepoAction::GetCommitBySha { sha, result } => {
MockRepoAction::GetCommit { sha, result } => {
assert_eq!(sha, "head");
result
.send(Ok(Some(Commit {
Expand Down Expand Up @@ -629,7 +630,7 @@ mod tests {
&mut conn,
BrawlCommandContext {
repo: &client,
pr: Arc::new(pr),
pr,
user: User {
id: UserId(3),
login: "test".to_string(),
Expand Down Expand Up @@ -660,7 +661,7 @@ mod tests {
}

match rx.recv().await.unwrap() {
MockRepoAction::GetCommitBySha { sha, result } => {
MockRepoAction::GetCommit { sha, result } => {
assert_eq!(sha, "head");
result.send(Ok(None)).unwrap();
}
Expand Down Expand Up @@ -718,7 +719,7 @@ mod tests {
&mut conn,
BrawlCommandContext {
repo: &client,
pr: Arc::new(pr),
pr,
user: User {
id: UserId(3),
login: "test".to_string(),
Expand Down Expand Up @@ -749,7 +750,7 @@ mod tests {
}

match rx.recv().await.unwrap() {
MockRepoAction::GetCommitBySha { sha, result } => {
MockRepoAction::GetCommit { sha, result } => {
assert_eq!(sha, "base");
result.send(Ok(None)).unwrap();
}
Expand Down Expand Up @@ -800,7 +801,7 @@ mod tests {
&mut conn,
BrawlCommandContext {
repo: &client,
pr: Arc::new(pr),
pr,
user: User {
id: UserId(3),
login: "test".to_string(),
Expand Down Expand Up @@ -857,7 +858,7 @@ mod tests {
&mut conn,
BrawlCommandContext {
repo: &client,
pr: Arc::new(pr),
pr,
user: User {
id: UserId(3),
login: "test".to_string(),
Expand Down
Loading

0 comments on commit e48e299

Please sign in to comment.