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 Tests/StackNudgePanelCoreTests/GitHubFeedTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ final class GitHubFeedTests: XCTestCase {
XCTAssertFalse(body.contains("org:"))
}

func testTheQueryDropsTeamRequestsWhenTeamReviewsAreOff() {
let off = GitHubFeed.query(login: "octocat", teamReviews: false)
XCTAssertTrue(off.contains("user-review-requested:octocat"))
XCTAssertFalse(off.contains(" review-requested:octocat"))
XCTAssertTrue(off.contains("author:octocat"))
XCTAssertFalse(GitHubFeed.query(login: "octocat").contains("user-review-requested"))
}

func testTheEmptyStateNamesTheSettingWhenTeamReviewsAreOff() {
XCTAssertFalse(PullRequestsView.emptyDetail(teamReviews: true).contains("Team review requests"))
XCTAssertTrue(PullRequestsView.emptyDetail(teamReviews: false).contains("Team review requests are hidden"))
}

// Search can return an issue, which comes back as {} in a PR fragment.
func testNonPRResultsAreSkipped() {
let parsed = snapshot(mine: [[:], pr()])
Expand Down Expand Up @@ -251,6 +264,13 @@ final class GitHubFeedTests: XCTestCase {
XCTAssertEqual(rows[1].chips.map(\.text), ["Requested", "from bob"])
}

// Team review requests off: only reviews asked of you by name are listed.
func testTeamRequestsCanBeLeftOut() {
let snap = snapshot(requested: [requested(number: 8, team: "Platform"), requested(number: 7)])
XCTAssertEqual(PRRows.rows(snap, login: login).map(\.label), ["api#7", "api#8"])
XCTAssertEqual(PRRows.rows(snap, login: login, teamReviews: false).map(\.label), ["api#7"])
}

func testAReRequestSaysSo() {
let now = GitHubFeed.isoDate("2027-01-15T09:00:00Z")!
let snap = snapshot(requested: [requested(requestedAt: "2027-01-15T08:00:00Z", reviewedAt: "2027-01-14T12:00:00Z")])
Expand Down
4 changes: 2 additions & 2 deletions Tests/StackNudgePanelCoreTests/IntegrationPageTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ final class IntegrationPageTests: XCTestCase {
XCTAssertEqual(nav.rows(in: .integrationPage(.slack)),
[.slackPaste, .slackIdentity, .slackTest,
.slackEnabled, .slackIdle, .slackDetail, .slackStop])
XCTAssertEqual(nav.rows(in: .integrationPage(.github)), [.githubLinks, .githubActivity, .hideShipped, .connectGithub])
XCTAssertEqual(nav.rows(in: .integrationPage(.github)), [.githubLinks, .githubActivity, .teamReviews, .hideShipped, .connectGithub])
}

// Signed out, the page is somewhere to sign in from; signed in, to sign out.
func testGitHubOffersConnectOrDisconnectButNeverBoth() {
let nav = PanelNav()
nav.githubSignedIn = true
XCTAssertEqual(nav.rows(in: .integrationPage(.github)), [.githubLinks, .githubActivity, .hideShipped, .disconnectGithub])
XCTAssertEqual(nav.rows(in: .integrationPage(.github)), [.githubLinks, .githubActivity, .teamReviews, .hideShipped, .disconnectGithub])
}

// The second card, so "opens the selected one" can't pass as "opens a
Expand Down
5 changes: 3 additions & 2 deletions docs/panel.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ Reachable from the tab strip, `Cmd+,`, or the last `Cmd`-number. A sidebar of ca
| **Appearance** | Floating widget (`Pill`, `Companion` or `Off`), then the pill's own rows: Snap to corners, Widget corner, Widget opacity, Widget type, Mascot, Accent color |
| **Companion** | Size, Count badge, Preview pose, Reset position; **Turn on companion** while it's off. See [Companion](#companion) |
| **Usage** | Quota tracking, Quota alerts, Alert threshold, Poll frequency, Context alert, Show remaining, and the two pi budgets |
| **Integrations** | A card each for Slack and GitHub, with where it stands on the right; `→` or `⏎` opens its page. Slack's: paste setup, detected user, test message, on/off, idle threshold, message text, finished turns. GitHub's: PR links, GitHub activity, Hide shipped, Connect GitHub (or Disconnect once signed in). Each page's first line says what it's doing or what's wrong |
| **Integrations** | A card each for Slack and GitHub, with where it stands on the right; `→` or `⏎` opens its page. Slack's: paste setup, detected user, test message, on/off, idle threshold, message text, finished turns. GitHub's: PR links, GitHub activity, Team review requests, Hide shipped, Connect GitHub (or Disconnect once signed in). Each page's first line says what it's doing or what's wrong |
| **Extensions** | What's installed, then **Browse extensions** (see [Extensions](#extensions)) |
| **MCP** | **Set up for…**, whose page has a card each for Claude Code, Claude Desktop and Codex: `⏎` copies what adds stack-nudge to it, and a tick shows once its config has it. Then MCP clients can change settings. See [the local MCP server](design/local-mcp.md) |
| **Panel** | Hotkey, Pin panel, Keep open when empty, Launch at login, Name from tab titles |
Expand Down Expand Up @@ -213,6 +213,7 @@ Opt-in GitHub linking adds real **PR + CI status** (so even squash-merged work r
|-----|--------------|
| `STACKNUDGE_GITHUB` | `true` to enable GitHub PR/CI linking (off by default) |
| `STACKNUDGE_GITHUB_ACTIVITY` | `true` for GitHub activity events and the PRs tab (off by default; needs the sign-in above) |
| `STACKNUDGE_GITHUB_TEAM_REVIEWS` | `false` to leave reviews asked only of your teams out of the PRs tab, and out of the search so they can't crowd direct ones out (on by default) |
| `STACKNUDGE_GITHUB_CLIENT_ID` | Override the embedded OAuth app Client ID (rarely needed) |
| `STACKNUDGE_TICKET_URL` | Deep-link template for ticket rows, e.g. `https://linear.app/acme/issue/{key}`; `{key}` is replaced with the ticket |
| `STACKNUDGE_HIDE_SHIPPED` | `true` to drop groups once their PR reads merged, keeping the list on in-flight work |
Expand All @@ -236,7 +237,7 @@ With **Settings → Integrations → GitHub → GitHub activity** on (`STACKNUDG

If the GitHub CLI (`gh`) is installed and logged in, these requests and PR links go through it (`gh api`), so gh sends its own credential and stack-nudge never reads it, and the GitHub page's first line says so ("Signed in with your gh login"); otherwise it uses its own sign-in. That matters for an org that restricts third-party OAuth apps: until an owner approves stack-nudge's app, its own sign-in can't see the org's private repos, while a `gh` login usually can. `STACKNUDGE_GITHUB_USE_GH=false` always uses the sign-in. It searches by your login across GitHub, with no org filter. The first check records what is already there without announcing it, and its state lives in `~/.stack-nudge/github-feed.json`, so a relaunch announces nothing twice. `⏎` on one of these events opens it on GitHub.

The same check fills a **PRs** tab, shown while GitHub activity is on: your open PRs (with draft, review, CI and conflict chips) and the PRs waiting on your review, asked of you by name first, then through your teams (marked with the team). `↑↓` select, `⏎` or a click opens the PR, `⌘↑` / `⌘↓` jump to the first / last row, `Esc` hides.
The same check fills a **PRs** tab, shown while GitHub activity is on: your open PRs (with draft, review, CI and conflict chips) and the PRs waiting on your review, asked of you by name first, then through your teams (marked with the team). Turn off **Team review requests** on the GitHub page to list only the ones asked of you by name; team requests never become events either way. `↑↓` select, `⏎` or a click opens the PR, `⌘↑` / `⌘↓` jump to the first / last row, `Esc` hides.

## Extensions

Expand Down
8 changes: 5 additions & 3 deletions panel/GitHubFeed.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ enum GitHubFeed {
// reviews asked of you are yours wherever they live.
// `review-requested` covers requests to you and to your teams. Only direct
// ones become events (team requests land on nearly every PR and would
// drown the rest); the PRs tab lists both, each marked.
static func query(login: String) -> String {
// drown the rest); the PRs tab lists both, each marked. With team reviews
// off the search is `user-review-requested`, so team requests can't fill
// the 50 results and push direct ones out.
static func query(login: String, teamReviews: Bool = true) -> String {
let pr = """
number title url isDraft reviewDecision mergeable \
repository{nameWithOwner} \
Expand All @@ -38,7 +40,7 @@ enum GitHubFeed {
"query": graphql,
"variables": [
"mine": "is:pr is:open author:\(login) archived:false",
"requested": "is:pr is:open review-requested:\(login) archived:false",
"requested": "is:pr is:open \(teamReviews ? "review-requested" : "user-review-requested"):\(login) archived:false",
],
]
let data = (try? JSONSerialization.data(withJSONObject: body)) ?? Data()
Expand Down
7 changes: 6 additions & 1 deletion panel/GitHubFeedPoller.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ final class GitHubFeedPoller {
// body -> response; nil when there is no way to reach GitHub (no gh
// login and no sign-in), which skips the poll.
private let run: (String) -> String?
// Only touched on `queue`; set through setTeamReviews from the settings sink.
private var teamReviews = true
private let deliver: ([NudgeEvent]) -> Void // called on main
// Every successful poll's lists, for the PRs tab; called on main.
private let snapshot: (GitHubFeed.Snapshot, String) -> Void
Expand Down Expand Up @@ -43,6 +45,9 @@ final class GitHubFeedPoller {
}
}

// Applies from the next poll.
func setTeamReviews(_ on: Bool) { queue.async { [weak self] in self?.teamReviews = on } }

func pollNow() { queue.async { [weak self] in self?.poll() } }

private func poll() {
Expand All @@ -51,7 +56,7 @@ final class GitHubFeedPoller {
defer { polling = false }
if login == nil { login = run(GitHubFeed.viewerQuery).flatMap(GitHubFeed.parseViewer) }
guard let login,
let response = run(GitHubFeed.query(login: login)),
let response = run(GitHubFeed.query(login: login, teamReviews: teamReviews)),
let snapshot = GitHubFeed.parse(response)
else { return }
let result = GitHubFeed.diff(snapshot, previous: Self.loadState(), login: login, now: Date())
Expand Down
11 changes: 11 additions & 0 deletions panel/Panel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1705,6 +1705,17 @@ final class PanelController: NSObject, NSApplicationDelegate, PanelKeyDelegate,
self?.nav.pullRequestLogin = login
})
githubFeed = feed
// Before setEnabled, so the first poll already searches the right way.
// Turning team requests back on fetches them now, not at the next tick.
nav.$githubTeamReviews
.removeDuplicates()
.sink { feed.setTeamReviews($0) }
.store(in: &cancellables)
nav.$githubTeamReviews
.removeDuplicates()
.dropFirst()
.sink { [weak self] _ in if self?.nav.githubActivityEnabled == true { feed.pollNow() } }
.store(in: &cancellables)
nav.$githubActivityEnabled
.removeDuplicates()
.sink { feed.setEnabled($0) }
Expand Down
23 changes: 18 additions & 5 deletions panel/PanelNav.swift
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ enum SettingsRow: Hashable {
case quotaTracking, quotaAlerts, alertThreshold, pollFrequency, contextAlert, showRemaining
case piApiBudget, piLocalBudget
case awayLock
case githubLinks, githubActivity, hideShipped, connectGithub, disconnectGithub
case githubLinks, githubActivity, teamReviews, hideShipped, connectGithub, disconnectGithub
case historyPerSession
case editPhrases, checkPermissions, openConfig, releaseNotes, updateChannel, checkUpdates, uninstall, quit
// The local MCP server (docs/design/local-mcp.md): the door to the page of
Expand Down Expand Up @@ -275,7 +275,7 @@ extension SettingsRow: CaseIterable {
.quotaTracking, .quotaAlerts, .alertThreshold, .pollFrequency,
.contextAlert, .showRemaining, .piApiBudget, .piLocalBudget,
.awayLock,
.githubLinks, .githubActivity, .hideShipped, .connectGithub, .disconnectGithub,
.githubLinks, .githubActivity, .teamReviews, .hideShipped, .connectGithub, .disconnectGithub,
.historyPerSession,
.editPhrases, .checkPermissions, .openConfig, .releaseNotes,
.updateChannel, .checkUpdates, .uninstall, .quit,
Expand Down Expand Up @@ -669,8 +669,12 @@ final class PanelNav: ObservableObject {
@Published var pullRequestLogin: String?
@Published var prSelectedIndex = 0

// The PRs tab lists reviews asked of your teams too, unless this is off
// (STACKNUDGE_GITHUB_TEAM_REVIEWS). Events only ever take direct requests.
@Published var githubTeamReviews: Bool = true

var pullRequestRows: [PRRow] {
pullRequestSnapshot.map { PRRows.rows($0, login: pullRequestLogin) } ?? []
pullRequestSnapshot.map { PRRows.rows($0, login: pullRequestLogin, teamReviews: githubTeamReviews) } ?? []
}

func movePullRequestSelection(_ delta: Int) {
Expand Down Expand Up @@ -883,6 +887,12 @@ final class PanelNav: ObservableObject {
}
}

func setGithubTeamReviews(_ on: Bool) {
githubTeamReviews = on
ConfigFile.write(key: "STACKNUDGE_GITHUB_TEAM_REVIEWS", value: on ? "true" : "false")
prSelectedIndex = min(prSelectedIndex, max(0, pullRequestRows.count - 1))
}

func toggleHideShipped() {
hideShippedTickets.toggle()
ConfigFile.write(key: "STACKNUDGE_HIDE_SHIPPED",
Expand Down Expand Up @@ -1737,7 +1747,7 @@ final class PanelNav: ObservableObject {
// Connect while signed out, Disconnect once signed in: the page is
// somewhere to sign in from, not only to sign out.
case .integrationPage(.github):
return [.githubLinks, .githubActivity, .hideShipped, githubSignedIn ? .disconnectGithub : .connectGithub]
return [.githubLinks, .githubActivity, .teamReviews, .hideShipped, githubSignedIn ? .disconnectGithub : .connectGithub]
case .mcp:
return [.mcpSetupClients, .mcpWrites]
case .mcpSetupPage:
Expand Down Expand Up @@ -2007,6 +2017,7 @@ final class PanelNav: ObservableObject {
githubLinkingEnabled = ConfigFile.bool(config, "STACKNUDGE_GITHUB", default: false)
githubActivityEnabled = ConfigFile.bool(config, "STACKNUDGE_GITHUB_ACTIVITY", default: false)
hideShippedTickets = ConfigFile.bool(config, "STACKNUDGE_HIDE_SHIPPED", default: false)
githubTeamReviews = ConfigFile.bool(config, "STACKNUDGE_GITHUB_TEAM_REVIEWS", default: true)
githubUseGH = ConfigFile.bool(config, "STACKNUDGE_GITHUB_USE_GH", default: true)
githubSignedIn = githubUsesCLILogin || GitHubAuth.token() != nil
refreshGitHubCLILogin()
Expand Down Expand Up @@ -2388,7 +2399,7 @@ final class PanelNav: ObservableObject {
.keepOpenWhenEmpty, .launchAtLogin, .snapToCorners, .companionBadge,
.soundEnabled, .voiceEnabled,
.quotaTracking, .quotaAlerts, .showRemaining,
.githubLinks, .githubActivity, .hideShipped, .eventHistory,
.githubLinks, .githubActivity, .teamReviews, .hideShipped, .eventHistory,
.slackEnabled, .slackDetail, .slackStop, .awayLock, .mcpWrites:
return false
case .permissions, .update, .extensionUpdates, .hotkey, .speakHotkey, .downloadVoiceModel:
Expand Down Expand Up @@ -2733,6 +2744,8 @@ final class PanelNav: ObservableObject {
githubActivityEnabled.toggle()
ConfigFile.write(key: "STACKNUDGE_GITHUB_ACTIVITY", value: githubActivityEnabled ? "true" : "false")
refreshGitHubCLILogin()
case .teamReviews:
setGithubTeamReviews(!githubTeamReviews)
case .hideShipped:
toggleHideShipped()
case .slackEnabled:
Expand Down
15 changes: 12 additions & 3 deletions panel/PullRequestsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ enum PRRows {

// Mine first, then To review, each in GitHub's search order (most
// recently updated first).
static func rows(_ snapshot: GitHubFeed.Snapshot, login: String?, now: Date = Date()) -> [PRRow] {
// `teamReviews` false leaves out reviews asked only of your teams.
static func rows(_ snapshot: GitHubFeed.Snapshot, login: String?, teamReviews: Bool = true,
now: Date = Date()) -> [PRRow] {
let mine = snapshot.mine.map { pr -> PRRow in
// One review-state label, as in Hounder: a decision outranks draft.
var chips: [PRRow.Chip] = []
Expand All @@ -47,7 +49,7 @@ enum PRRows {
}
// Asked of you by name first, then through a team.
let direct = snapshot.requested.filter { pr in login.map { pr.isDirect(login: $0) } ?? false }
let viaTeam = snapshot.requested.filter { pr in !(login.map { pr.isDirect(login: $0) } ?? false) }
let viaTeam = teamReviews ? snapshot.requested.filter { pr in !(login.map { pr.isDirect(login: $0) } ?? false) } : []
Comment thread
adefreitas marked this conversation as resolved.
Resolved
let review = (direct + viaTeam).map { pr -> PRRow in
var chips: [PRRow.Chip] = [.init(text: "Requested", tone: .requested)]
Comment thread
adefreitas marked this conversation as resolved.
Resolved
if let login, pr.isDirect(login: login) {
Expand Down Expand Up @@ -98,6 +100,13 @@ struct PullRequestsView: View {
]
}

// With team reviews off they aren't fetched, so there is no count to give.
static func emptyDetail(teamReviews: Bool) -> String {
teamReviews
? "No open pull requests of yours, and no reviews waiting on you."
: "No open pull requests of yours, and no reviews asked of you by name. Team review requests are hidden: Settings → Integrations → GitHub."
}

@ViewBuilder
private var content: some View {
let rows = nav.pullRequestRows
Expand All @@ -106,7 +115,7 @@ struct PullRequestsView: View {
} else if nav.pullRequestSnapshot == nil {
message("Loading your pull requests…", "The first check runs a few seconds after GitHub activity is turned on.")
} else if rows.isEmpty {
message("Nothing open", "No open pull requests of yours, and no reviews waiting on you.")
message("Nothing open", Self.emptyDetail(teamReviews: nav.githubTeamReviews))
} else {
ScrollViewReader { proxy in
ScrollView {
Expand Down
1 change: 1 addition & 0 deletions panel/Settings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,7 @@ struct SettingsView: View {
case .slackStop: row(.slackStop, label: "Also notify on finished turns", kind: .toggle, value: nav.slackNotifyOnStop ? "On" : "Off", enabled: nav.slackReady && nav.slackEnabled)
case .githubLinks: row(.githubLinks, label: "GitHub PR links", kind: .toggle, value: nav.githubLinkingEnabled ? "On" : "Off")
case .githubActivity: row(.githubActivity, label: "GitHub activity", kind: .toggle, value: nav.githubActivityEnabled ? "On" : "Off")
case .teamReviews: row(.teamReviews, label: "Team review requests", kind: .toggle, value: nav.githubTeamReviews ? "On" : "Off", enabled: nav.githubActivityEnabled)
case .hideShipped: row(.hideShipped, label: "Hide shipped", kind: .toggle, value: nav.hideShippedTickets ? "On" : "Off", enabled: nav.githubLinkingEnabled)
case .connectGithub:
let connect = connectGithubRow
Expand Down
2 changes: 2 additions & 0 deletions panel/SettingsRegistry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ enum SettingsRegistry {
kind: .toggle, read: { .bool($0.githubLinkingEnabled) }),
SettingSpec(key: "STACKNUDGE_GITHUB_ACTIVITY", label: "GitHub activity", category: "integrations",
kind: .toggle, read: { .bool($0.githubActivityEnabled) }),
SettingSpec(key: "STACKNUDGE_GITHUB_TEAM_REVIEWS", label: "Team review requests", category: "integrations",
kind: .toggle, read: { .bool($0.githubTeamReviews) }),
SettingSpec(key: "STACKNUDGE_HIDE_SHIPPED", label: "Hide shipped", category: "integrations",
kind: .toggle, read: { .bool($0.hideShippedTickets) }),
// Panel
Expand Down
5 changes: 5 additions & 0 deletions panel/SettingsRegistryWrites.swift
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ extension SettingsRegistry {
nav.refreshGitHubCLILogin()
return nil
},
"STACKNUDGE_GITHUB_TEAM_REVIEWS": { nav, value in
guard case .bool(let on) = value else { return "STACKNUDGE_GITHUB_TEAM_REVIEWS takes true or false." }
nav.setGithubTeamReviews(on)
return nil
},
"STACKNUDGE_HIDE_SHIPPED": { nav, value in
guard case .bool(let on) = value else { return "STACKNUDGE_HIDE_SHIPPED takes true or false." }
if nav.hideShippedTickets != on { nav.toggleHideShipped() }
Expand Down
Loading