upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/sub_commands
diff options
context:
space:
mode:
Diffstat (limited to 'src/sub_commands')
-rw-r--r--src/sub_commands/send.rs252
1 files changed, 134 insertions, 118 deletions
diff --git a/src/sub_commands/send.rs b/src/sub_commands/send.rs
index 7c8f2ee..410e119 100644
--- a/src/sub_commands/send.rs
+++ b/src/sub_commands/send.rs
@@ -603,15 +603,13 @@ pub async fn generate_cover_letter_and_patch_events(
603 commits.len() 603 commits.len()
604 ), 604 ),
605 [ 605 [
606 repo_ref.maintainers.iter().map(|m| Tag::coordinate(Coordinate {
607 kind: nostr::Kind::Custom(REPO_REF_KIND),
608 public_key: *m,
609 identifier: repo_ref.identifier.to_string(),
610 relays: repo_ref.relays.clone(),
611 })).collect::<Vec<Tag>>(),
606 vec![ 612 vec![
607 // TODO: why not tag all maintainer identifiers?
608 Tag::coordinate(Coordinate {
609 kind: nostr::Kind::Custom(REPO_REF_KIND),
610 public_key: *repo_ref.maintainers.first()
611 .context("repo reference should always have at least one maintainer")?,
612 identifier: repo_ref.identifier.to_string(),
613 relays: repo_ref.relays.clone(),
614 }),
615 Tag::from_standardized(TagStandard::Reference(format!("{root_commit}"))), 613 Tag::from_standardized(TagStandard::Reference(format!("{root_commit}"))),
616 Tag::hashtag("cover-letter"), 614 Tag::hashtag("cover-letter"),
617 Tag::custom( 615 Tag::custom(
@@ -885,124 +883,142 @@ pub async fn generate_patch_event(
885 .context("failed to get parent commit")?; 883 .context("failed to get parent commit")?;
886 let relay_hint = repo_ref.relays.first().map(nostr::UncheckedUrl::from); 884 let relay_hint = repo_ref.relays.first().map(nostr::UncheckedUrl::from);
887 885
888 sign_event(EventBuilder::new( 886 sign_event(
889 nostr::event::Kind::Custom(PATCH_KIND), 887 EventBuilder::new(
890 git_repo 888 nostr::event::Kind::Custom(PATCH_KIND),
891 .make_patch_from_commit(commit,&series_count) 889 git_repo
892 .context(format!("cannot make patch for commit {commit}"))?, 890 .make_patch_from_commit(commit, &series_count)
893 [ 891 .context(format!("cannot make patch for commit {commit}"))?,
894 vec![ 892 [
895 Tag::coordinate(Coordinate { 893 repo_ref
896 kind: nostr::Kind::Custom(REPO_REF_KIND), 894 .maintainers
897 public_key: *repo_ref.maintainers.first() 895 .iter()
898 .context("repo reference should always have at least one maintainer - the issuer of the repo event") 896 .map(|m| {
899 ?, 897 Tag::coordinate(Coordinate {
900 identifier: repo_ref.identifier.to_string(), 898 kind: nostr::Kind::Custom(REPO_REF_KIND),
901 relays: repo_ref.relays.clone(), 899 public_key: *m,
902 }), 900 identifier: repo_ref.identifier.to_string(),
903 Tag::from_standardized(TagStandard::Reference(root_commit.to_string())), 901 relays: repo_ref.relays.clone(),
904 // commit id reference is a trade-off. its now 902 })
905 // unclear which one is the root commit id but it 903 })
906 // enables easier location of code comments againt 904 .collect::<Vec<Tag>>(),
907 // code that makes it into the main branch, assuming
908 // the commit id is correct
909 Tag::from_standardized(TagStandard::Reference(commit.to_string())),
910 Tag::custom(
911 TagKind::Custom(std::borrow::Cow::Borrowed("alt")),
912 vec![format!("git patch: {}", git_repo.get_commit_message_summary(commit).unwrap_or_default())],
913 ),
914 ],
915
916 if let Some(thread_event_id) = thread_event_id {
917 vec![Tag::from_standardized(nostr_sdk::TagStandard::Event {
918 event_id: thread_event_id,
919 relay_url: relay_hint.clone(),
920 marker: Some(Marker::Root),
921 public_key: None,
922 })]
923 } else if let Some(event_ref) = root_proposal_id.clone() {
924 vec![
925 Tag::hashtag("root"),
926 Tag::hashtag("revision-root"),
927 // TODO check if id is for a root proposal (perhaps its for an issue?)
928 event_tag_from_nip19_or_hex(&event_ref,"proposal", Marker::Reply, false, false)?,
929 ]
930 } else {
931 vec![ 905 vec![
932 Tag::hashtag("root"), 906 Tag::from_standardized(TagStandard::Reference(root_commit.to_string())),
933 ] 907 // commit id reference is a trade-off. its now
934 }, 908 // unclear which one is the root commit id but it
935 mentions.to_vec(), 909 // enables easier location of code comments againt
936 if let Some(id) = parent_patch_event_id { 910 // code that makes it into the main branch, assuming
937 vec![Tag::from_standardized(nostr_sdk::TagStandard::Event { 911 // the commit id is correct
938 event_id: id, 912 Tag::from_standardized(TagStandard::Reference(commit.to_string())),
939 relay_url: relay_hint.clone(), 913 Tag::custom(
940 marker: Some(Marker::Reply), 914 TagKind::Custom(std::borrow::Cow::Borrowed("alt")),
941 public_key: None, 915 vec![format!(
942 })] 916 "git patch: {}",
943 } else { 917 git_repo
944 vec![] 918 .get_commit_message_summary(commit)
945 }, 919 .unwrap_or_default()
946 // see comment on branch names in cover letter event creation 920 )],
947 if let Some(branch_name) = branch_name { 921 ),
948 if thread_event_id.is_none() { 922 ],
923 if let Some(thread_event_id) = thread_event_id {
924 vec![Tag::from_standardized(nostr_sdk::TagStandard::Event {
925 event_id: thread_event_id,
926 relay_url: relay_hint.clone(),
927 marker: Some(Marker::Root),
928 public_key: None,
929 })]
930 } else if let Some(event_ref) = root_proposal_id.clone() {
949 vec![ 931 vec![
950 Tag::custom( 932 Tag::hashtag("root"),
933 Tag::hashtag("revision-root"),
934 // TODO check if id is for a root proposal (perhaps its for an issue?)
935 event_tag_from_nip19_or_hex(
936 &event_ref,
937 "proposal",
938 Marker::Reply,
939 false,
940 false,
941 )?,
942 ]
943 } else {
944 vec![Tag::hashtag("root")]
945 },
946 mentions.to_vec(),
947 if let Some(id) = parent_patch_event_id {
948 vec![Tag::from_standardized(nostr_sdk::TagStandard::Event {
949 event_id: id,
950 relay_url: relay_hint.clone(),
951 marker: Some(Marker::Reply),
952 public_key: None,
953 })]
954 } else {
955 vec![]
956 },
957 // see comment on branch names in cover letter event creation
958 if let Some(branch_name) = branch_name {
959 if thread_event_id.is_none() {
960 vec![Tag::custom(
951 TagKind::Custom(std::borrow::Cow::Borrowed("branch-name")), 961 TagKind::Custom(std::borrow::Cow::Borrowed("branch-name")),
952 vec![branch_name.to_string()], 962 vec![branch_name.to_string()],
953 ) 963 )]
954 ] 964 } else {
955 } 965 vec![]
956 else { vec![]} 966 }
957 } 967 } else {
958 else { vec![]}, 968 vec![]
959 // whilst it is in nip34 draft to tag the maintainers 969 },
960 // I'm not sure it is a good idea because if they are 970 // whilst it is in nip34 draft to tag the maintainers
961 // interested in all patches then their specialised 971 // I'm not sure it is a good idea because if they are
962 // client should subscribe to patches tagged with the 972 // interested in all patches then their specialised
963 // repo reference. maintainers of large repos will not 973 // client should subscribe to patches tagged with the
964 // be interested in every patch. 974 // repo reference. maintainers of large repos will not
965 repo_ref.maintainers 975 // be interested in every patch.
976 repo_ref
977 .maintainers
966 .iter() 978 .iter()
967 .map(|pk| Tag::public_key(*pk)) 979 .map(|pk| Tag::public_key(*pk))
968 .collect(), 980 .collect(),
969 vec![ 981 vec![
970 // a fallback is now in place to extract this from the patch 982 // a fallback is now in place to extract this from the patch
971 Tag::custom( 983 Tag::custom(
972 TagKind::Custom(std::borrow::Cow::Borrowed("commit")), 984 TagKind::Custom(std::borrow::Cow::Borrowed("commit")),
973 vec![commit.to_string()], 985 vec![commit.to_string()],
974 ), 986 ),
975 // this is required as patches cannot be relied upon to include the 'base commit' 987 // this is required as patches cannot be relied upon to include the 'base
976 Tag::custom( 988 // commit'
977 TagKind::Custom(std::borrow::Cow::Borrowed("parent-commit")), 989 Tag::custom(
978 vec![commit_parent.to_string()], 990 TagKind::Custom(std::borrow::Cow::Borrowed("parent-commit")),
979 ), 991 vec![commit_parent.to_string()],
980 // this is required to ensure the commit id matches 992 ),
981 Tag::custom( 993 // this is required to ensure the commit id matches
982 TagKind::Custom(std::borrow::Cow::Borrowed("commit-pgp-sig")), 994 Tag::custom(
983 vec![ 995 TagKind::Custom(std::borrow::Cow::Borrowed("commit-pgp-sig")),
984 git_repo 996 vec![
985 .extract_commit_pgp_signature(commit) 997 git_repo
986 .unwrap_or_default(), 998 .extract_commit_pgp_signature(commit)
999 .unwrap_or_default(),
987 ], 1000 ],
988 ), 1001 ),
989 // removing description tag will not cause anything to break 1002 // removing description tag will not cause anything to break
990 Tag::from_standardized(nostr_sdk::TagStandard::Description( 1003 Tag::from_standardized(nostr_sdk::TagStandard::Description(
991 git_repo.get_commit_message(commit)?.to_string() 1004 git_repo.get_commit_message(commit)?.to_string(),
992 )), 1005 )),
993 Tag::custom( 1006 Tag::custom(
994 TagKind::Custom(std::borrow::Cow::Borrowed("author")), 1007 TagKind::Custom(std::borrow::Cow::Borrowed("author")),
995 git_repo.get_commit_author(commit)?, 1008 git_repo.get_commit_author(commit)?,
996 ), 1009 ),
997 // this is required to ensure the commit id matches 1010 // this is required to ensure the commit id matches
998 Tag::custom( 1011 Tag::custom(
999 TagKind::Custom(std::borrow::Cow::Borrowed("committer")), 1012 TagKind::Custom(std::borrow::Cow::Borrowed("committer")),
1000 git_repo.get_commit_comitter(commit)?, 1013 git_repo.get_commit_comitter(commit)?,
1001 ), 1014 ),
1002 ], 1015 ],
1003 ] 1016 ]
1004 .concat(), 1017 .concat(),
1005 ), signer).await 1018 ),
1019 signer,
1020 )
1021 .await
1006 .context("failed to sign event") 1022 .context("failed to sign event")
1007} 1023}
1008// TODO 1024// TODO