hive-forge: explain the pr-blocked-by-issue dependency failure instead of a raw 500
This commit is contained in:
parent
b2ee674415
commit
ad7a0572cd
2 changed files with 53 additions and 10 deletions
|
|
@ -131,20 +131,28 @@ pub(crate) enum Kind {
|
|||
Issue,
|
||||
}
|
||||
|
||||
/// Verify `number` is the expected kind before a kind-namespaced verb (one
|
||||
/// of the generics that work on both — close/comment/labels/…) acts on it —
|
||||
/// the validation win the `pr <verb>` / `issue <verb>` split buys over the
|
||||
/// old generic verbs. Forgejo's `/issues/{n}` endpoint serves both issues and
|
||||
/// PRs and marks PRs with a non-null `pull_request` field, so one GET
|
||||
/// classifies it. Errors with a "use the other command" message on mismatch.
|
||||
pub(crate) fn assert_kind(client: &Client, number: u64, expected: Kind) -> Result<()> {
|
||||
let (owner, name) = client.owner_repo()?;
|
||||
/// Whether `number` is a PR rather than a plain issue. Forgejo's
|
||||
/// `/issues/{n}` endpoint serves both and marks PRs with a non-null
|
||||
/// `pull_request` field, so one GET classifies it — shared by
|
||||
/// [`assert_kind`] and by `dependency`'s failure-diagnosis path, which
|
||||
/// needs the same classification without wanting an error on mismatch.
|
||||
pub(crate) fn is_pr(client: &Client, owner: &str, name: &str, number: u64) -> Result<bool> {
|
||||
let issue = client
|
||||
.api()
|
||||
.issue_get_issue(owner, name, index(number)?)
|
||||
.send()?;
|
||||
let is_pr = issue.pull_request.is_some();
|
||||
match (expected, is_pr) {
|
||||
Ok(issue.pull_request.is_some())
|
||||
}
|
||||
|
||||
/// Verify `number` is the expected kind before a kind-namespaced verb (one
|
||||
/// of the generics that work on both — close/comment/labels/…) acts on it —
|
||||
/// the validation win the `pr <verb>` / `issue <verb>` split buys over the
|
||||
/// old generic verbs. Errors with a "use the other command" message on
|
||||
/// mismatch.
|
||||
pub(crate) fn assert_kind(client: &Client, number: u64, expected: Kind) -> Result<()> {
|
||||
let (owner, name) = client.owner_repo()?;
|
||||
let is_pr_result = is_pr(client, owner, name, number)?;
|
||||
match (expected, is_pr_result) {
|
||||
(Kind::Pr, false) => {
|
||||
anyhow::bail!(
|
||||
"#{number} is an issue, not a PR — use `hive-forge issue <verb> {number}`"
|
||||
|
|
|
|||
Loading…
Reference in a new issue