diff options
Diffstat (limited to 'src/bin/git_remote_nostr/push.rs')
| -rw-r--r-- | src/bin/git_remote_nostr/push.rs | 109 |
1 files changed, 52 insertions, 57 deletions
diff --git a/src/bin/git_remote_nostr/push.rs b/src/bin/git_remote_nostr/push.rs index e8e1587..05c8fc2 100644 --- a/src/bin/git_remote_nostr/push.rs +++ b/src/bin/git_remote_nostr/push.rs | |||
| @@ -53,7 +53,6 @@ use crate::{ | |||
| 53 | pub async fn run_push( | 53 | pub async fn run_push( |
| 54 | git_repo: &Repo, | 54 | git_repo: &Repo, |
| 55 | repo_ref: &RepoRef, | 55 | repo_ref: &RepoRef, |
| 56 | decoded_nostr_url: &NostrUrlDecoded, | ||
| 57 | stdin: &Stdin, | 56 | stdin: &Stdin, |
| 58 | initial_refspec: &str, | 57 | initial_refspec: &str, |
| 59 | client: &Client, | 58 | client: &Client, |
| @@ -75,16 +74,18 @@ pub async fn run_push( | |||
| 75 | 74 | ||
| 76 | let term = console::Term::stderr(); | 75 | let term = console::Term::stderr(); |
| 77 | 76 | ||
| 78 | let list_outputs = match list_outputs { | 77 | let list_outputs = list_outputs.unwrap_or_else(|| { |
| 79 | Some(outputs) => outputs, | 78 | list_from_remotes( |
| 80 | _ => list_from_remotes(&term, git_repo, &repo_ref.git_server, decoded_nostr_url), | 79 | &term, |
| 81 | }; | 80 | git_repo, |
| 82 | 81 | &repo_ref.git_server, | |
| 83 | let nostr_state = get_state_from_cache(Some(git_repo.get_path()?), repo_ref).await; | 82 | &repo_ref.to_nostr_git_url(&None), |
| 83 | ) | ||
| 84 | }); | ||
| 84 | 85 | ||
| 85 | let existing_state = { | 86 | let existing_state = { |
| 86 | // if no state events - create from first git server listed | 87 | // if no state events - create from first git server listed |
| 87 | if let Ok(nostr_state) = &nostr_state { | 88 | if let Ok(nostr_state) = &get_state_from_cache(Some(git_repo.get_path()?), repo_ref).await { |
| 88 | nostr_state.state.clone() | 89 | nostr_state.state.clone() |
| 89 | } else if let Some(url) = repo_ref | 90 | } else if let Some(url) = repo_ref |
| 90 | .git_server | 91 | .git_server |
| @@ -118,55 +119,51 @@ pub async fn run_push( | |||
| 118 | } | 119 | } |
| 119 | }); | 120 | }); |
| 120 | 121 | ||
| 121 | if git_server_refspecs.is_empty() && proposal_refspecs.is_empty() { | 122 | // all refspecs aren't rejected |
| 122 | // all refspecs rejected | 123 | if !(git_server_refspecs.is_empty() && proposal_refspecs.is_empty()) { |
| 123 | println!(); | 124 | let (rejected_proposal_refspecs, rejected) = create_and_publish_events( |
| 124 | return Ok(()); | 125 | git_repo, |
| 125 | } | 126 | repo_ref, |
| 126 | 127 | &git_server_refspecs, | |
| 127 | let (rejected_proposal_refspecs, rejected) = create_and_publish_events( | 128 | &proposal_refspecs, |
| 128 | git_repo, | 129 | client, |
| 129 | repo_ref, | 130 | existing_state, |
| 130 | decoded_nostr_url, | 131 | &term, |
| 131 | &git_server_refspecs, | 132 | ) |
| 132 | &proposal_refspecs, | 133 | .await?; |
| 133 | client, | ||
| 134 | existing_state, | ||
| 135 | &term, | ||
| 136 | ) | ||
| 137 | .await?; | ||
| 138 | 134 | ||
| 139 | if !rejected { | 135 | if !rejected { |
| 140 | for refspec in &[git_server_refspecs.clone(), proposal_refspecs.clone()].concat() { | 136 | for refspec in git_server_refspecs.iter().chain(proposal_refspecs.iter()) { |
| 141 | if rejected_proposal_refspecs.contains(refspec) { | 137 | if rejected_proposal_refspecs.contains(refspec) { |
| 142 | continue; | 138 | continue; |
| 139 | } | ||
| 140 | let (_, to) = refspec_to_from_to(refspec)?; | ||
| 141 | println!("ok {to}"); | ||
| 142 | update_remote_refs_pushed( | ||
| 143 | &git_repo.git_repo, | ||
| 144 | refspec, | ||
| 145 | &repo_ref.to_nostr_git_url(&None).to_string(), | ||
| 146 | ) | ||
| 147 | .context("could not update remote_ref locally")?; | ||
| 143 | } | 148 | } |
| 144 | let (_, to) = refspec_to_from_to(refspec)?; | ||
| 145 | println!("ok {to}"); | ||
| 146 | update_remote_refs_pushed( | ||
| 147 | &git_repo.git_repo, | ||
| 148 | refspec, | ||
| 149 | &decoded_nostr_url.original_string, | ||
| 150 | ) | ||
| 151 | .context("could not update remote_ref locally")?; | ||
| 152 | } | ||
| 153 | 149 | ||
| 154 | // TODO make async - check gitlib2 callbacks work async | 150 | // TODO make async - check gitlib2 callbacks work async |
| 155 | 151 | ||
| 156 | for (git_server_url, remote_refspecs) in remote_refspecs { | 152 | for (git_server_url, remote_refspecs) in remote_refspecs { |
| 157 | let remote_refspecs = remote_refspecs | 153 | let remote_refspecs = remote_refspecs |
| 158 | .iter() | 154 | .iter() |
| 159 | .filter(|refspec| git_server_refspecs.contains(refspec)) | 155 | .filter(|refspec| git_server_refspecs.contains(refspec)) |
| 160 | .cloned() | 156 | .cloned() |
| 161 | .collect::<Vec<String>>(); | 157 | .collect::<Vec<String>>(); |
| 162 | if !refspecs.is_empty() { | 158 | if !refspecs.is_empty() { |
| 163 | let _ = push_to_remote( | 159 | let _ = push_to_remote( |
| 164 | git_repo, | 160 | git_repo, |
| 165 | &git_server_url, | 161 | &git_server_url, |
| 166 | decoded_nostr_url, | 162 | &repo_ref.to_nostr_git_url(&None), |
| 167 | &remote_refspecs, | 163 | &remote_refspecs, |
| 168 | &term, | 164 | &term, |
| 169 | ); | 165 | ); |
| 166 | } | ||
| 170 | } | 167 | } |
| 171 | } | 168 | } |
| 172 | } | 169 | } |
| @@ -175,11 +172,9 @@ pub async fn run_push( | |||
| 175 | Ok(()) | 172 | Ok(()) |
| 176 | } | 173 | } |
| 177 | 174 | ||
| 178 | #[allow(clippy::too_many_arguments)] | ||
| 179 | async fn create_and_publish_events( | 175 | async fn create_and_publish_events( |
| 180 | git_repo: &Repo, | 176 | git_repo: &Repo, |
| 181 | repo_ref: &RepoRef, | 177 | repo_ref: &RepoRef, |
| 182 | decoded_nostr_url: &NostrUrlDecoded, | ||
| 183 | git_server_refspecs: &Vec<String>, | 178 | git_server_refspecs: &Vec<String>, |
| 184 | proposal_refspecs: &Vec<String>, | 179 | proposal_refspecs: &Vec<String>, |
| 185 | client: &Client, | 180 | client: &Client, |
| @@ -222,7 +217,7 @@ async fn create_and_publish_events( | |||
| 222 | 217 | ||
| 223 | for event in get_merged_status_events( | 218 | for event in get_merged_status_events( |
| 224 | term, | 219 | term, |
| 225 | decoded_nostr_url, | 220 | &repo_ref.to_nostr_git_url(&None), |
| 226 | repo_ref, | 221 | repo_ref, |
| 227 | git_repo, | 222 | git_repo, |
| 228 | &signer, | 223 | &signer, |
| @@ -235,7 +230,7 @@ async fn create_and_publish_events( | |||
| 235 | 230 | ||
| 236 | if let Ok(Some(repo_ref_event)) = get_maintainers_yaml_update( | 231 | if let Ok(Some(repo_ref_event)) = get_maintainers_yaml_update( |
| 237 | term, | 232 | term, |
| 238 | decoded_nostr_url, | 233 | &repo_ref.to_nostr_git_url(&None), |
| 239 | repo_ref, | 234 | repo_ref, |
| 240 | git_repo, | 235 | git_repo, |
| 241 | &signer, | 236 | &signer, |