diff options
Diffstat (limited to 'src/bin/ngit/sub_commands')
| -rw-r--r-- | src/bin/ngit/sub_commands/issue_status.rs | 30 | ||||
| -rw-r--r-- | src/bin/ngit/sub_commands/pr_status.rs | 29 |
2 files changed, 42 insertions, 17 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)] |
| 33 | async fn launch_status(id: &str, offline: bool, new_kind: Kind, action: &str) -> Result<()> { | 33 | async 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 | ||
| 172 | pub async fn launch_close(id: &str, offline: bool) -> Result<()> { | 182 | pub 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 | ||
| 176 | pub async fn launch_reopen(id: &str, offline: bool) -> Result<()> { | 186 | pub 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 | |||
| 190 | pub async fn launch_resolved(id: &str, offline: bool, reason: Option<&str>) -> Result<()> { | ||
| 191 | launch_status(id, offline, Kind::GitStatusApplied, "resolved", reason).await | ||
| 178 | } | 192 | } |
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)] |
| 33 | async fn launch_status(id: &str, offline: bool, new_kind: Kind, action: &str) -> Result<()> { | 33 | async 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 | ||
| 189 | pub async fn launch_close(id: &str, offline: bool) -> Result<()> { | 196 | pub 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 | ||
| 193 | pub async fn launch_reopen(id: &str, offline: bool) -> Result<()> { | 200 | pub 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 | ||
| 197 | pub async fn launch_ready(id: &str, offline: bool) -> Result<()> { | 204 | pub 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 | |||
| 208 | pub async fn launch_draft(id: &str, offline: bool) -> Result<()> { | ||
| 209 | launch_status(id, offline, Kind::GitStatusDraft, "converted to draft", None).await | ||
| 199 | } | 210 | } |