Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions crates/agentdeck-client/src/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,9 @@ pub mod types {
pub updated_at: ::std::string::String,
///Its GitHub page.
pub url: ::std::string::String,
///Why it is yours, in this order: `authored`, `review_requested` (a review request names you), `assigned`; empty once it is none of these, when it is Finished (spec §8). Absent from an older daemon, which read only the PRs you authored.
#[serde(default, skip_serializing_if = "::std::vec::Vec::is_empty")]
pub yours: ::std::vec::Vec<agentdeck_core::Yours>,
}
impl PullRequest {
pub fn builder() -> builder::PullRequest {
Expand Down Expand Up @@ -2887,6 +2890,10 @@ pub mod types {
unreachable: ::std::result::Result<bool, ::std::string::String>,
updated_at: ::std::result::Result<::std::string::String, ::std::string::String>,
url: ::std::result::Result<::std::string::String, ::std::string::String>,
yours: ::std::result::Result<
::std::vec::Vec<agentdeck_core::Yours>,
::std::string::String,
>,
}
impl ::std::default::Default for PullRequest {
fn default() -> Self {
Expand All @@ -2906,6 +2913,7 @@ pub mod types {
unreachable: Err("no value supplied for unreachable".to_string()),
updated_at: Err("no value supplied for updated_at".to_string()),
url: Err("no value supplied for url".to_string()),
yours: Ok(Default::default()),
}
}
}
Expand Down Expand Up @@ -3060,6 +3068,16 @@ pub mod types {
.map_err(|e| format!("error converting supplied value for url: {e}"));
self
}
pub fn yours<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::vec::Vec<agentdeck_core::Yours>>,
T::Error: ::std::fmt::Display,
{
self.yours = value
.try_into()
.map_err(|e| format!("error converting supplied value for yours: {e}"));
self
}
}
impl ::std::convert::TryFrom<PullRequest> for super::PullRequest {
type Error = super::error::ConversionError;
Expand All @@ -3082,6 +3100,7 @@ pub mod types {
unreachable: value.unreachable?,
updated_at: value.updated_at?,
url: value.url?,
yours: value.yours?,
})
}
}
Expand All @@ -3103,6 +3122,7 @@ pub mod types {
unreachable: Ok(value.unreachable),
updated_at: Ok(value.updated_at),
url: Ok(value.url),
yours: Ok(value.yours),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/agentdeck-core/src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use serde::{Deserialize, Serialize};
/// fails when `openapi.json` changes without a bump.
///
/// `0` is every daemon from before it existed, whose `daemon.json` has no `api_version`.
pub const API_VERSION: u32 = 27;
pub const API_VERSION: u32 = 28;

/// What `$XDG_RUNTIME_DIR/agentdeck/daemon.json` holds. The daemon writes it once it serves;
/// the GUI and the CLI read it to reach the daemon.
Expand Down
4 changes: 3 additions & 1 deletion crates/agentdeck-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ pub use daemon::{API_VERSION, DaemonInfo};
pub use id::{PaneId, TabId, WorkspaceId};
pub use layout::{Layout, LayoutError, Ratio, SplitDirection};
pub use pane::{Agent, PaneKind};
pub use pr::{ChecksState, NotAPr, PrRef, PrState, ReviewState, pr_details, prs_details};
pub use pr::{
ChecksState, NotAPr, PrRef, PrState, ReviewState, Yours, pr_details, prs_details, why_yours,
};
pub use repository::{Linking, NotARepository, RepositoryId, RepositoryName, pr_alerts_muted};
pub use state::AgentState;
pub use text_enum::UnknownValue;
Expand Down
112 changes: 112 additions & 0 deletions crates/agentdeck-core/src/pr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,44 @@ text_enum! {
}
}

text_enum! {
/// Why a pull request is yours (spec §8): PR sync keeps the ones you authored, the ones
/// where your review is requested and the ones assigned to you. One can be yours several
/// ways at once, and an open one that is yours no way at all is Finished.
pub enum Yours ("why it's yours") {
/// You opened it.
Authored => "authored",
/// Its review requests name you.
ReviewRequested => "review_requested",
/// Its assignees include you.
Assigned => "assigned",
}
}

