Skip to content

feat: track mergeability #219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 2025
Merged
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
target/
.env
.env
.DS_Store

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

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

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

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

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

2 changes: 2 additions & 0 deletions migrations/20250315140840_add_merge_state_to_pr.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Add up migration script here
ALTER TABLE pull_request ADD COLUMN mergeable_state TEXT NOT NULL DEFAULT 'unknown';
2 changes: 2 additions & 0 deletions migrations/20250315140840_add_merge_to_pr.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Add down migration script here
ALTER TABLE pull_request DROP COLUMN mergeable_state;
10 changes: 10 additions & 0 deletions src/bors/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ pub enum BorsRepositoryEvent {
PullRequestEdited(PullRequestEdited),
/// When a pull request is opened.
PullRequestOpened(PullRequestOpened),
/// When there is a push to a branch. This includes when a commit is pushed, when a commit tag is pushed,
/// when a branch is deleted or when a tag is deleted.
PushToBranch(PushToBranch),
/// A workflow run on Github Actions or a check run from external CI system has been started.
WorkflowStarted(WorkflowStarted),
/// A workflow run on Github Actions or a check run from external CI system has been completed.
Expand All @@ -29,6 +32,7 @@ impl BorsRepositoryEvent {
BorsRepositoryEvent::PullRequestCommitPushed(payload) => &payload.repository,
BorsRepositoryEvent::PullRequestEdited(payload) => &payload.repository,
BorsRepositoryEvent::PullRequestOpened(payload) => &payload.repository,
BorsRepositoryEvent::PushToBranch(payload) => &payload.repository,
BorsRepositoryEvent::WorkflowStarted(workflow) => &workflow.repository,
BorsRepositoryEvent::WorkflowCompleted(workflow) => &workflow.repository,
BorsRepositoryEvent::CheckSuiteCompleted(payload) => &payload.repository,
Expand Down Expand Up @@ -81,6 +85,12 @@ pub struct PullRequestOpened {
pub pull_request: PullRequest,
}

#[derive(Debug)]
pub struct PushToBranch {
pub repository: GithubRepoName,
pub branch: String,
}

#[derive(Debug)]
pub struct WorkflowStarted {
pub repository: GithubRepoName,
Expand Down
7 changes: 6 additions & 1 deletion src/bors/handlers/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ pub(super) async fn command_info(
) -> anyhow::Result<()> {
// Geting PR info from database
let pr_model = db
.get_or_create_pull_request(repo.client.repository(), pr.number, &pr.base.name)
.get_or_create_pull_request(
repo.client.repository(),
pr.number,
&pr.base.name,
pr.mergeable_state.clone().into(),
)
.await?;

// Building the info message
Expand Down
18 changes: 16 additions & 2 deletions src/bors/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ use crate::{load_repositories, PgDbClient, TeamApiClient};
use anyhow::Context;
use octocrab::Octocrab;
use pr_events::{
handle_pull_request_edited, handle_pull_request_opened, handle_push_to_pull_request,
handle_pull_request_edited, handle_pull_request_opened, handle_push_to_branch,
handle_push_to_pull_request,
};
use review::{command_delegate, command_set_priority, command_set_rollup, command_undelegate};
use tracing::Instrument;
Expand Down Expand Up @@ -146,6 +147,14 @@ pub async fn handle_bors_repository_event(
.instrument(span.clone())
.await?;
}
BorsRepositoryEvent::PushToBranch(payload) => {
let span =
tracing::info_span!("Pushed to branch", repo = payload.repository.to_string());

handle_push_to_branch(repo, db, payload)
.instrument(span.clone())
.await?;
}
}
Ok(())
}
Expand Down Expand Up @@ -435,7 +444,12 @@ async fn has_permission(
}

let pr_model = db
.get_or_create_pull_request(repo_state.repository(), pr.number, &pr.base.name)
.get_or_create_pull_request(
repo_state.repository(),
pr.number,
&pr.base.name,
pr.mergeable_state.clone().into(),
)
.await?;
let is_delegated = pr_model.delegated && author.id == pr.author.id;

Expand Down
Loading