diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-02-16 22:31:29 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-02-16 22:31:29 +0000 |
| commit | 701668b02d999af42f51d8bd25fffb2a8692c3c8 (patch) | |
| tree | 7defd0e7e711d743c8464994c2223a7a332ccf2a /src/sub_commands/list.rs | |
| parent | 61ffbf2008c0aaaee3d19ac027d63bca823dc8c9 (diff) | |
refactor: rename PR to proposal
PR is a problematic term when it ambiguous whether the
set of patches are PR-like or email-patch like.
Diffstat (limited to 'src/sub_commands/list.rs')
| -rw-r--r-- | src/sub_commands/list.rs | 54 |
1 files changed, 28 insertions, 26 deletions
diff --git a/src/sub_commands/list.rs b/src/sub_commands/list.rs index 4764adc..b8c2919 100644 --- a/src/sub_commands/list.rs +++ b/src/sub_commands/list.rs | |||
| @@ -46,21 +46,21 @@ pub async fn launch(_cli_args: &Cli, _args: &SubCommandArgs) -> Result<()> { | |||
| 46 | ) | 46 | ) |
| 47 | .await?; | 47 | .await?; |
| 48 | 48 | ||
| 49 | println!("finding PRs..."); | 49 | println!("finding proposals..."); |
| 50 | 50 | ||
| 51 | let pr_events: Vec<nostr::Event> = | 51 | let proposal_events: Vec<nostr::Event> = |
| 52 | find_pr_events(&client, &repo_ref, &root_commit.to_string()).await?; | 52 | find_proposal_events(&client, &repo_ref, &root_commit.to_string()).await?; |
| 53 | 53 | ||
| 54 | if pr_events.is_empty() { | 54 | if proposal_events.is_empty() { |
| 55 | println!("no PRs found... create one? try `ngit send`"); | 55 | println!("no proposals found... create one? try `ngit send`"); |
| 56 | return Ok(()); | 56 | return Ok(()); |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | let selected_index = Interactor::default().choice( | 59 | let selected_index = Interactor::default().choice( |
| 60 | PromptChoiceParms::default() | 60 | PromptChoiceParms::default() |
| 61 | .with_prompt("All PRs") | 61 | .with_prompt("all proposals") |
| 62 | .with_choices( | 62 | .with_choices( |
| 63 | pr_events | 63 | proposal_events |
| 64 | .iter() | 64 | .iter() |
| 65 | .map(|e| { | 65 | .map(|e| { |
| 66 | if let Ok(cl) = event_to_cover_letter(e) { | 66 | if let Ok(cl) = event_to_cover_letter(e) { |
| @@ -78,26 +78,27 @@ pub async fn launch(_cli_args: &Cli, _args: &SubCommandArgs) -> Result<()> { | |||
| 78 | println!("finding commits..."); | 78 | println!("finding commits..."); |
| 79 | 79 | ||
| 80 | let commits_events: Vec<nostr::Event> = | 80 | let commits_events: Vec<nostr::Event> = |
| 81 | find_commits_for_pr_event(&client, &pr_events[selected_index], &repo_ref).await?; | 81 | find_commits_for_proposal_root_event(&client, &proposal_events[selected_index], &repo_ref) |
| 82 | .await?; | ||
| 82 | 83 | ||
| 83 | confirm_checkout(&git_repo)?; | 84 | confirm_checkout(&git_repo)?; |
| 84 | 85 | ||
| 85 | let most_recent_pr_patch_chain = get_most_recent_patch_with_ancestors(commits_events) | 86 | let most_recent_proposal_patch_chain = get_most_recent_patch_with_ancestors(commits_events) |
| 86 | .context("cannot get most recent patch for PR")?; | 87 | .context("cannot get most recent patch for proposal")?; |
| 87 | 88 | ||
| 88 | let branch_name: String = event_to_cover_letter(&pr_events[selected_index]) | 89 | let branch_name: String = event_to_cover_letter(&proposal_events[selected_index]) |
| 89 | .context("cannot assign a branch name as event is not a patch set root")? | 90 | .context("cannot assign a branch name as event is not a patch set root")? |
| 90 | .branch_name; | 91 | .branch_name; |
| 91 | 92 | ||
| 92 | let applied = git_repo | 93 | let applied = git_repo |
| 93 | .apply_patch_chain(&branch_name, most_recent_pr_patch_chain) | 94 | .apply_patch_chain(&branch_name, most_recent_proposal_patch_chain) |
| 94 | .context("cannot apply patch chain")?; | 95 | .context("cannot apply patch chain")?; |
| 95 | 96 | ||
| 96 | if applied.is_empty() { | 97 | if applied.is_empty() { |
| 97 | println!("checked out PR branch. no new commits to pull"); | 98 | println!("checked out proposal branch. no new commits to pull"); |
| 98 | } else { | 99 | } else { |
| 99 | println!( | 100 | println!( |
| 100 | "checked out PR branch. pulled {} new commits", | 101 | "checked out proposal branch. pulled {} new commits", |
| 101 | applied.len(), | 102 | applied.len(), |
| 102 | ); | 103 | ); |
| 103 | } | 104 | } |
| @@ -115,7 +116,7 @@ fn confirm_checkout(git_repo: &Repo) -> Result<()> { | |||
| 115 | 116 | ||
| 116 | if git_repo.has_outstanding_changes()? { | 117 | if git_repo.has_outstanding_changes()? { |
| 117 | bail!( | 118 | bail!( |
| 118 | "cannot pull PR branch when repository is not clean. discard or stash (un)staged changes and try again." | 119 | "cannot pull proposal branch when repository is not clean. discard or stash (un)staged changes and try again." |
| 119 | ); | 120 | ); |
| 120 | } | 121 | } |
| 121 | Ok(()) | 122 | Ok(()) |
| @@ -201,7 +202,7 @@ pub fn get_most_recent_patch_with_ancestors( | |||
| 201 | Ok(res) | 202 | Ok(res) |
| 202 | } | 203 | } |
| 203 | 204 | ||
| 204 | pub async fn find_pr_events( | 205 | pub async fn find_proposal_events( |
| 205 | #[cfg(test)] client: &crate::client::MockConnect, | 206 | #[cfg(test)] client: &crate::client::MockConnect, |
| 206 | #[cfg(not(test))] client: &Client, | 207 | #[cfg(not(test))] client: &Client, |
| 207 | repo_ref: &RepoRef, | 208 | repo_ref: &RepoRef, |
| @@ -221,7 +222,8 @@ pub async fn find_pr_events( | |||
| 221 | .iter() | 222 | .iter() |
| 222 | .map(|m| format!("{REPO_REF_KIND}:{m}:{}", repo_ref.identifier)), | 223 | .map(|m| format!("{REPO_REF_KIND}:{m}:{}", repo_ref.identifier)), |
| 223 | ), | 224 | ), |
| 224 | // also pick up prs from the same repo but no target at our maintainers repo events | 225 | // also pick up proposals from the same repo but no target at our maintainers repo |
| 226 | // events | ||
| 225 | nostr::Filter::default() | 227 | nostr::Filter::default() |
| 226 | .kind(nostr::Kind::Custom(PATCH_KIND)) | 228 | .kind(nostr::Kind::Custom(PATCH_KIND)) |
| 227 | .custom_tag(nostr::Alphabet::T, vec!["root"]) | 229 | .custom_tag(nostr::Alphabet::T, vec!["root"]) |
| @@ -229,7 +231,7 @@ pub async fn find_pr_events( | |||
| 229 | ], | 231 | ], |
| 230 | ) | 232 | ) |
| 231 | .await | 233 | .await |
| 232 | .context("cannot get pr events")? | 234 | .context("cannot get proposal events")? |
| 233 | .iter() | 235 | .iter() |
| 234 | .filter(|e| { | 236 | .filter(|e| { |
| 235 | event_is_patch_set_root(e) | 237 | event_is_patch_set_root(e) |
| @@ -250,10 +252,10 @@ pub async fn find_pr_events( | |||
| 250 | .collect::<Vec<nostr::Event>>()) | 252 | .collect::<Vec<nostr::Event>>()) |
| 251 | } | 253 | } |
| 252 | 254 | ||
| 253 | pub async fn find_commits_for_pr_event( | 255 | pub async fn find_commits_for_proposal_root_event( |
| 254 | #[cfg(test)] client: &crate::client::MockConnect, | 256 | #[cfg(test)] client: &crate::client::MockConnect, |
| 255 | #[cfg(not(test))] client: &Client, | 257 | #[cfg(not(test))] client: &Client, |
| 256 | pr_event: &nostr::Event, | 258 | proposal_root_event: &nostr::Event, |
| 257 | repo_ref: &RepoRef, | 259 | repo_ref: &RepoRef, |
| 258 | ) -> Result<Vec<nostr::Event>> { | 260 | ) -> Result<Vec<nostr::Event>> { |
| 259 | let mut patch_events: Vec<nostr::Event> = client | 261 | let mut patch_events: Vec<nostr::Event> = client |
| @@ -265,7 +267,7 @@ pub async fn find_commits_for_pr_event( | |||
| 265 | // this requires every patch to reference the root event | 267 | // this requires every patch to reference the root event |
| 266 | // this will not pick up v2,v3 patch sets | 268 | // this will not pick up v2,v3 patch sets |
| 267 | // TODO: fetch commits for v2.. patch sets | 269 | // TODO: fetch commits for v2.. patch sets |
| 268 | .event(pr_event.id), | 270 | .event(proposal_root_event.id), |
| 269 | ], | 271 | ], |
| 270 | ) | 272 | ) |
| 271 | .await | 273 | .await |
| @@ -273,15 +275,15 @@ pub async fn find_commits_for_pr_event( | |||
| 273 | .iter() | 275 | .iter() |
| 274 | .filter(|e| { | 276 | .filter(|e| { |
| 275 | e.kind.as_u64() == PATCH_KIND | 277 | e.kind.as_u64() == PATCH_KIND |
| 276 | && e.tags | 278 | && e.tags.iter().any(|t| { |
| 277 | .iter() | 279 | t.as_vec().len() > 2 && t.as_vec()[1].eq(&proposal_root_event.id.to_string()) |
| 278 | .any(|t| t.as_vec().len() > 2 && t.as_vec()[1].eq(&pr_event.id.to_string())) | 280 | }) |
| 279 | }) | 281 | }) |
| 280 | .map(std::borrow::ToOwned::to_owned) | 282 | .map(std::borrow::ToOwned::to_owned) |
| 281 | .collect(); | 283 | .collect(); |
| 282 | 284 | ||
| 283 | if !event_is_cover_letter(pr_event) { | 285 | if !event_is_cover_letter(proposal_root_event) { |
| 284 | patch_events.push(pr_event.clone()); | 286 | patch_events.push(proposal_root_event.clone()); |
| 285 | } | 287 | } |
| 286 | Ok(patch_events) | 288 | Ok(patch_events) |
| 287 | } | 289 | } |