upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/bin/ngit/sub_commands/pr_status.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/ngit/sub_commands/pr_status.rs')
-rw-r--r--src/bin/ngit/sub_commands/pr_status.rs29
1 files changed, 20 insertions, 9 deletions
diff --git a/src/bin/ngit/sub_commands/pr_status.rs b/src/bin/ngit/sub_commands/pr_status.rs
index e84117d..12aafb7 100644
--- a/src/bin/ngit/sub_commands/pr_status.rs
+++ b/src/bin/ngit/sub_commands/pr_status.rs
@@ -30,7 +30,13 @@ fn parse_event_id(id: &str) -> Result<EventId> {
30} 30}
31 31
32#[allow(clippy::too_many_lines)] 32#[allow(clippy::too_many_lines)]
33async fn launch_status(id: &str, offline: bool, new_kind: Kind, action: &str) -> Result<()> { 33async fn launch_status(
34 id: &str,
35 offline: bool,
36 new_kind: Kind,
37 action: &str,
38 reason: Option<&str>,
39) -> Result<()> {
34 let event_id = parse_event_id(id)?; 40 let event_id = parse_event_id(id)?;
35 41
36 let git_repo = Repo::discover().context("failed to find a git repository")?; 42 let git_repo = Repo::discover().context("failed to find a git repository")?;
@@ -65,7 +71,7 @@ async fn launch_status(id: &str, offline: bool, new_kind: Kind, action: &str) ->
65 71
66 // Only author or maintainer may change status 72 // Only author or maintainer may change status
67 if proposal.pubkey != user_pubkey && !repo_ref.maintainers.contains(&user_pubkey) { 73 if proposal.pubkey != user_pubkey && !repo_ref.maintainers.contains(&user_pubkey) {
68 bail!("only the PR author or a repository maintainer can {action} a PR"); 74 bail!("only the PR author or a repository maintainer can change the status of a PR");
69 } 75 }
70 76
71 // Fetch existing statuses to check current state 77 // Fetch existing statuses to check current state
@@ -124,8 +130,10 @@ async fn launch_status(id: &str, offline: bool, new_kind: Kind, action: &str) ->
124 repo_ref.maintainers.iter().copied().collect(); 130 repo_ref.maintainers.iter().copied().collect();
125 public_keys.insert(proposal.pubkey); 131 public_keys.insert(proposal.pubkey);
126 132
133 let content = reason.unwrap_or("").to_string();
134
127 let status_event = sign_event( 135 let status_event = sign_event(
128 EventBuilder::new(new_kind, "").tags( 136 EventBuilder::new(new_kind, content).tags(
129 [ 137 [
130 vec![ 138 vec![
131 Tag::custom( 139 Tag::custom(
@@ -159,7 +167,7 @@ async fn launch_status(id: &str, offline: bool, new_kind: Kind, action: &str) ->
159 .concat(), 167 .concat(),
160 ), 168 ),
161 &signer, 169 &signer,
162 format!("{action} PR"), 170 format!("PR {action}"),
163 ) 171 )
164 .await?; 172 .await?;
165 173
@@ -178,22 +186,25 @@ async fn launch_status(id: &str, offline: bool, new_kind: Kind, action: &str) ->
178 .await?; 186 .await?;
179 187
180 println!( 188 println!(
181 "PR {} {}d: {}", 189 "PR {} {action}: {}",
182 &event_id.to_hex()[..8], 190 &event_id.to_hex()[..8],
183 action,
184 proposal.pubkey.to_bech32().unwrap_or_default() 191 proposal.pubkey.to_bech32().unwrap_or_default()
185 ); 192 );
186 Ok(()) 193 Ok(())
187} 194}
188 195
189pub async fn launch_close(id: &str, offline: bool) -> Result<()> { 196pub async fn launch_close(id: &str, offline: bool) -> Result<()> {
190 launch_status(id, offline, Kind::GitStatusClosed, "close").await 197 launch_status(id, offline, Kind::GitStatusClosed, "closed", None).await
191} 198}
192 199
193pub async fn launch_reopen(id: &str, offline: bool) -> Result<()> { 200pub async fn launch_reopen(id: &str, offline: bool) -> Result<()> {
194 launch_status(id, offline, Kind::GitStatusOpen, "reopen").await 201 launch_status(id, offline, Kind::GitStatusOpen, "reopened", None).await
195} 202}
196 203
197pub async fn launch_ready(id: &str, offline: bool) -> Result<()> { 204pub async fn launch_ready(id: &str, offline: bool) -> Result<()> {
198 launch_status(id, offline, Kind::GitStatusOpen, "mark as ready").await 205 launch_status(id, offline, Kind::GitStatusOpen, "marked as ready", None).await
206}
207
208pub async fn launch_draft(id: &str, offline: bool) -> Result<()> {
209 launch_status(id, offline, Kind::GitStatusDraft, "converted to draft", None).await
199} 210}