-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #21 - troy/auto-try, r=<dry>
add auto-try feature Adds an ability to specify an auto-try feature Requested-by: ScuffleCloud <[email protected]>
- Loading branch information
Showing
17 changed files
with
295 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TABLE github_pr DROP COLUMN auto_try; |
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 @@ | ||
ALTER TABLE github_pr ADD COLUMN auto_try BOOLEAN NOT NULL DEFAULT FALSE; |
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
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,67 @@ | ||
use diesel_async::{AsyncPgConnection, RunQueryDsl}; | ||
|
||
use super::BrawlCommandContext; | ||
use crate::database::pr::Pr; | ||
use crate::github::messages; | ||
use crate::github::models::PullRequest; | ||
use crate::github::repo::GitHubRepoClient; | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq)] | ||
pub struct AutoTryCommand { | ||
pub force: bool, | ||
pub disable: bool, | ||
} | ||
|
||
pub async fn handle<R: GitHubRepoClient>( | ||
conn: &mut AsyncPgConnection, | ||
context: BrawlCommandContext<'_, R>, | ||
command: AutoTryCommand, | ||
) -> anyhow::Result<()> { | ||
let pr = context.repo.get_pull_request(context.pr_number).await?; | ||
handle_with_pr(conn, pr, context, command).await | ||
} | ||
|
||
async fn handle_with_pr<R: GitHubRepoClient>( | ||
conn: &mut AsyncPgConnection, | ||
pr: PullRequest, | ||
context: BrawlCommandContext<'_, R>, | ||
command: AutoTryCommand, | ||
) -> anyhow::Result<()> { | ||
if !context.repo.config().enabled { | ||
return Ok(()); | ||
} | ||
|
||
if !context.repo.can_try(context.user.id).await? { | ||
tracing::debug!("user does not have permission to do this"); | ||
return Ok(()); | ||
} | ||
|
||
let db_pr = Pr::find(context.repo.id(), context.pr_number).get_result(conn).await?; | ||
|
||
match (command.disable, db_pr.auto_try) { | ||
(true, true) => { | ||
db_pr.update().auto_try(false).build().query().execute(conn).await?; | ||
|
||
context | ||
.repo | ||
.send_message(context.pr_number, &messages::auto_try_disabled()) | ||
.await?; | ||
} | ||
(false, false) => { | ||
if !command.force && pr.head.repo.is_none_or(|r| r.id != context.repo.id()) { | ||
context.repo.send_message(context.pr_number, &messages::error_no_body("This PR is not from this repository, so auto-try cannot be enabled. To bypass this check, use force `?brawl auto-try force`")).await?; | ||
return Ok(()); | ||
} | ||
|
||
db_pr.update().auto_try(true).build().query().execute(conn).await?; | ||
|
||
context | ||
.repo | ||
.send_message(context.pr_number, &messages::auto_try_enabled()) | ||
.await?; | ||
} | ||
(_, _) => {} | ||
} | ||
|
||
Ok(()) | ||
} |
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
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
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
Oops, something went wrong.