Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .github/brawl.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
enabled = true

branches = [
"main",
]

merge_permissions = [
"role:write",
]
Expand Down
10 changes: 7 additions & 3 deletions server/src/command/dry_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ async fn handle_with_pr<R: GitHubRepoClient>(
context: BrawlCommandContext<'_, R>,
mut command: DryRunCommand,
) -> anyhow::Result<()> {
if !context.repo.config().enabled {
let Some(config) = context.repo.config().await? else {
return Ok(());
};

if !config.enabled {
return Ok(());
}

Expand Down Expand Up @@ -92,7 +96,7 @@ async fn handle_with_pr<R: GitHubRepoClient>(
.map(Base::from_sha)
.unwrap_or_else(|| Base::from_pr(&pr));

let branch = context.repo.config().try_branch(pr.number);
let branch = config.try_branch(pr.number);

let db_pr = Pr::new(&pr, context.user.id, context.repo.id())
.upsert()
Expand Down Expand Up @@ -920,7 +924,7 @@ mod tests {

let pr = PullRequest {
number: 1,
merged_at: Some(Utc::now().into()),
merged_at: Some(Utc::now()),
..Default::default()
};

Expand Down
8 changes: 6 additions & 2 deletions server/src/command/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ async fn handle_with_pr<R: GitHubRepoClient>(
context: BrawlCommandContext<'_, R>,
command: MergeCommand,
) -> anyhow::Result<()> {
if !context.repo.config().enabled {
let Some(config) = context.repo.config().await? else {
return Ok(());
};

if !config.enabled {
return Ok(());
}

Expand Down Expand Up @@ -110,7 +114,7 @@ async fn handle_with_pr<R: GitHubRepoClient>(
let run = CiRun::insert(context.repo.id(), pr.number)
.base_ref(Base::from_pr(&pr))
.head_commit_sha(pr.head.sha.as_str().into())
.ci_branch(context.repo.config().merge_branch(&pr.base.ref_field).into())
.ci_branch(config.merge_branch(&pr.base.ref_field).into())
.maybe_priority(command.priority.or(db_pr.default_priority))
.requested_by_id(context.user.id.0 as i64)
.approved_by_ids(reviewer_ids)
Expand Down
10 changes: 8 additions & 2 deletions server/src/command/ping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ pub async fn handle<R: GitHubRepoClient>(
_: &mut AsyncPgConnection,
context: BrawlCommandContext<'_, R>,
) -> anyhow::Result<()> {
let config = context.repo.config().await?;

// Should we also say what permissions the user has?
context
.repo
.send_message(
context.pr_number,
&messages::pong(
context.user.login,
if context.repo.config().enabled {
if config.is_some_and(|c| c.enabled) {
"enabled"
} else {
"disabled"
Expand All @@ -35,6 +37,7 @@ mod tests {
use super::*;
use crate::command::BrawlCommand;
use crate::database::get_test_connection;
use crate::github::config::GitHubBrawlRepoConfig;
use crate::github::merge_workflow::GitHubMergeWorkflow;
use crate::github::models::User;
use crate::github::repo::test_utils::{MockRepoAction, MockRepoClient};
Expand Down Expand Up @@ -87,7 +90,10 @@ mod tests {
let mut conn = get_test_connection().await;
let (mut client, mut rx) = MockRepoClient::new(MockMergeWorkFlow);

client.config.enabled = false;
client.config = Some(GitHubBrawlRepoConfig {
enabled: false,
..Default::default()
});

tokio::spawn(async move {
handle(
Expand Down
4 changes: 3 additions & 1 deletion server/src/command/retry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ async fn handle_with_pr<R: GitHubRepoClient>(
pr: PullRequest,
context: BrawlCommandContext<'_, R>,
) -> anyhow::Result<()> {
if !context.repo.config().enabled {
let config = context.repo.config().await?;

if !config.is_some_and(|c| c.enabled) {
return Ok(());
}

Expand Down
25 changes: 2 additions & 23 deletions server/src/github/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ use std::str::FromStr;
use serde::{Deserialize, Deserializer, Serialize, Serializer};

#[derive(Debug, Deserialize, Serialize, Clone, smart_default::SmartDefault)]
#[serde(default)]
#[serde(default, deny_unknown_fields)]
pub struct GitHubBrawlRepoConfig {
/// Whether Brawl is enabled for this repo
#[default(true)]
pub enabled: bool,
/// Labels to attach to PRs on different states
pub labels: GitHubBrawlLabelsConfig,
/// The target branches that this queue matches against.
pub branches: Vec<String>,
/// The branch prefix for @brawl try commands
/// (default: "automation/brawl/try/")
#[default("automation/brawl/try/")]
Expand Down Expand Up @@ -59,13 +57,6 @@ pub struct GitHubBrawlRepoConfig {
}

impl GitHubBrawlRepoConfig {
pub fn missing() -> Self {
Self {
enabled: false,
..Default::default()
}
}

pub fn try_permissions(&self) -> &[Permission] {
self.try_permissions.as_ref().unwrap_or(&self.merge_permissions)
}
Expand All @@ -88,7 +79,7 @@ impl GitHubBrawlRepoConfig {
}

#[derive(Debug, Deserialize, Serialize, Clone, smart_default::SmartDefault)]
#[serde(default)]
#[serde(default, deny_unknown_fields)]
pub struct GitHubBrawlLabelsConfig {
/// The label to attach to PRs when they are in the merge queue
#[serde(skip_serializing_if = "Vec::is_empty", deserialize_with = "string_or_vec")]
Expand Down Expand Up @@ -314,19 +305,12 @@ mod tests {
);
}

#[test]
fn test_missing_disabled() {
let config = GitHubBrawlRepoConfig::missing();
assert!(!config.enabled);
}

#[test]
fn test_default_config() {
let config = GitHubBrawlRepoConfig::default();
let s = toml::to_string_pretty(&config).unwrap();
insta::assert_snapshot!(s, @r#"
enabled = true
branches = []
try_branch_prefix = "automation/brawl/try/"
merge_branch_prefix = "automation/brawl/merge/"
temp_branch_prefix = "automation/brawl/temp/"
Expand All @@ -343,10 +327,6 @@ mod tests {
fn test_config_deserialize() {
let config = r#"
enabled = true
branches = [
"main",
"staging",
]
try_branch_prefix = "automation/brawl/try/"
merge_branch_prefix = "automation/brawl/merge/"
temp_branch_prefix = "automation/brawl/temp/"
Expand All @@ -366,7 +346,6 @@ mod tests {

let config: GitHubBrawlRepoConfig = toml::from_str(config).unwrap();
assert!(config.enabled);
assert_eq!(config.branches, vec!["main", "staging"]);
assert_eq!(config.try_branch_prefix, "automation/brawl/try/");
assert_eq!(config.merge_branch_prefix, "automation/brawl/merge/");
assert_eq!(config.temp_branch_prefix, "automation/brawl/temp/");
Expand Down
Loading