/// Why a pull request is yours, the signed-in `login`'s (spec §8), in [`Yours::ALL`]'s order,
/// as GitHub shows it: its `author`'s login (`None` once that account is gone), the logins
/// its review requests name (a team's request names no login) and its assignees' logins.
/// Logins match ignoring case, as GitHub's do. Empty when it is none of these.
pub fn why_yours<'a>(
login: &str,
author: Option<&str>,
requested: impl IntoIterator<Item = &'a str>,
assignees: impl IntoIterator<Item = &'a str>,
) -> Vec<Yours> {
let me = |other: &str| other.eq_ignore_ascii_case(login);
let authored = author.is_some_and(me);
let requested = requested.into_iter().any(me);
let assigned = assignees.into_iter().any(me);
[
(authored, Yours::Authored),
(requested, Yours::ReviewRequested),
(assigned, Yours::Assigned),
]
.into_iter()
.filter_map(|(yes, why)| yes.then_some(why))
.collect()
}

/// What **Copy PR details** puts on the clipboard for one pull request (spec §11): three lines
/// of plain text that also read as markdown. Its reference and title, its GitHub page, then the
/// branch it merges from and the one it merges into:
Expand Down Expand Up @@ -328,4 +366,78 @@ mod tests {
assert_eq!(texts, ["approved", "changes_requested", "review_required"]);
}
}

mod yours {
use super::*;

#[test]
fn should_use_the_spec_column_values() {
let texts: Vec<_> = Yours::ALL.iter().map(|s| s.as_str()).collect();
assert_eq!(texts, ["authored", "review_requested", "assigned"]);
}
}

mod why_yours {
use super::*;

const NOBODY: [&str; 0] = [];

#[test]
fn should_be_authored_when_you_opened_it() {
assert_eq!(
why_yours("octocat", Some("octocat"), NOBODY, NOBODY),
[Yours::Authored]
);
}

#[test]
fn should_be_review_requested_when_a_request_names_you() {
assert_eq!(
why_yours("octocat", Some("hubot"), ["monalisa", "octocat"], NOBODY),
[Yours::ReviewRequested]
);
}

#[test]
fn should_be_assigned_when_you_are_an_assignee() {
assert_eq!(
why_yours("octocat", Some("hubot"), NOBODY, ["octocat"]),
[Yours::Assigned]
);
}

#[test]
fn should_give_every_way_it_is_yours_in_order() {
assert_eq!(
why_yours(
"octocat",
Some("octocat"),
["octocat"],
["hubot", "octocat"]
),
[Yours::Authored, Yours::ReviewRequested, Yours::Assigned]
);
}

#[test]
fn should_match_logins_ignoring_case() {
assert_eq!(
why_yours("OctoCat", Some("octocat"), ["OCTOCAT"], ["octoCat"]),
[Yours::Authored, Yours::ReviewRequested, Yours::Assigned]
);
}

#[test]
fn should_be_none_once_your_review_and_assignment_are_gone() {
assert_eq!(
why_yours("octocat", Some("hubot"), ["monalisa"], ["hubot"]),
[]
);
}

#[test]
fn should_not_be_authored_when_its_authors_account_is_gone() {
assert_eq!(why_yours("octocat", None, NOBODY, NOBODY), []);
}
}
}
3 changes: 2 additions & 1 deletion crates/agentdeck-gui/src/overview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ pub(crate) mod fixtures {
PrSyncStatus, PullRequest, Repository, RepositoryLinks, Workspace,
};
use agentdeck_core::{
AgentState, PaneId, PrRef, PrState, RepositoryId, RepositoryName, WorkspaceId,
AgentState, PaneId, PrRef, PrState, RepositoryId, RepositoryName, WorkspaceId, Yours,
};

use super::{PaneState, Snapshot};
Expand Down Expand Up @@ -374,6 +374,7 @@ pub(crate) mod fixtures {
finished: false,
updated_at: CREATED.into(),
url: format!("https://github.com/{repo}/pull/{n}"),
yours: vec![Yours::Authored],
}
}

Expand Down
37 changes: 36 additions & 1 deletion crates/agentdeck-gui/src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2748,7 +2748,7 @@ mod tests {
/// in the Pull requests view, muted by the Workspaces linking its Repository.
mod pr_alerts {
use agentdeck_client::types::PullRequest;
use agentdeck_core::{RepositoryId, ReviewState};
use agentdeck_core::{RepositoryId, ReviewState, Yours};

use super::*;
use crate::gui_state;
Expand Down Expand Up @@ -2882,6 +2882,41 @@ mod tests {

assert_eq!(open.shown(), []);
}

#[gpui::test]
fn should_never_alert_for_a_pr_you_review_or_are_assigned(cx: &mut TestAppContext) {
// Someone else's: yours as a reviewer, as an assignee, and as both.
let theirs = |n, yours: &[Yours], checks, review| PullRequest {
author: Some("hubot".into()),
yours: yours.to_vec(),
review,
..pr(n, "acme/web", checks)
};
let ways: [&[Yours]; 3] = [
&[Yours::ReviewRequested],
&[Yours::Assigned],
&[Yours::ReviewRequested, Yours::Assigned],
];
let required = Some(ReviewState::ReviewRequired);
let before = (ways.iter().zip(5..))
.map(|(yours, n)| theirs(n, yours, ChecksState::Pending, required))
.collect();
let after = [
Some(ReviewState::Approved),
Some(ReviewState::ChangesRequested),
];
let mut open = Open::new(holding(before), cx);

for review in after {
open.sync(
(ways.iter().zip(5..))
.map(|(yours, n)| theirs(n, yours, ChecksState::Failure, review))
.collect(),
);
}

assert_eq!(open.shown(), []);
}
}

mod one_per_pr {
Expand Down
1 change: 1 addition & 0 deletions crates/agentdeck/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,7 @@ mod tests {
reference.repository(),
reference.number()
),
yours: vec![agentdeck_core::Yours::Authored],
}
}

Expand Down
76 changes: 52 additions & 24 deletions crates/agentdeck/tests/integration/pr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ mod pr_sync {
fn should_run_a_full_sync_though_an_incremental_one_is_due() {
use crate::support::github::{Pr, mock_open_prs};
let github = httpmock::MockServer::start();
let seven = Pr {
repo: "acme/widgets",
number: 7,
};
let seven = Pr::open("acme/widgets", 7);
let mocks = mock_open_prs(&github, "gho_test", &[seven]);
let env = TestEnv::with_github(&github.url("/graphql"), "gho_test");

Expand Down Expand Up @@ -69,16 +66,10 @@ mod pr_ls {
}

fn widgets(number: i64) -> Pr {
Pr {
repo: "acme/widgets",
number,
}
Pr::open("acme/widgets", number)
}

const GADGET: Pr = Pr {
repo: "acme/gadgets",
number: 9,
};
const GADGET: Pr = Pr::open("acme/gadgets", 9);

#[test]
fn should_list_each_pr_by_its_reference_with_its_state() {
Expand Down Expand Up @@ -129,6 +120,52 @@ mod pr_ls {
assert!(pr["repository"]["id"].is_u64(), "{pr}");
}

#[test]
fn should_list_prs_you_review_or_are_assigned_with_why_each_is_yours_with_json() {
let github = MockServer::start();
let review = Pr {
author: "hubot",
requested: true,
..widgets(8)
};
let assigned = Pr {
author: "hubot",
assigned: true,
..GADGET
};
let env = synced(&github, &[widgets(7), review, assigned]);

let stdout = env.ok(&["pr", "ls"]);
let prs = env.json(&["pr", "ls"]);

assert_eq!(
stdout,
"PR STATE TITLE\n\
acme/gadgets#9 open PR 9\n\
acme/widgets#7 open PR 7\n\
acme/widgets#8 open PR 8\n"
);
let yours: Vec<(String, Value)> = (prs.as_array().expect("a list").iter())
.map(|pr| {
(
pr["reference"].as_str().unwrap().to_owned(),
pr["yours"].clone(),
)
})
.collect();
assert_eq!(
yours,
[
("acme/gadgets#9".to_owned(), serde_json::json!(["assigned"])),
("acme/widgets#7".to_owned(), serde_json::json!(["authored"])),
(
"acme/widgets#8".to_owned(),
serde_json::json!(["review_requested"])
),
]
);
}

#[test]
fn should_list_only_the_pull_requests_of_the_repositories_a_workspace_links() {
let github = MockServer::start();
Expand Down Expand Up @@ -199,18 +236,9 @@ mod pr_close {

const TOKEN: &str = "gho_test";

const SEVEN: Pr = Pr {
repo: "acme/widgets",
number: 7,
};
const EIGHT: Pr = Pr {
repo: "acme/widgets",
number: 8,
};
const NINE: Pr = Pr {
repo: "acme/gadgets",
number: 9,
};
const SEVEN: Pr = Pr::open("acme/widgets", 7);
const EIGHT: Pr = Pr::open("acme/widgets", 8);
const NINE: Pr = Pr::open("acme/gadgets", 9);

/// A world whose daemon has synced `prs`.
fn synced(github: &MockServer, prs: &[Pr]) -> TestEnv {
Expand Down
Loading