Skip to content

Commit 8ab2cfd

Browse files
committed
feat: re-request review on PRs with changes requested
1 parent dfe1dcb commit 8ab2cfd

11 files changed

Lines changed: 86 additions & 11 deletions

File tree

‎README.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Your PR sits in **In Review** for two days because nobody noticed it. A teammate
3939
- 🚚 **Moves the card for you**: approve and the card goes to the next status (e.g. *Reviewed*); request changes and it goes back to *In Progress* and you're unassigned. Toggle it with *Move Cards After My Review*. When all the PRs of one of your own tasks are merged, it goes to *Ready to Verify* from whatever earlier column it is in (*Move My Merged Tasks to Ready to Verify*). The same goes for a *User Story* split into sub-issues: once all its sub-issues are closed or in *Ready to Verify* (or later), the story moves to *Ready to Verify* too.
4040
- 🔍 **Review state at a glance**: *awaiting review*, *being reviewed*, *changes requested*, *approved*, *merged*, plus the reviewers and CI status (✅ ❌ ⏳).
4141
- 🙋 **Needs reviewer**: teammates' tasks in review with no second assignee, and an **Assign me** button that adds you as the reviewer without opening GitHub (the task then moves to *Reviewing*).
42+
- 🔁 **Re-request review**: when your PR has *changes requested* and you've pushed the fixes, the card shows a **Re-request review** button (also in the right-click menu). It asks those reviewers to look again, moves the card back to the review status and re-assigns them if they were unassigned.
4243
- ⏱️ **Time in status**: an age badge turns orange after 24h and red after 72h.
4344
- 🔔 **Native notifications** when something needs you: a new review, changes requested, approval, failing CI, merged PR, a task moved forward, or a new task waiting for a reviewer. Each kind of event has its own synth sound (needs you, good news, bad news, comment), and you can preview them or switch to the macOS default in the *Sound* menu.
4445
- ⬆️ **Updates itself**: when a new release is out, a popup offers *Update Now* (downloads, installs and reopens in a few seconds, no Terminal or browser) or *Remind Me Later* (asks again the next day). A dot on the ⋯ button and an *Update GitHub Float* menu item stay until you update; *Check for Updates…* is always in the menu.
@@ -106,7 +107,7 @@ Your project needs a single-select **Status** field (the default in GitHub Proje
106107
| **Reviewing** | Items assigned to you where someone else authored the linked PR (or, without a PR, is the first assignee), while the PR is still open. *Your turn* means you have not reviewed yet or a re-review was requested. A task leaves once you approve or request changes. |
107108
| **Needs reviewer** | Open items in the review status (default: *In Review*) **not** assigned to you that have fewer than 2 assignees. The convention: the author is the first assignee, and a reviewer adds themselves as the second one. |
108109

109-
Review stage of each linked PR: merged/closed → draft → approved / changes requested → being reviewed (a review was submitted) → awaiting review (reviewers requested) → no reviewers. Bot reviews and the author's own comments are ignored.
110+
Review stage of each linked PR: merged/closed → draft → approved / changes requested (until every reviewer who asked for changes is re-requested) → being reviewed (a review was submitted) → awaiting review (reviewers requested) → no reviewers. Bot reviews and the author's own comments are ignored.
110111

111112
When you approve a task that is in the review status, GitHub Float moves it to the next status on the board. When you request changes, it moves the task to *In Progress* and removes you from its assignees. Only reviews submitted after the task entered the review status count, so older reviews never move a card back. This needs the `project` scope (`gh auth refresh -s project`).
112113

‎Sources/GitHubFloat/GitHubClient.swift‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ struct RepoNode: Decodable { let name: String }
6161
struct LoginNode: Decodable { let login: String }
6262

6363
struct PRNode: Decodable {
64+
let id: String?
6465
let number: Int
6566
let title: String
6667
let url: String
@@ -288,6 +289,19 @@ actor GitHubClient {
288289
""", ["i": issueId])
289290
}
290291

292+
/// Asks reviewers again (e.g. after addressing their requested changes); keeps the other requests.
293+
func requestReviews(_ logins: [String], on pullRequestId: String) async throws {
294+
try await mutate("""
295+
mutation($p:ID!, $u:[String!]) { requestReviewsByLogin(input:{pullRequestId:$p, userLogins:$u, union:true}) { clientMutationId } }
296+
""", ["p": pullRequestId, "u": logins])
297+
}
298+
299+
func userId(_ login: String) async throws -> String? {
300+
struct R: Decodable { struct U: Decodable { let id: String }; struct D: Decodable { let user: U? }; let data: D? }
301+
let data = try await post("query($l:String!) { user(login:$l) { id } }", ["l": login])
302+
return try JSONDecoder().decode(R.self, from: data).data?.user?.id
303+
}
304+
291305
func addAssignee(_ userId: String, to assignableId: String) async throws {
292306
try await mutate("""
293307
mutation($a:ID!, $u:ID!) { addAssigneesToAssignable(input:{assignableId:$a, assigneeIds:[$u]}) { clientMutationId } }

‎Sources/GitHubFloat/Model.swift‎

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ enum CheckState: String {
9898

9999
struct PullRequest: Identifiable, Hashable {
100100
var id: String { url }
101+
let nodeId: String?
101102
let number: Int
102103
let repo: String
103104
let title: String
@@ -107,11 +108,15 @@ struct PullRequest: Identifiable, Hashable {
107108
private(set) var reviewers: [ReviewerState]
108109
let checks: CheckState?
109110

111+
/// Reviewers whose "changes requested" review hasn't been re-requested yet.
112+
var changesRequestedBy: [String] { reviewers.filter { $0.state == "CHANGES_REQUESTED" }.map(\.login) }
113+
110114
static func isBot(_ login: String) -> Bool {
111115
login.hasSuffix("[bot]") || login.hasPrefix("copilot-")
112116
}
113117

114118
init(_ n: PRNode) {
119+
nodeId = n.id
115120
number = n.number
116121
repo = n.repository.name
117122
title = n.title
@@ -140,7 +145,8 @@ struct PullRequest: Identifiable, Hashable {
140145
else if n.state == "CLOSED" { stage = .closed }
141146
else if n.isDraft { stage = .draft }
142147
else if n.reviewDecision == "APPROVED" { stage = .approved }
143-
else if n.reviewDecision == "CHANGES_REQUESTED" { stage = .changesRequested }
148+
// Once every reviewer who requested changes has been asked again, it's back to waiting for them.
149+
else if n.reviewDecision == "CHANGES_REQUESTED", byLogin.values.contains("CHANGES_REQUESTED") || requested.isEmpty { stage = .changesRequested }
144150
else if submitted { stage = .beingReviewed }
145151
else if !requested.isEmpty { stage = .awaitingReview }
146152
else { stage = .noReviewers }
@@ -395,6 +401,7 @@ final class Store: ObservableObject {
395401
@Published private(set) var changed: Set<String> = []
396402
/// Tasks being assigned to you right now (item ids).
397403
@Published private(set) var assigning: Set<String> = []
404+
@Published private(set) var rerequesting: Set<String> = []
398405

399406
let settings: Settings
400407
private let client = GitHubClient()
@@ -516,6 +523,42 @@ final class Store: ObservableObject {
516523
}
517524
}
518525

526+
/// Your PRs on this task with requested changes, i.e. the ones you can send back to their reviewers.
527+
func reReviewPRs(_ task: BoardTask) -> [PullRequest] {
528+
task.prs.filter { $0.author == viewer && $0.stage == .changesRequested && $0.nodeId != nil && !$0.changesRequestedBy.isEmpty }
529+
}
530+
531+
/// Notifies the reviewers who requested changes that the PR is ready for another look,
532+
/// puts the card back in the review status and the reviewers back as assignees (team convention).
533+
func requestReReview(_ task: BoardTask) {
534+
let prs = reReviewPRs(task)
535+
guard !prs.isEmpty, !rerequesting.contains(task.id) else { return }
536+
let reviewers = Set(prs.flatMap(\.changesRequestedBy))
537+
let reviewOption = task.status == settings.reviewStatus ? nil : option(named: settings.reviewStatus)
538+
rerequesting.insert(task.id)
539+
Task { [weak self] in
540+
guard let self else { return }
541+
do {
542+
for pr in prs { try await client.requestReviews(pr.changesRequestedBy, on: pr.nodeId!) }
543+
if let board, task.kind != "DraftIssue" {
544+
if let id = reviewOption?.id {
545+
try await client.setStatus(projectId: board.projectId, itemId: task.id, fieldId: board.statusFieldId, optionId: id)
546+
}
547+
if let content = task.contentId {
548+
for login in reviewers.subtracting(task.assignees).sorted() {
549+
if let uid = try await client.userId(login) { try await client.addAssignee(uid, to: content) }
550+
}
551+
}
552+
}
553+
error = nil
554+
} catch {
555+
self.error = "Could not re-request review on \(task.title): \(error.localizedDescription)"
556+
}
557+
await refresh()
558+
rerequesting.remove(task.id)
559+
}
560+
}
561+
519562
func acknowledge(_ id: String) { changed.remove(id) }
520563
func acknowledgeAll() { changed.removeAll() }
521564

‎Sources/GitHubFloat/Screenshots.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ enum Screenshots {
9393
let rv = reviews.map { #"{"author":{"login":"\#($0.0)"},"state":"\#($0.1)"}"# }.joined(separator: ",")
9494
let rq = requested.map { #"{"requestedReviewer":{"login":"\#($0)"}}"# }.joined(separator: ",")
9595
let dec = decision.map { "\"\($0)\"" } ?? "null"
96-
return #"{"number":\#(n),"title":"PR \#(n)","url":"https://github.com/acme/x/pull/\#(n)","state":"OPEN","isDraft":\#(draft),"reviewDecision":\#(dec),"author":{"login":"\#(author)"},"repository":{"name":"x"},"assignees":{"nodes":[]},"reviewRequests":{"nodes":[\#(rq)]},"latestReviews":{"nodes":[\#(rv)]},"commits":{"nodes":[{"commit":{"statusCheckRollup":{"state":"\#(checks)"}}}]}}"#
96+
return #"{"id":"PR_\#(n)","number":\#(n),"title":"PR \#(n)","url":"https://github.com/acme/x/pull/\#(n)","state":"OPEN","isDraft":\#(draft),"reviewDecision":\#(dec),"author":{"login":"\#(author)"},"repository":{"name":"x"},"assignees":{"nodes":[]},"reviewRequests":{"nodes":[\#(rq)]},"latestReviews":{"nodes":[\#(rv)]},"commits":{"nodes":[{"commit":{"statusCheckRollup":{"state":"\#(checks)"}}}]}}"#
9797
}
9898

9999
private static func item(_ id: String, repo: String, n: Int, title: String, status: String, hours: Double,

‎Sources/GitHubFloat/Views.swift‎

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,8 @@ struct ContentView: View {
328328
isNew: store.changed.contains(key),
329329
onAssign: tab == .open && (staticLayout || store.canAssignMe(task)) ? { store.assignMe(task) } : nil,
330330
assigning: store.assigning.contains(task.id),
331+
onReReview: tab == .mine && !store.reReviewPRs(task).isEmpty ? { store.requestReReview(task) } : nil,
332+
rerequesting: store.rerequesting.contains(task.id),
331333
accent: accent(task, tab: tab)) { store.acknowledge(key) }
332334
.id(key + task.signature) // redraw when the card moves between sections
333335
}
@@ -460,6 +462,8 @@ struct TaskRow: View {
460462
let isNew: Bool
461463
var onAssign: (() -> Void)? = nil
462464
var assigning = false
465+
var onReReview: (() -> Void)? = nil
466+
var rerequesting = false
463467
/// Outlook-style colored bar on the card's leading edge (the task's status color).
464468
var accent: Color = .gray
465469
let onSeen: () -> Void
@@ -503,7 +507,8 @@ struct TaskRow: View {
503507
Text(task.assignees.first ?? "Unassigned")
504508
Spacer(minLength: 0)
505509
if let onAssign {
506-
assignButton(onAssign)
510+
actionButton("person.crop.circle.badge.plus", "Assign me", busy: assigning ? "Assigning…" : nil,
511+
help: "Add yourself as the reviewer (second assignee) of this task", onAssign)
507512
} else {
508513
Text("needs a reviewer").foregroundStyle(.orange)
509514
}
@@ -519,6 +524,13 @@ struct TaskRow: View {
519524
ForEach(task.prs) { pr in
520525
PRLine(pr: pr, showRepo: pr.repo != task.repo)
521526
}
527+
if let onReReview {
528+
HStack {
529+
Spacer(minLength: 0)
530+
actionButton("arrow.triangle.2.circlepath", "Re-request review", busy: rerequesting ? "Requesting…" : nil,
531+
help: "Changes done? Notify the reviewers who requested changes to review again", onReReview)
532+
}
533+
}
522534
}
523535
.padding(8)
524536
.padding(.leading, 6)
@@ -545,24 +557,24 @@ struct TaskRow: View {
545557
.help(task.title)
546558
}
547559

548-
private func assignButton(_ action: @escaping () -> Void) -> some View {
560+
private func actionButton(_ icon: String, _ title: String, busy: String?, help: String, _ action: @escaping () -> Void) -> some View {
549561
Button { onSeen(); action() } label: {
550562
HStack(spacing: 3) {
551-
if assigning {
563+
if busy != nil {
552564
ProgressView().controlSize(.mini).scaleEffect(0.7).frame(width: 10, height: 10)
553565
} else {
554-
Image(systemName: "person.crop.circle.badge.plus").font(.system(size: 10))
566+
Image(systemName: icon).font(.system(size: 10))
555567
}
556-
Text(assigning ? "Assigning…" : "Assign me").font(.system(size: 10, weight: .semibold))
568+
Text(busy ?? title).font(.system(size: 10, weight: .semibold))
557569
}
558570
.padding(.horizontal, 7)
559571
.padding(.vertical, 2)
560572
.foregroundStyle(.white)
561-
.background(Capsule().fill(Color.accentColor.opacity(assigning ? 0.5 : 0.9)))
573+
.background(Capsule().fill(Color.accentColor.opacity(busy != nil ? 0.5 : 0.9)))
562574
}
563575
.buttonStyle(.plain)
564-
.disabled(assigning)
565-
.help("Add yourself as the reviewer (second assignee) of this task")
576+
.disabled(busy != nil)
577+
.help(help)
566578
}
567579

568580
private var reviewingLine: some View {

‎Sources/GitHubFloat/main.swift‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,11 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate, NSWind
248248
menu.addItem(ActionMenuItem("Assign Me as Reviewer") { store.acknowledge(key); store.assignMe(task) })
249249
menu.addItem(.separator())
250250
}
251+
if hit.tab == .mine, !store.reReviewPRs(task).isEmpty, !store.rerequesting.contains(task.id) {
252+
let who = Set(store.reReviewPRs(task).flatMap(\.changesRequestedBy)).sorted().joined(separator: ", ")
253+
menu.addItem(ActionMenuItem("Re-request Review from \(who)") { store.acknowledge(key); store.requestReReview(task) })
254+
menu.addItem(.separator())
255+
}
251256
if let url = task.url {
252257
menu.addItem(ActionMenuItem("Open \(task.kind == "PullRequest" ? "Pull Request" : "Issue")") { open(url) })
253258
}

‎docs/collapsed.png‎

-98.2 KB
Loading

‎docs/mine.png‎

-839 KB
Loading

‎docs/needs-reviewer.png‎

-641 KB
Loading

‎docs/reviewing.png‎

-685 KB
Loading

0 commit comments

Comments
 (0)