Skip to content

Commit 98fe9aa

Browse files
refactor: attach repo name to event
1 parent 0eb786e commit 98fe9aa

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

src/bors/event.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ pub enum BorsRepositoryEvent {
1515
CheckSuiteCompleted(CheckSuiteCompleted),
1616
}
1717

18+
impl BorsRepositoryEvent {
19+
pub fn repository(&self) -> &GithubRepoName {
20+
match self {
21+
BorsRepositoryEvent::Comment(comment) => &comment.repository,
22+
BorsRepositoryEvent::WorkflowStarted(workflow) => &workflow.repository,
23+
BorsRepositoryEvent::WorkflowCompleted(workflow) => &workflow.repository,
24+
BorsRepositoryEvent::CheckSuiteCompleted(payload) => &payload.repository,
25+
}
26+
}
27+
}
28+
1829
#[derive(Debug)]
1930
pub enum BorsGlobalEvent {
2031
/// The configuration of some repository has been changed for the bot's Github App.

src/bors/handlers/mod.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ pub async fn handle_bors_repository_event<Client: RepositoryClient>(
4848
ctx: Arc<BorsContext>,
4949
) -> anyhow::Result<()> {
5050
let db = Arc::clone(&ctx.db);
51-
match event {
52-
BorsRepositoryEvent::Comment(comment) => {
53-
// We want to ignore comments made by this bot
54-
if let Some(repo) = get_repo_state(state, &comment.repository) {
51+
if let Some(repo) = get_repo_state(state, &event.repository()) {
52+
match event {
53+
BorsRepositoryEvent::Comment(comment) => {
54+
// We want to ignore comments made by this bot
5555
if repo.client.is_comment_internal(&comment).await? {
5656
tracing::trace!(
5757
"Ignoring comment {comment:?} because it was authored by this bot"
@@ -81,10 +81,8 @@ pub async fn handle_bors_repository_event<Client: RepositoryClient>(
8181
.context("Cannot send comment reacting to an error")?;
8282
}
8383
}
84-
}
8584

86-
BorsRepositoryEvent::WorkflowStarted(payload) => {
87-
if let Some(_) = get_repo_state(state, &payload.repository) {
85+
BorsRepositoryEvent::WorkflowStarted(payload) => {
8886
let span = tracing::info_span!(
8987
"Workflow started",
9088
repo = payload.repository.to_string(),
@@ -97,9 +95,7 @@ pub async fn handle_bors_repository_event<Client: RepositoryClient>(
9795
span.log_error(error);
9896
}
9997
}
100-
}
101-
BorsRepositoryEvent::WorkflowCompleted(payload) => {
102-
if let Some(repo) = get_repo_state(state, &payload.repository) {
98+
BorsRepositoryEvent::WorkflowCompleted(payload) => {
10399
let span = tracing::info_span!(
104100
"Workflow completed",
105101
repo = payload.repository.to_string(),
@@ -112,9 +108,7 @@ pub async fn handle_bors_repository_event<Client: RepositoryClient>(
112108
span.log_error(error);
113109
}
114110
}
115-
}
116-
BorsRepositoryEvent::CheckSuiteCompleted(payload) => {
117-
if let Some(repo) = get_repo_state(state, &payload.repository) {
111+
BorsRepositoryEvent::CheckSuiteCompleted(payload) => {
118112
let span = tracing::info_span!(
119113
"Check suite completed",
120114
repo = payload.repository.to_string(),

0 commit comments

Comments
 (0)