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

chore(friendshipper): poll for pr mergeability in a separate thread #315

Merged
merged 2 commits into from
Oct 14, 2024
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
52 changes: 29 additions & 23 deletions friendshipper/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,14 @@ fn force_window_to_front(window: Window) {
const PORT: u16 = 8484;

fn main() -> Result<(), CoreError> {
let arg = std::env::args().nth(1).unwrap_or_default();
if arg.starts_with("friendshipper://") {
tauri_plugin_deep_link::prepare("com.believer.friendshipper");
} else {
let _ = tauri_plugin_deep_link::set_identifier("com.believer.friendshipper");
#[cfg(not(target_os = "macos"))]
{
let arg = std::env::args().nth(1).unwrap_or_default();
if arg.starts_with("friendshipper://") {
tauri_plugin_deep_link::prepare("com.believer.friendshipper");
} else {
let _ = tauri_plugin_deep_link::set_identifier("com.believer.friendshipper");
}
}

// MacOS .app files don't inherit any PATH variables
Expand Down Expand Up @@ -358,28 +361,31 @@ fn main() -> Result<(), CoreError> {
}
});

let deep_link_handle = handle.clone();
tauri::async_runtime::spawn(async move {
let deep_link_request = move |request| {
info!("Received deep link: {:?}", request);
match deep_link_handle.emit_all("scheme-request-received", request) {
#[cfg(not(target_os = "macos"))]
{
let deep_link_handle = handle.clone();
tauri::async_runtime::spawn(async move {
let deep_link_request = move |request| {
info!("Received deep link: {:?}", request);
match deep_link_handle.emit_all("scheme-request-received", request) {
Ok(_) => {}
Err(e) => {
error!("Failed to emit scheme-request-received: {:?}", e);
}
}

if let Some(window) = deep_link_handle.get_window("main") {
force_window_to_front(window);
}
};
match tauri_plugin_deep_link::register("friendshipper", deep_link_request) {
Ok(_) => {}
Err(e) => {
error!("Failed to emit scheme-request-received: {:?}", e);
error!("Failed to register deep link handler: {:?}", e);
}
}

if let Some(window) = deep_link_handle.get_window("main") {
force_window_to_front(window);
}
};
match tauri_plugin_deep_link::register("friendshipper", deep_link_request) {
Ok(_) => {}
Err(e) => {
error!("Failed to register deep link handler: {:?}", e);
}
}
});
});
}

Ok(())
})
Expand Down
44 changes: 33 additions & 11 deletions friendshipper/src-tauri/src/repo/operations/gh/submit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl Task for GitHubSubmitOp {
repo = status.repo_name.clone();
}

let mut pr = octocrab
let pr = octocrab
.pulls(owner.clone(), repo.clone())
.create(
format!("{} {}", SUBMIT_PREFIX, truncated_message),
Expand All @@ -89,16 +89,38 @@ impl Task for GitHubSubmitOp {
.send()
.await?;

pr = self
.poll_for_mergeable(octocrab, pr, owner.clone(), repo.clone())
.await?;

let id = self
.client
.get_pull_request_id(owner.clone(), repo.clone(), pr.number as i64)
.await?;

self.client.enqueue_pull_request(id).await?;
let octocrab_clone = octocrab.clone();
let owner_clone = owner.clone();
let repo_clone = repo.clone();
let client_clone = self.client.clone();
let self_clone = self.clone();

// There's a lot of variability in how long this takes, so we give the frontend
// a chance to return control to the user before it starts polling
tokio::spawn(async move {
match self_clone
.poll_for_mergeable(octocrab_clone, pr, owner_clone.clone(), repo_clone.clone())
.await
{
Ok(updated_pr) => {
if let Ok(id) = client_clone
.get_pull_request_id(
owner_clone.clone(),
repo_clone.clone(),
updated_pr.number as i64,
)
.await
{
if let Err(e) = client_clone.enqueue_pull_request(id).await {
warn!("Failed to enqueue pull request: {:?}", e);
}
} else {
warn!("Failed to get pull request ID");
}
}
Err(e) => warn!("Failed to poll for mergeable state: {:?}", e),
}
});
Copy link
Member Author

Choose a reason for hiding this comment

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

The potential downside here is if queuing the PR errors, the frontend might not be aware of it. I'd like any reviewer to chime in on whether that risk is worth the 10-30s of savings on submission time.

Copy link
Contributor

Choose a reason for hiding this comment

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

I dont think the saved time is enough to offset a bad ui experience?
maybe if users were used to checking on their submissions via github, this would be fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

the bad ui experience is if and only if putting the PR into the queue errors out. the frontend still watches the PR and updates its state accordingly. the difference is that we were blocking the submission modal from closing until the PR gets queued.

If the background thread errors out, users will see that their PR is open but not in the queue. The fix in this case would be to click the PR link in the UI and manually put the PR into the queue. In our data, this error has occurred 0 times in the last 60 days.

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 fine then


Ok(())
}
Expand Down
Loading