upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/bin/ngit/sub_commands/issue_status.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/ngit/sub_commands/issue_status.rs')
-rw-r--r--src/bin/ngit/sub_commands/issue_status.rs30
1 files changed, 22 insertions, 8 deletions
diff --git a/src/bin/ngit/sub_commands/issue_status.rs b/src/bin/ngit/sub_commands/issue_status.rs
index 3facee3..840ab8e 100644
--- a/src/bin/ngit/sub_commands/issue_status.rs
+++ b/src/bin/ngit/sub_commands/issue_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")?;
@@ -64,7 +70,7 @@ async fn launch_status(id: &str, offline: bool, new_kind: Kind, action: &str) ->
64 70
65 // Only author or maintainer may change status 71 // Only author or maintainer may change status
66 if issue.pubkey != user_pubkey && !repo_ref.maintainers.contains(&user_pubkey) { 72 if issue.pubkey != user_pubkey && !repo_ref.maintainers.contains(&user_pubkey) {
67 bail!("only the issue author or a repository maintainer can {action} an issue"); 73 bail!("only the issue author or a repository maintainer can change the status of an issue");
68 } 74 }
69 75
70 // Fetch existing statuses to check current state 76 // Fetch existing statuses to check current state
@@ -96,6 +102,7 @@ async fn launch_status(id: &str, offline: bool, new_kind: Kind, action: &str) ->
96 let status_str = match new_kind { 102 let status_str = match new_kind {
97 Kind::GitStatusOpen => "open", 103 Kind::GitStatusOpen => "open",
98 Kind::GitStatusClosed => "closed", 104 Kind::GitStatusClosed => "closed",
105 Kind::GitStatusApplied => "resolved",
99 _ => "unknown", 106 _ => "unknown",
100 }; 107 };
101 println!("issue is already {status_str}"); 108 println!("issue is already {status_str}");
@@ -105,6 +112,7 @@ async fn launch_status(id: &str, offline: bool, new_kind: Kind, action: &str) ->
105 let alt_text = match new_kind { 112 let alt_text = match new_kind {
106 Kind::GitStatusOpen => "issue reopened", 113 Kind::GitStatusOpen => "issue reopened",
107 Kind::GitStatusClosed => "issue closed", 114 Kind::GitStatusClosed => "issue closed",
115 Kind::GitStatusApplied => "issue resolved",
108 _ => "issue status updated", 116 _ => "issue status updated",
109 }; 117 };
110 118
@@ -112,8 +120,10 @@ async fn launch_status(id: &str, offline: bool, new_kind: Kind, action: &str) ->
112 repo_ref.maintainers.iter().copied().collect(); 120 repo_ref.maintainers.iter().copied().collect();
113 public_keys.insert(issue.pubkey); 121 public_keys.insert(issue.pubkey);
114 122
123 let content = reason.unwrap_or("").to_string();
124
115 let status_event = sign_event( 125 let status_event = sign_event(
116 EventBuilder::new(new_kind, "").tags( 126 EventBuilder::new(new_kind, content).tags(
117 [ 127 [
118 vec![ 128 vec![
119 Tag::custom( 129 Tag::custom(
@@ -147,7 +157,7 @@ async fn launch_status(id: &str, offline: bool, new_kind: Kind, action: &str) ->
147 .concat(), 157 .concat(),
148 ), 158 ),
149 &signer, 159 &signer,
150 format!("{action} issue"), 160 format!("issue {action}"),
151 ) 161 )
152 .await?; 162 .await?;
153 163
@@ -165,14 +175,18 @@ async fn launch_status(id: &str, offline: bool, new_kind: Kind, action: &str) ->
165 ) 175 )
166 .await?; 176 .await?;
167 177
168 println!("issue {} {}d", &event_id.to_hex()[..8], action,); 178 println!("issue {} {action}", &event_id.to_hex()[..8]);
169 Ok(()) 179 Ok(())
170} 180}
171 181
172pub async fn launch_close(id: &str, offline: bool) -> Result<()> { 182pub async fn launch_close(id: &str, offline: bool, reason: Option<&str>) -> Result<()> {
173 launch_status(id, offline, Kind::GitStatusClosed, "close").await 183 launch_status(id, offline, Kind::GitStatusClosed, "closed", reason).await
174} 184}
175 185
176pub async fn launch_reopen(id: &str, offline: bool) -> Result<()> { 186pub async fn launch_reopen(id: &str, offline: bool) -> Result<()> {
177 launch_status(id, offline, Kind::GitStatusOpen, "reopen").await 187 launch_status(id, offline, Kind::GitStatusOpen, "reopened", None).await
188}
189
190pub async fn launch_resolved(id: &str, offline: bool, reason: Option<&str>) -> Result<()> {
191 launch_status(id, offline, Kind::GitStatusApplied, "resolved", reason).await
178} 192}