Skip to content

Commit

Permalink
show number of PR if only one type selected
Browse files Browse the repository at this point in the history
  • Loading branch information
streetturtle committed Aug 5, 2022
1 parent d252d2d commit 5aa2699
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
24 changes: 20 additions & 4 deletions pullBar/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
icon?.isTemplate = true
icon?.size = size
statusButton.image = icon
statusButton.imagePosition = NSControl.ImagePosition.imageLeft

statusBarItem.menu = menu

Expand Down Expand Up @@ -81,6 +82,7 @@ extension AppDelegate {
func refreshMenu() {
NSLog("Refreshing menu")
self.menu.removeAllItems()
self.statusBarItem.button?.title = ""

if (githubUsername == "" || githubToken == "") {
addMenuFooterItems()
Expand Down Expand Up @@ -121,33 +123,47 @@ extension AppDelegate {

group.notify(queue: .main) {

let isOneSelected = (self.showAssigned.intValue + self.showCreated.intValue + self.showRequested.intValue) == 1


if let assignedPulls = assignedPulls, let createdPulls = createdPulls, let reviewRequestedPulls = reviewRequestedPulls {

if self.showAssigned && !assignedPulls.isEmpty {
self.menu.addItem(NSMenuItem(title: "Assigned", action: nil, keyEquivalent: ""))
self.menu.addItem(NSMenuItem(title: "Assigned (\(assignedPulls.count))", action: nil, keyEquivalent: ""))
for pull in assignedPulls {
self.menu.addItem(self.createMenuItem(pull: pull))
}
self.menu.addItem(.separator())
if isOneSelected {
self.statusBarItem.button?.title = String(assignedPulls.count)
}
}

if self.showCreated && !createdPulls.isEmpty {
self.menu.addItem(NSMenuItem(title: "Created", action: nil, keyEquivalent: ""))
self.menu.addItem(NSMenuItem(title: "Created (\(createdPulls.count))", action: nil, keyEquivalent: ""))
for pull in createdPulls {
self.menu.addItem(self.createMenuItem(pull: pull))
}
self.menu.addItem(.separator())
if isOneSelected {
self.statusBarItem.button?.title = String(createdPulls.count)
}

}

if self.showRequested && !reviewRequestedPulls.isEmpty {
self.menu.addItem(NSMenuItem(title: "Review Requested", action: nil, keyEquivalent: ""))
self.menu.addItem(NSMenuItem(title: "Review Requested (\(reviewRequestedPulls.count))", action: nil, keyEquivalent: ""))
for pull in reviewRequestedPulls {
self.menu.addItem(self.createMenuItem(pull: pull))
}
self.menu.addItem(.separator())
if isOneSelected {
self.statusBarItem.button?.title = String(reviewRequestedPulls.count)
}

}


self.addMenuFooterItems()
}
}
Expand Down
6 changes: 6 additions & 0 deletions pullBar/Extensions/StringExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ extension String {
return (self.count > length) ? self.prefix(length) + trailing : self
}
}

extension Bool {
var intValue: Int {
return self ? 1 : 0
}
}

0 comments on commit 5aa2699

Please sign in to comment.