-
Notifications
You must be signed in to change notification settings - Fork 26
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
Conversation
There was a problem hiding this 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 ( |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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')), |
There was a problem hiding this comment.
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.
src/bors/command/parser.rs
Outdated
@@ -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> { |
There was a problem hiding this comment.
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.
src/bors/event.rs
Outdated
@@ -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), |
There was a problem hiding this comment.
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.
src/bors/handlers/queue.rs
Outdated
} | ||
|
||
/// Process the queue of pull requests for each repository | ||
pub async fn process_queue( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, Removing it
There was a problem hiding this 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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
treeclosed INT NULL, | |
treeclosed BOOLEAN NULL, |
Postgres supports booleans directly :)
There was a problem hiding this comment.
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?
src/bors/command/parser.rs
Outdated
@@ -112,6 +119,20 @@ fn parse_parts(input: &str) -> Result<Vec<CommandPart>, CommandParseError> { | |||
break; | |||
} | |||
|
|||
// Special handling for r- command | |||
if item == "r-" { |
There was a problem hiding this comment.
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",
})),
}
}
There was a problem hiding this comment.
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
src/bors/handlers/help.rs
Outdated
@@ -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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"`tree open`: Open the repository tree for merging" | |
"`treeclosed-`: Open the repository tree for merging" |
There was a problem hiding this comment.
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>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this do?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
src/database/operations.rs
Outdated
let row = sqlx::query_as!( | ||
RepoModel, | ||
r#" | ||
SELECT id, name, COALESCE(treeclosed, 0) as "treeclosed: TreeState", treeclosed_src, created_at |
There was a problem hiding this comment.
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? 🤔
There was a problem hiding this comment.
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.
You have a merge commit here. You should rebase onto
|
Issue #207