diff options
Diffstat (limited to 'src/sub_commands/pull.rs')
| -rw-r--r-- | src/sub_commands/pull.rs | 62 |
1 files changed, 6 insertions, 56 deletions
diff --git a/src/sub_commands/pull.rs b/src/sub_commands/pull.rs index f3ae81f..2b20d3d 100644 --- a/src/sub_commands/pull.rs +++ b/src/sub_commands/pull.rs | |||
| @@ -8,10 +8,8 @@ use crate::{ | |||
| 8 | client::Connect, | 8 | client::Connect, |
| 9 | git::{Repo, RepoActions}, | 9 | git::{Repo, RepoActions}, |
| 10 | repo_ref, | 10 | repo_ref, |
| 11 | repo_ref::REPO_REF_KIND, | 11 | sub_commands::{ |
| 12 | sub_commands::prs::{ | 12 | prs::list::get_most_recent_patch_with_ancestors, push::fetch_pr_and_most_recent_patch_chain, |
| 13 | create::{PATCH_KIND, PR_KIND}, | ||
| 14 | list::{get_most_recent_patch_with_ancestors, tag_value}, | ||
| 15 | }, | 13 | }, |
| 16 | }; | 14 | }; |
| 17 | 15 | ||
| @@ -46,63 +44,15 @@ pub async fn launch() -> Result<()> { | |||
| 46 | ) | 44 | ) |
| 47 | .await?; | 45 | .await?; |
| 48 | 46 | ||
| 49 | println!("finding PR event..."); | 47 | let (_pr_event, commit_events) = |
| 50 | 48 | fetch_pr_and_most_recent_patch_chain(&client, &repo_ref, &root_commit, &branch_name) | |
| 51 | let pr_event: nostr::Event = client | 49 | .await?; |
| 52 | .get_events( | ||
| 53 | repo_ref.relays.clone(), | ||
| 54 | vec![ | ||
| 55 | nostr::Filter::default() | ||
| 56 | .kind(nostr::Kind::Custom(PR_KIND)) | ||
| 57 | .identifiers( | ||
| 58 | repo_ref | ||
| 59 | .maintainers | ||
| 60 | .iter() | ||
| 61 | .map(|m| format!("{REPO_REF_KIND}:{m}:{}", repo_ref.identifier)), | ||
| 62 | ), | ||
| 63 | ], | ||
| 64 | ) | ||
| 65 | .await? | ||
| 66 | .iter() | ||
| 67 | .find(|e| { | ||
| 68 | e.kind.as_u64() == PR_KIND | ||
| 69 | && e.tags | ||
| 70 | .iter() | ||
| 71 | .any(|t| t.as_vec().len() > 1 && t.as_vec()[1].eq(&format!("{root_commit}"))) | ||
| 72 | && tag_value(e, "branch-name") | ||
| 73 | .unwrap_or_default() | ||
| 74 | .eq(&branch_name) | ||
| 75 | }) | ||
| 76 | .context("cannot find a PR event associated with the checked out branch name")? | ||
| 77 | .to_owned(); | ||
| 78 | |||
| 79 | println!("found PR event. finding commits..."); | ||
| 80 | |||
| 81 | let commits_events: Vec<nostr::Event> = client | ||
| 82 | .get_events( | ||
| 83 | repo_ref.relays.clone(), | ||
| 84 | vec![ | ||
| 85 | nostr::Filter::default() | ||
| 86 | .kind(nostr::Kind::Custom(PATCH_KIND)) | ||
| 87 | .event(pr_event.id), | ||
| 88 | ], | ||
| 89 | ) | ||
| 90 | .await? | ||
| 91 | .iter() | ||
| 92 | .filter(|e| { | ||
| 93 | e.kind.as_u64() == PATCH_KIND | ||
| 94 | && e.tags | ||
| 95 | .iter() | ||
| 96 | .any(|t| t.as_vec().len() > 2 && t.as_vec()[1].eq(&pr_event.id.to_string())) | ||
| 97 | }) | ||
| 98 | .map(std::borrow::ToOwned::to_owned) | ||
| 99 | .collect(); | ||
| 100 | 50 | ||
| 101 | if git_repo.has_outstanding_changes()? { | 51 | if git_repo.has_outstanding_changes()? { |
| 102 | bail!("cannot pull changes when repository is not clean. discard changes and try again."); | 52 | bail!("cannot pull changes when repository is not clean. discard changes and try again."); |
| 103 | } | 53 | } |
| 104 | 54 | ||
| 105 | let most_recent_pr_patch_chain = get_most_recent_patch_with_ancestors(commits_events) | 55 | let most_recent_pr_patch_chain = get_most_recent_patch_with_ancestors(commit_events) |
| 106 | .context("cannot get most recent patch for PR")?; | 56 | .context("cannot get most recent patch for PR")?; |
| 107 | 57 | ||
| 108 | let applied = git_repo | 58 | let applied = git_repo |