fix(#1233): subscription --watch uses PUT, GET handles 404 as not-watching
This commit is contained in:
parent
34bc4c0b06
commit
d3239fef35
2 changed files with 36 additions and 7 deletions
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
use anyhow::Result;
|
||||
use clap::Args as ClapArgs;
|
||||
use serde_json::{Value, json};
|
||||
use serde_json::json;
|
||||
|
||||
use crate::client::Client;
|
||||
use crate::verbs::print_json;
|
||||
|
|
@ -34,7 +34,8 @@ pub fn run(client: &Client, args: Args) -> Result<()> {
|
|||
} else {
|
||||
(true, false)
|
||||
};
|
||||
let resp = client.post_json(
|
||||
// Forgejo requires PUT (not POST) for this endpoint.
|
||||
let resp = client.put_json(
|
||||
&format!("/repos/{repo}/subscription"),
|
||||
&json!({ "subscribed": subscribed, "ignored": ignored }),
|
||||
)?;
|
||||
|
|
@ -43,9 +44,13 @@ pub fn run(client: &Client, args: Args) -> Result<()> {
|
|||
"ignored": resp.get("ignored"),
|
||||
}));
|
||||
}
|
||||
let resp: Value = client.get_json(&format!("/repos/{repo}/subscription"))?;
|
||||
print_json(&json!({
|
||||
"subscribed": resp.get("subscribed"),
|
||||
"ignored": resp.get("ignored"),
|
||||
}))
|
||||
// Forgejo returns 404 when the current user is not watching the repo
|
||||
// (rather than a response with subscribed=false).
|
||||
match client.get_json_optional(&format!("/repos/{repo}/subscription"))? {
|
||||
Some(resp) => print_json(&json!({
|
||||
"subscribed": resp.get("subscribed"),
|
||||
"ignored": resp.get("ignored"),
|
||||
})),
|
||||
None => print_json(&json!({ "subscribed": false, "ignored": false })),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue