Skip to content
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

Tree Closing and Opening #211

Closed
wants to merge 0 commits into from
Closed

Conversation

Rhythm1710
Copy link
Contributor

@Rhythm1710 Rhythm1710 commented Mar 5, 2025

Issue #207

Copy link
Contributor

@Kobzol Kobzol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Left a bunch of comments.

Once we have the repository in the DB, we should link PRs to repositories through foreign keys, so that we can easily join them in queries (we will need to figure out if a repo for a given PR is closed or not, and get PRs belonging to a given repo). This doesn't need to happen in this PR, but probably we'll want to change the repository field of PRs to become a FK to the repository table, and then always try to insert a repo into the DB when creating new PRs.

@@ -0,0 +1,8 @@
-- Add down migration script here
CREATE TABLE repo_model (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just repository, to be consistent with the rest of the tables.

-- Add down migration script here
CREATE TABLE repo_model (
id SERIAL PRIMARY KEY,
repo TEXT NOT NULL,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

repo -> name

CREATE TABLE repo_model (
id SERIAL PRIMARY KEY,
repo TEXT NOT NULL,
treeclosed TEXT NOT NULL CHECK (treeclosed IN ('open', 'closed')),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Homu stored a numeric value P that states "closed for PRs below priority P". So I would store this column as treeclosed INT NULL, where NULL means "not closed" and a non-null value means a closed tree with the priority P.

@@ -321,6 +323,30 @@ fn parse_priority_arg<'a>(parts: &[CommandPart<'a>]) -> Result<Option<u32>, Comm
Ok(priority)
}

fn parse_tree_open<'a>(command: &'a str, _parts: &[CommandPart<'a>]) -> ParseResult<'a> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use the original homu commands, so treeclosed- for opening a tree.

@@ -18,6 +18,8 @@ pub enum BorsRepositoryEvent {
/// A check suite has been completed, either as a workflow run on Github Actions, or as a
/// workflow from some external CI system.
CheckSuiteCompleted(CheckSuiteCompleted),
/// When a repository's tree state changes (open/closed)
TreeStateChanged(TreeStateChanged),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that we need any event for this? It should be enough to just handle the comment and store information about closed/opened repo in the DB.

}

/// Process the queue of pull requests for each repository
pub async fn process_queue(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like it implements a basic merge functionality or something? Let's not do that in this PR :) Just store the information about the tree being closed/open in the DB and that's it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will we need this in future? I can just comment it out and will be helpful in the future

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how the merge functionality will look like, that will require some up-front planning, design and discussions. So let's remove this for now, it's not needed for basic tree open/close functionality.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, Removing it

Copy link
Contributor

@Kobzol Kobzol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few comments :)

CREATE TABLE repository (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL UNIQUE,
treeclosed INT NULL,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
treeclosed INT NULL,
treeclosed BOOLEAN NULL,

Postgres supports booleans directly :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this dont we have to store priority numeric value of treeclosed?

@@ -112,6 +119,20 @@ fn parse_parts(input: &str) -> Result<Vec<CommandPart>, CommandParseError> {
break;
}

// Special handling for r- command
if item == "r-" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to avoid special cases here. We can parse the two commands in a much simpler way, e.g.:

fn parse_tree_open<'a>(command: &'a str, _parts: &[CommandPart<'a>]) -> ParseResult<'a> {
    if command != "treeclosed-" {
        return None;
    }
    Some(Ok(BorsCommand::TreeOpen))
}

fn parse_tree_closed<'a>(command: &'a str, parts: &[CommandPart<'a>]) -> ParseResult<'a> {
    if command != "treeclosed" {
        return None;
    }

    match parts {
        [CommandPart::KeyValue { value, .. }] => match validate_priority(value) {
            Ok(priority) => Some(Ok(BorsCommand::TreeClosed(priority))),
            Err(e) => Some(Err(e)),
        },
        _ => Some(Err(CommandParseError::MissingArgValue {
            arg: "treeclosed",
        })),
    }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad! I will change this

@@ -65,6 +67,12 @@ fn get_command_help(command: BorsCommand) -> String {
BorsCommand::TryCancel => {
"`try cancel`: Cancel a running try build"
}
BorsCommand::TreeOpen => {
"`tree open`: Open the repository tree for merging"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"`tree open`: Open the repository tree for merging"
"`treeclosed-`: Open the repository tree for merging"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this

src/config.rs Outdated
@@ -21,6 +21,8 @@ pub struct RepositoryConfig {
pub labels: HashMap<LabelTrigger, Vec<LabelModification>>,
#[serde(default, deserialize_with = "deserialize_duration_from_secs_opt")]
pub min_ci_time: Option<Duration>,
#[serde(default)]
pub treeclosed: Option<u32>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this we were setting tree closed, changing that to tree open by default

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a struct that represents a configuration of bors per each repository. Why should it mention treeclosed?

let row = sqlx::query_as!(
RepoModel,
r#"
SELECT id, name, COALESCE(treeclosed, 0) as "treeclosed: TreeState", treeclosed_src, created_at
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The COALESCE shouldn't be needed, since we're loading the treestate as Option<i32>, right? 🤔

Copy link
Contributor Author

@Rhythm1710 Rhythm1710 Mar 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it was not needed, fixed this as well.

@Kobzol
Copy link
Contributor

Kobzol commented Mar 7, 2025

You have a merge commit here. You should rebase onto master instead. Something like this:

git fetch origin
git rebase origin/main
git push --force

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants