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/push.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/push.rs')
| -rw-r--r-- | src/sub_commands/push.rs | 59 |
1 files changed, 32 insertions, 27 deletions
diff --git a/src/sub_commands/push.rs b/src/sub_commands/push.rs index 7c6b95b..0fdd56f 100644 --- a/src/sub_commands/push.rs +++ b/src/sub_commands/push.rs | |||
| @@ -12,7 +12,7 @@ use crate::{ | |||
| 12 | repo_ref::{self, RepoRef}, | 12 | repo_ref::{self, RepoRef}, |
| 13 | sub_commands::{ | 13 | sub_commands::{ |
| 14 | list::{ | 14 | list::{ |
| 15 | find_commits_for_pr_event, find_pr_events, get_commit_id_from_patch, | 15 | find_commits_for_proposal_root_event, find_proposal_events, get_commit_id_from_patch, |
| 16 | get_most_recent_patch_with_ancestors, tag_value, | 16 | get_most_recent_patch_with_ancestors, tag_value, |
| 17 | }, | 17 | }, |
| 18 | send::{event_to_cover_letter, generate_patch_event, send_events}, | 18 | send::{event_to_cover_letter, generate_patch_event, send_events}, |
| @@ -36,7 +36,7 @@ pub async fn launch(cli_args: &Cli) -> Result<()> { | |||
| 36 | .context("cannot get checked out branch name")?; | 36 | .context("cannot get checked out branch name")?; |
| 37 | 37 | ||
| 38 | if branch_name == main_or_master_branch_name { | 38 | if branch_name == main_or_master_branch_name { |
| 39 | bail!("checkout a branch associated with a PR first") | 39 | bail!("checkout a branch associated with a proposal first") |
| 40 | } | 40 | } |
| 41 | #[cfg(not(test))] | 41 | #[cfg(not(test))] |
| 42 | let mut client = Client::default(); | 42 | let mut client = Client::default(); |
| @@ -51,44 +51,48 @@ pub async fn launch(cli_args: &Cli) -> Result<()> { | |||
| 51 | ) | 51 | ) |
| 52 | .await?; | 52 | .await?; |
| 53 | 53 | ||
| 54 | let (pr_event, commit_events) = | 54 | let (proposal_root_event, commit_events) = fetch_proposal_root_and_most_recent_patch_chain( |
| 55 | fetch_pr_and_most_recent_patch_chain(&client, &repo_ref, &root_commit, &branch_name) | 55 | &client, |
| 56 | .await?; | 56 | &repo_ref, |
| 57 | &root_commit, | ||
| 58 | &branch_name, | ||
| 59 | ) | ||
| 60 | .await?; | ||
| 57 | 61 | ||
| 58 | // TODO: fix these scenarios: | 62 | // TODO: fix these scenarios: |
| 59 | // - local PR branch is 2 behind and 1 ahead. intructions: ... | 63 | // - local proposal branch is 2 behind and 1 ahead. intructions: ... |
| 60 | // - PR has been rebased. (against commit in main) instructions: ... | 64 | // - proposal has been rebased. (against commit in main) instructions: ... |
| 61 | // - PR has been rebased. (against commit not in repo) instructions: .. | 65 | // - proposal has been rebased. (against commit not in repo) instructions: .. |
| 62 | 66 | ||
| 63 | let most_recent_pr_patch_chain = get_most_recent_patch_with_ancestors(commit_events) | 67 | let most_recent_proposal_patch_chain = get_most_recent_patch_with_ancestors(commit_events) |
| 64 | .context("cannot get most recent patch for PR")?; | 68 | .context("cannot get most recent patch for proposal")?; |
| 65 | 69 | ||
| 66 | let branch_tip = git_repo.get_tip_of_local_branch(&branch_name)?; | 70 | let branch_tip = git_repo.get_tip_of_local_branch(&branch_name)?; |
| 67 | 71 | ||
| 68 | let most_recent_patch_commit_id = str_to_sha1( | 72 | let most_recent_patch_commit_id = str_to_sha1( |
| 69 | &get_commit_id_from_patch(&most_recent_pr_patch_chain[0]) | 73 | &get_commit_id_from_patch(&most_recent_proposal_patch_chain[0]) |
| 70 | .context("latest patch event doesnt have a commit tag")?, | 74 | .context("latest patch event doesnt have a commit tag")?, |
| 71 | ) | 75 | ) |
| 72 | .context("latest patch event commit tag isn't a valid SHA1 hash")?; | 76 | .context("latest patch event commit tag isn't a valid SHA1 hash")?; |
| 73 | 77 | ||
| 74 | if most_recent_patch_commit_id.eq(&branch_tip) { | 78 | if most_recent_patch_commit_id.eq(&branch_tip) { |
| 75 | bail!("nostr pr already up-to-date with local branch"); | 79 | bail!("nostr proposal already up-to-date with local branch"); |
| 76 | } | 80 | } |
| 77 | 81 | ||
| 78 | if most_recent_pr_patch_chain.iter().any(|e| { | 82 | if most_recent_proposal_patch_chain.iter().any(|e| { |
| 79 | let c = tag_value(e, "parent-commit").unwrap_or_default(); | 83 | let c = tag_value(e, "parent-commit").unwrap_or_default(); |
| 80 | c.eq(&branch_tip.to_string()) | 84 | c.eq(&branch_tip.to_string()) |
| 81 | }) { | 85 | }) { |
| 82 | bail!("nostr pr is ahead of local branch"); | 86 | bail!("nostr proposal is ahead of local branch"); |
| 83 | } | 87 | } |
| 84 | 88 | ||
| 85 | let (ahead, behind) = git_repo | 89 | let (ahead, behind) = git_repo |
| 86 | .get_commits_ahead_behind(&most_recent_patch_commit_id, &branch_tip) | 90 | .get_commits_ahead_behind(&most_recent_patch_commit_id, &branch_tip) |
| 87 | .context("the latest patch in pr doesnt share an ancestor with your branch.")?; | 91 | .context("the latest patch in proposal doesnt share an ancestor with your branch.")?; |
| 88 | 92 | ||
| 89 | if !behind.is_empty() { | 93 | if !behind.is_empty() { |
| 90 | bail!( | 94 | bail!( |
| 91 | "your local pr branch is {} behind patches on nostr. consider rebasing or force pushing", | 95 | "your local proposal branch is {} behind patches on nostr. consider rebasing or force pushing", |
| 92 | behind.len() | 96 | behind.len() |
| 93 | ) | 97 | ) |
| 94 | } | 98 | } |
| @@ -109,7 +113,7 @@ pub async fn launch(cli_args: &Cli) -> Result<()> { | |||
| 109 | &git_repo, | 113 | &git_repo, |
| 110 | &root_commit, | 114 | &root_commit, |
| 111 | commit, | 115 | commit, |
| 112 | Some(pr_event.id), | 116 | Some(proposal_root_event.id), |
| 113 | &keys, | 117 | &keys, |
| 114 | &repo_ref, | 118 | &repo_ref, |
| 115 | patch_events.last().map(nostr::Event::id), | 119 | patch_events.last().map(nostr::Event::id), |
| @@ -135,33 +139,34 @@ pub async fn launch(cli_args: &Cli) -> Result<()> { | |||
| 135 | Ok(()) | 139 | Ok(()) |
| 136 | } | 140 | } |
| 137 | 141 | ||
| 138 | pub async fn fetch_pr_and_most_recent_patch_chain( | 142 | pub async fn fetch_proposal_root_and_most_recent_patch_chain( |
| 139 | #[cfg(test)] client: &crate::client::MockConnect, | 143 | #[cfg(test)] client: &crate::client::MockConnect, |
| 140 | #[cfg(not(test))] client: &Client, | 144 | #[cfg(not(test))] client: &Client, |
| 141 | repo_ref: &RepoRef, | 145 | repo_ref: &RepoRef, |
| 142 | root_commit: &Sha1Hash, | 146 | root_commit: &Sha1Hash, |
| 143 | branch_name: &String, | 147 | branch_name: &String, |
| 144 | ) -> Result<(nostr::Event, Vec<nostr::Event>)> { | 148 | ) -> Result<(nostr::Event, Vec<nostr::Event>)> { |
| 145 | println!("finding PR event..."); | 149 | println!("finding proposal root event..."); |
| 146 | 150 | ||
| 147 | let pr_events: Vec<nostr::Event> = find_pr_events(client, repo_ref, &root_commit.to_string()) | 151 | let proposal_events: Vec<nostr::Event> = |
| 148 | .await | 152 | find_proposal_events(client, repo_ref, &root_commit.to_string()) |
| 149 | .context("cannot get pr events for repo")?; | 153 | .await |
| 154 | .context("cannot get proposal events for repo")?; | ||
| 150 | 155 | ||
| 151 | let pr_event: nostr::Event = pr_events | 156 | let proposal_root_event: nostr::Event = proposal_events |
| 152 | .iter() | 157 | .iter() |
| 153 | .find(|e| { | 158 | .find(|e| { |
| 154 | event_to_cover_letter(e).is_ok_and(|cl| cl.branch_name.eq(branch_name)) | 159 | event_to_cover_letter(e).is_ok_and(|cl| cl.branch_name.eq(branch_name)) |
| 155 | // TODO remove the dependancy on same branch name and replace with | 160 | // TODO remove the dependancy on same branch name and replace with |
| 156 | // references stored in .git/ngit | 161 | // references stored in .git/ngit |
| 157 | }) | 162 | }) |
| 158 | .context("cannot find a PR event associated with the checked out branch name")? | 163 | .context("cannot find a proposal root event associated with the checked out branch name")? |
| 159 | .to_owned(); | 164 | .to_owned(); |
| 160 | 165 | ||
| 161 | println!("found PR event. finding commits..."); | 166 | println!("found proposal root event. finding commits..."); |
| 162 | 167 | ||
| 163 | let commits_events: Vec<nostr::Event> = | 168 | let commits_events: Vec<nostr::Event> = |
| 164 | find_commits_for_pr_event(client, &pr_event, repo_ref).await?; | 169 | find_commits_for_proposal_root_event(client, &proposal_root_event, repo_ref).await?; |
| 165 | 170 | ||
| 166 | Ok((pr_event, commits_events)) | 171 | Ok((proposal_root_event, commits_events)) |
| 167 | } | 172 | } |