diff options
Diffstat (limited to 'src/bin/git_remote_nostr/push.rs')
| -rw-r--r-- | src/bin/git_remote_nostr/push.rs | 62 |
1 files changed, 26 insertions, 36 deletions
diff --git a/src/bin/git_remote_nostr/push.rs b/src/bin/git_remote_nostr/push.rs index f2ac169..e8e1587 100644 --- a/src/bin/git_remote_nostr/push.rs +++ b/src/bin/git_remote_nostr/push.rs | |||
| @@ -6,17 +6,17 @@ use std::{ | |||
| 6 | time::Instant, | 6 | time::Instant, |
| 7 | }; | 7 | }; |
| 8 | 8 | ||
| 9 | use anyhow::{anyhow, bail, Context, Result}; | 9 | use anyhow::{Context, Result, anyhow, bail}; |
| 10 | use auth_git2::GitAuthenticator; | 10 | use auth_git2::GitAuthenticator; |
| 11 | use client::{ | 11 | use client::{ |
| 12 | get_events_from_local_cache, get_state_from_cache, send_events, sign_event, STATE_KIND, | 12 | STATE_KIND, get_events_from_local_cache, get_state_from_cache, send_events, sign_event, |
| 13 | }; | 13 | }; |
| 14 | use console::Term; | 14 | use console::Term; |
| 15 | use git::{sha1_to_oid, RepoActions}; | 15 | use git::{RepoActions, sha1_to_oid}; |
| 16 | use git2::{Oid, Repository}; | ||
| 17 | use git_events::{ | 16 | use git_events::{ |
| 18 | generate_cover_letter_and_patch_events, generate_patch_event, get_commit_id_from_patch, | 17 | generate_cover_letter_and_patch_events, generate_patch_event, get_commit_id_from_patch, |
| 19 | }; | 18 | }; |
| 19 | use git2::{Oid, Repository}; | ||
| 20 | use ngit::{ | 20 | use ngit::{ |
| 21 | cli_interactor::count_lines_per_msg_vec, | 21 | cli_interactor::count_lines_per_msg_vec, |
| 22 | client::{self, get_event_from_cache_by_id}, | 22 | client::{self, get_event_from_cache_by_id}, |
| @@ -32,8 +32,8 @@ use ngit::{ | |||
| 32 | }; | 32 | }; |
| 33 | use nostr::nips::nip10::Marker; | 33 | use nostr::nips::nip10::Marker; |
| 34 | use nostr_sdk::{ | 34 | use nostr_sdk::{ |
| 35 | hashes::sha1::Hash as Sha1Hash, Event, EventBuilder, EventId, Kind, NostrSigner, PublicKey, | 35 | Event, EventBuilder, EventId, Kind, NostrSigner, PublicKey, RelayUrl, Tag, |
| 36 | RelayUrl, Tag, | 36 | hashes::sha1::Hash as Sha1Hash, |
| 37 | }; | 37 | }; |
| 38 | use repo_ref::RepoRef; | 38 | use repo_ref::RepoRef; |
| 39 | use repo_state::RepoState; | 39 | use repo_state::RepoState; |
| @@ -43,9 +43,10 @@ use crate::{ | |||
| 43 | git::Repo, | 43 | git::Repo, |
| 44 | list::list_from_remotes, | 44 | list::list_from_remotes, |
| 45 | utils::{ | 45 | utils::{ |
| 46 | find_proposal_and_patches_by_branch_name, get_all_proposals, get_remote_name_by_url, | 46 | Direction, find_proposal_and_patches_by_branch_name, get_all_proposals, |
| 47 | get_short_git_server_name, get_write_protocols_to_try, join_with_and, | 47 | get_remote_name_by_url, get_short_git_server_name, get_write_protocols_to_try, |
| 48 | push_error_is_not_authentication_failure, read_line, set_protocol_preference, Direction, | 48 | join_with_and, push_error_is_not_authentication_failure, read_line, |
| 49 | set_protocol_preference, | ||
| 49 | }, | 50 | }, |
| 50 | }; | 51 | }; |
| 51 | 52 | ||
| @@ -1023,13 +1024,10 @@ async fn get_merged_status_events( | |||
| 1023 | let (ahead, _) = | 1024 | let (ahead, _) = |
| 1024 | git_repo.get_commits_ahead_behind(&tip_of_remote_branch, &tip_of_pushed_branch)?; | 1025 | git_repo.get_commits_ahead_behind(&tip_of_remote_branch, &tip_of_pushed_branch)?; |
| 1025 | 1026 | ||
| 1026 | let commit_events = get_events_from_local_cache( | 1027 | let commit_events = get_events_from_local_cache(git_repo.get_path()?, vec![ |
| 1027 | git_repo.get_path()?, | 1028 | nostr::Filter::default().kind(nostr::Kind::GitPatch), |
| 1028 | vec![ | 1029 | // TODO: limit by repo_ref |
| 1029 | nostr::Filter::default().kind(nostr::Kind::GitPatch), | 1030 | ]) |
| 1030 | // TODO: limit by repo_ref | ||
| 1031 | ], | ||
| 1032 | ) | ||
| 1033 | .await?; | 1031 | .await?; |
| 1034 | 1032 | ||
| 1035 | let merged_proposals_info = | 1033 | let merged_proposals_info = |
| @@ -1106,12 +1104,9 @@ async fn get_merged_proposals_info( | |||
| 1106 | proposals.entry(proposal_id).or_default(); | 1104 | proposals.entry(proposal_id).or_default(); |
| 1107 | // ignore revisions without all the merged commits | 1105 | // ignore revisions without all the merged commits |
| 1108 | if entry_revision_id == &revision_id { | 1106 | if entry_revision_id == &revision_id { |
| 1109 | merged_patches.insert( | 1107 | merged_patches.insert(*commit_hash, MergedPRCommitType::PatchCommit { |
| 1110 | *commit_hash, | 1108 | event_id: patch_event.id, |
| 1111 | MergedPRCommitType::PatchCommit { | 1109 | }); |
| 1112 | event_id: patch_event.id, | ||
| 1113 | }, | ||
| 1114 | ); | ||
| 1115 | } | 1110 | } |
| 1116 | } | 1111 | } |
| 1117 | } | 1112 | } |
| @@ -1136,12 +1131,9 @@ async fn get_merged_proposals_info( | |||
| 1136 | proposals.entry(proposal_id).or_default(); | 1131 | proposals.entry(proposal_id).or_default(); |
| 1137 | // ignore revisions without all the applied commits | 1132 | // ignore revisions without all the applied commits |
| 1138 | if entry_revision_id == &revision_id { | 1133 | if entry_revision_id == &revision_id { |
| 1139 | merged_patches.insert( | 1134 | merged_patches.insert(*commit_hash, MergedPRCommitType::PatchApplied { |
| 1140 | *commit_hash, | 1135 | event_id: patch_event.id, |
| 1141 | MergedPRCommitType::PatchApplied { | 1136 | }); |
| 1142 | event_id: patch_event.id, | ||
| 1143 | }, | ||
| 1144 | ); | ||
| 1145 | } | 1137 | } |
| 1146 | } | 1138 | } |
| 1147 | } | 1139 | } |
| @@ -1379,10 +1371,9 @@ async fn get_proposal_and_revision_root_from_patch( | |||
| 1379 | .clone(), | 1371 | .clone(), |
| 1380 | )?; | 1372 | )?; |
| 1381 | 1373 | ||
| 1382 | get_events_from_local_cache( | 1374 | get_events_from_local_cache(git_repo.get_path()?, vec![ |
| 1383 | git_repo.get_path()?, | 1375 | nostr::Filter::default().id(proposal_or_revision_id), |
| 1384 | vec![nostr::Filter::default().id(proposal_or_revision_id)], | 1376 | ]) |
| 1385 | ) | ||
| 1386 | .await? | 1377 | .await? |
| 1387 | .first() | 1378 | .first() |
| 1388 | .unwrap() | 1379 | .unwrap() |
| @@ -1538,10 +1529,9 @@ impl BuildRepoState for RepoState { | |||
| 1538 | ) -> Result<RepoState> { | 1529 | ) -> Result<RepoState> { |
| 1539 | let mut tags = vec![Tag::identifier(identifier.clone())]; | 1530 | let mut tags = vec![Tag::identifier(identifier.clone())]; |
| 1540 | for (name, value) in &state { | 1531 | for (name, value) in &state { |
| 1541 | tags.push(Tag::custom( | 1532 | tags.push(Tag::custom(nostr_sdk::TagKind::Custom(name.into()), vec![ |
| 1542 | nostr_sdk::TagKind::Custom(name.into()), | 1533 | value.clone(), |
| 1543 | vec![value.clone()], | 1534 | ])); |
| 1544 | )); | ||
| 1545 | } | 1535 | } |
| 1546 | let event = sign_event(EventBuilder::new(STATE_KIND, "").tags(tags), signer).await?; | 1536 | let event = sign_event(EventBuilder::new(STATE_KIND, "").tags(tags), signer).await?; |
| 1547 | Ok(RepoState { | 1537 | Ok(RepoState { |