Skip to content

Commit 263b7df

Browse files
committed
Remove the RepositoryClient trait
1 parent bea2233 commit 263b7df

File tree

12 files changed

+106
-157
lines changed

12 files changed

+106
-157
lines changed

src/bors/context.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ use std::{
55

66
use crate::{bors::command::CommandParser, github::GithubRepoName, PgDbClient};
77

8-
use super::{RepositoryClient, RepositoryState};
8+
use super::RepositoryState;
99

10-
pub struct BorsContext<Client: RepositoryClient> {
10+
pub struct BorsContext {
1111
pub parser: CommandParser,
1212
pub db: Arc<PgDbClient>,
13-
pub repositories: RwLock<HashMap<GithubRepoName, Arc<RepositoryState<Client>>>>,
13+
pub repositories: RwLock<HashMap<GithubRepoName, Arc<RepositoryState>>>,
1414
}
1515

16-
impl<Client: RepositoryClient> BorsContext<Client> {
16+
impl BorsContext {
1717
pub fn new(
1818
parser: CommandParser,
1919
db: Arc<PgDbClient>,
20-
repositories: HashMap<GithubRepoName, Arc<RepositoryState<Client>>>,
20+
repositories: HashMap<GithubRepoName, Arc<RepositoryState>>,
2121
) -> Self {
2222
let repositories = RwLock::new(repositories);
2323
Self {

src/bors/handlers/help.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::sync::Arc;
22

33
use crate::bors::Comment;
4-
use crate::bors::RepositoryClient;
54
use crate::bors::RepositoryState;
65
use crate::github::PullRequest;
76

@@ -12,8 +11,8 @@ const HELP_MESSAGE: &str = r#"
1211
- help: Print this help message
1312
"#;
1413

15-
pub(super) async fn command_help<Client: RepositoryClient>(
16-
repo: Arc<RepositoryState<Client>>,
14+
pub(super) async fn command_help(
15+
repo: Arc<RepositoryState>,
1716
pr: &PullRequest,
1817
) -> anyhow::Result<()> {
1918
repo.client

src/bors/handlers/labels.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use itertools::Itertools;
22
use tracing::log;
33

4-
use crate::bors::{RepositoryClient, RepositoryState};
4+
use crate::bors::RepositoryState;
55
use crate::github::{LabelModification, LabelTrigger, PullRequestNumber};
66

77
/// If there are any label modifications that should be performed on the given PR when `trigger`
88
/// happens, this function will perform them.
9-
pub async fn handle_label_trigger<Client: RepositoryClient>(
10-
repo: &RepositoryState<Client>,
9+
pub async fn handle_label_trigger(
10+
repo: &RepositoryState,
1111
pr: PullRequestNumber,
1212
trigger: LabelTrigger,
1313
) -> anyhow::Result<()> {

src/bors/handlers/mod.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::bors::handlers::trybuild::{command_try_build, command_try_cancel, TRY
1212
use crate::bors::handlers::workflow::{
1313
handle_check_suite_completed, handle_workflow_completed, handle_workflow_started,
1414
};
15-
use crate::bors::{BorsContext, Comment, RepositoryClient, RepositoryLoader, RepositoryState};
15+
use crate::bors::{BorsContext, Comment, RepositoryLoader, RepositoryState};
1616
use crate::{PgDbClient, TeamApiClient};
1717

1818
#[cfg(test)]
@@ -29,9 +29,9 @@ mod workflow;
2929
pub static WAIT_FOR_WORKFLOW_STARTED: TestSyncMarker = TestSyncMarker::new();
3030

3131
/// This function executes a single BORS repository event
32-
pub async fn handle_bors_repository_event<Client: RepositoryClient>(
32+
pub async fn handle_bors_repository_event(
3333
event: BorsRepositoryEvent,
34-
ctx: Arc<BorsContext<Client>>,
34+
ctx: Arc<BorsContext>,
3535
) -> anyhow::Result<()> {
3636
let db = Arc::clone(&ctx.db);
3737
let Some(repo) = ctx
@@ -118,10 +118,10 @@ pub async fn handle_bors_repository_event<Client: RepositoryClient>(
118118
pub static WAIT_FOR_REFRESH: TestSyncMarker = TestSyncMarker::new();
119119

120120
/// This function executes a single BORS global event
121-
pub async fn handle_bors_global_event<Client: RepositoryClient>(
121+
pub async fn handle_bors_global_event(
122122
event: BorsGlobalEvent,
123-
ctx: Arc<BorsContext<Client>>,
124-
repo_loader: &dyn RepositoryLoader<Client>,
123+
ctx: Arc<BorsContext>,
124+
repo_loader: &dyn RepositoryLoader,
125125
team_api_client: &TeamApiClient,
126126
) -> anyhow::Result<()> {
127127
let db = Arc::clone(&ctx.db);
@@ -134,7 +134,7 @@ pub async fn handle_bors_global_event<Client: RepositoryClient>(
134134
}
135135
BorsGlobalEvent::Refresh => {
136136
let span = tracing::info_span!("Refresh");
137-
let repos: Vec<Arc<RepositoryState<Client>>> =
137+
let repos: Vec<Arc<RepositoryState>> =
138138
ctx.repositories.read().unwrap().values().cloned().collect();
139139
futures::future::join_all(repos.into_iter().map(|repo| {
140140
let repo = Arc::clone(&repo);
@@ -155,10 +155,10 @@ pub async fn handle_bors_global_event<Client: RepositoryClient>(
155155
Ok(())
156156
}
157157

158-
async fn handle_comment<Client: RepositoryClient>(
159-
repo: Arc<RepositoryState<Client>>,
158+
async fn handle_comment(
159+
repo: Arc<RepositoryState>,
160160
database: Arc<PgDbClient>,
161-
ctx: Arc<BorsContext<Client>>,
161+
ctx: Arc<BorsContext>,
162162
comment: PullRequestComment,
163163
) -> anyhow::Result<()> {
164164
let pr_number = comment.pr_number;
@@ -241,9 +241,9 @@ async fn handle_comment<Client: RepositoryClient>(
241241
Ok(())
242242
}
243243

244-
async fn reload_repos<Client: RepositoryClient>(
245-
ctx: Arc<BorsContext<Client>>,
246-
repo_loader: &dyn RepositoryLoader<Client>,
244+
async fn reload_repos(
245+
ctx: Arc<BorsContext>,
246+
repo_loader: &dyn RepositoryLoader,
247247
team_api_client: &TeamApiClient,
248248
) -> anyhow::Result<()> {
249249
let reloaded_repos = repo_loader.load_repositories(team_api_client).await?;

src/bors/handlers/ping.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
use std::sync::Arc;
22

33
use crate::bors::Comment;
4-
use crate::bors::RepositoryClient;
54
use crate::bors::RepositoryState;
65
use crate::github::PullRequest;
76

8-
pub(super) async fn command_ping<Client: RepositoryClient>(
9-
repo: Arc<RepositoryState<Client>>,
7+
pub(super) async fn command_ping(
8+
repo: Arc<RepositoryState>,
109
pr: &PullRequest,
1110
) -> anyhow::Result<()> {
1211
repo.client

src/bors/handlers/refresh.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ use chrono::{DateTime, Utc};
66

77
use crate::bors::handlers::trybuild::cancel_build_workflows;
88
use crate::bors::Comment;
9-
use crate::bors::{RepositoryClient, RepositoryState};
9+
use crate::bors::RepositoryState;
1010
use crate::database::BuildStatus;
1111
use crate::{PgDbClient, TeamApiClient};
1212

13-
pub async fn refresh_repository<Client: RepositoryClient>(
14-
repo: Arc<RepositoryState<Client>>,
13+
pub async fn refresh_repository(
14+
repo: Arc<RepositoryState>,
1515
db: Arc<PgDbClient>,
1616
team_api_client: &TeamApiClient,
1717
) -> anyhow::Result<()> {
@@ -28,10 +28,7 @@ pub async fn refresh_repository<Client: RepositoryClient>(
2828
}
2929
}
3030

31-
async fn cancel_timed_out_builds<Client: RepositoryClient>(
32-
repo: &RepositoryState<Client>,
33-
db: &PgDbClient,
34-
) -> anyhow::Result<()> {
31+
async fn cancel_timed_out_builds(repo: &RepositoryState, db: &PgDbClient) -> anyhow::Result<()> {
3532
let running_builds = db.get_running_builds(&repo.repository).await?;
3633
tracing::info!("Found {} running build(s)", running_builds.len());
3734

@@ -65,8 +62,8 @@ async fn cancel_timed_out_builds<Client: RepositoryClient>(
6562
Ok(())
6663
}
6764

68-
async fn reload_permission<Client: RepositoryClient>(
69-
repo: &RepositoryState<Client>,
65+
async fn reload_permission(
66+
repo: &RepositoryState,
7067
team_api_client: &TeamApiClient,
7168
) -> anyhow::Result<()> {
7269
let permissions = team_api_client
@@ -82,9 +79,7 @@ async fn reload_permission<Client: RepositoryClient>(
8279
Ok(())
8380
}
8481

85-
async fn reload_config<Client: RepositoryClient>(
86-
repo: &RepositoryState<Client>,
87-
) -> anyhow::Result<()> {
82+
async fn reload_config(repo: &RepositoryState) -> anyhow::Result<()> {
8883
let config = repo.client.load_config().await?;
8984
repo.config.store(Arc::new(config));
9085
Ok(())

src/bors/handlers/trybuild.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use anyhow::{anyhow, Context};
55
use crate::bors::command::Parent;
66
use crate::bors::handlers::labels::handle_label_trigger;
77
use crate::bors::Comment;
8-
use crate::bors::RepositoryClient;
98
use crate::bors::RepositoryState;
109
use crate::database::RunId;
1110
use crate::database::{BuildModel, BuildStatus, PullRequestModel, WorkflowStatus, WorkflowType};
@@ -29,8 +28,8 @@ pub(super) const TRY_BRANCH_NAME: &str = "automation/bors/try";
2928
///
3029
/// If `parent` is set, it will use it as a base commit for the merge.
3130
/// Otherwise, it will use the latest commit on the main repository branch.
32-
pub(super) async fn command_try_build<Client: RepositoryClient>(
33-
repo: Arc<RepositoryState<Client>>,
31+
pub(super) async fn command_try_build(
32+
repo: Arc<RepositoryState>,
3433
db: Arc<PgDbClient>,
3534
pr: &PullRequest,
3635
author: &GithubUser,
@@ -140,8 +139,8 @@ pub(super) async fn command_try_build<Client: RepositoryClient>(
140139
}
141140
}
142141

143-
pub(super) async fn command_try_cancel<Client: RepositoryClient>(
144-
repo: Arc<RepositoryState<Client>>,
142+
pub(super) async fn command_try_cancel(
143+
repo: Arc<RepositoryState>,
145144
db: Arc<PgDbClient>,
146145
pr: &PullRequest,
147146
author: &GithubUser,
@@ -209,8 +208,8 @@ Cancelled workflows:"#
209208
Ok(())
210209
}
211210

212-
pub async fn cancel_build_workflows<Client: RepositoryClient>(
213-
repo: &RepositoryState<Client>,
211+
pub async fn cancel_build_workflows(
212+
repo: &RepositoryState,
214213
db: &PgDbClient,
215214
build: &BuildModel,
216215
) -> anyhow::Result<Vec<RunId>> {
@@ -285,8 +284,8 @@ handled during merge and rebase. This is normal, and you should still perform st
285284
)
286285
}
287286

288-
async fn check_try_permissions<Client: RepositoryClient>(
289-
repo: &RepositoryState<Client>,
287+
async fn check_try_permissions(
288+
repo: &RepositoryState,
290289
pr: &PullRequest,
291290
author: &GithubUser,
292291
) -> anyhow::Result<bool> {

src/bors/handlers/workflow.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use crate::bors::comment::try_build_succeeded_comment;
44
use crate::bors::event::{CheckSuiteCompleted, WorkflowCompleted, WorkflowStarted};
55
use crate::bors::handlers::is_bors_observed_branch;
66
use crate::bors::handlers::labels::handle_label_trigger;
7+
use crate::bors::RepositoryState;
78
use crate::bors::{CheckSuiteStatus, Comment};
8-
use crate::bors::{RepositoryClient, RepositoryState};
99
use crate::database::{BuildStatus, WorkflowStatus};
1010
use crate::github::LabelTrigger;
1111
use crate::PgDbClient;
@@ -58,8 +58,8 @@ pub(super) async fn handle_workflow_started(
5858
Ok(())
5959
}
6060

61-
pub(super) async fn handle_workflow_completed<Client: RepositoryClient>(
62-
repo: Arc<RepositoryState<Client>>,
61+
pub(super) async fn handle_workflow_completed(
62+
repo: Arc<RepositoryState>,
6363
db: Arc<PgDbClient>,
6464
payload: WorkflowCompleted,
6565
) -> anyhow::Result<()> {
@@ -80,8 +80,8 @@ pub(super) async fn handle_workflow_completed<Client: RepositoryClient>(
8080
try_complete_build(repo.as_ref(), db.as_ref(), event).await
8181
}
8282

83-
pub(super) async fn handle_check_suite_completed<Client: RepositoryClient>(
84-
repo: Arc<RepositoryState<Client>>,
83+
pub(super) async fn handle_check_suite_completed(
84+
repo: Arc<RepositoryState>,
8585
db: Arc<PgDbClient>,
8686
payload: CheckSuiteCompleted,
8787
) -> anyhow::Result<()> {
@@ -98,8 +98,8 @@ pub(super) async fn handle_check_suite_completed<Client: RepositoryClient>(
9898
}
9999

100100
/// Try to complete a pending build.
101-
async fn try_complete_build<Client: RepositoryClient>(
102-
repo: &RepositoryState<Client>,
101+
async fn try_complete_build(
102+
repo: &RepositoryState,
103103
db: &PgDbClient,
104104
payload: CheckSuiteCompleted,
105105
) -> anyhow::Result<()> {

0 commit comments

Comments
 (0)