From 29aaa5187d11c96a17c7d6fbd812a7c7a7e98397 Mon Sep 17 00:00:00 2001 From: LuanAdemi Date: Sun, 8 Sep 2019 19:52:40 +0200 Subject: [PATCH] Integrated GitHub Actions support (kinda) --- Classes/Bookmark/BookmarkCloudMigrator.swift | 2 +- .../Notifications/NewFeaturesController.swift | 3 +-- .../Notification+NotificationViewModel.swift | 23 +++++++++++------- Classes/Notifications/NotificationCell.swift | 7 +++--- .../NotificationModelController.swift | 2 ++ .../NotificationSectionController.swift | 10 ++++++-- .../Notifications/NotificationType+Icon.swift | 1 + Classes/Notifications/NotificationType.swift | 2 ++ .../NotificationsViewController.swift | 3 +-- Freetime.xcodeproj/project.pbxproj | 14 ++++------- .../RepoInboxRowController.swift | 1 + FreetimeWatch/FreetimeWatch.entitlements | 7 +----- .../GitHubAPI/GitHubAPI/V3DataResponse.swift | 1 - .../GitHubAPI/GitHubAPI/V3Notification.swift | 1 + .../GitHubAPI/V3NotificationSubject.swift | 1 + .../actions.imageset/Contents.json | 22 +++++++++++++++++ .../actions.imageset/actions@2x.png | Bin 0 -> 815 bytes .../actions.imageset/actions@3x.png | Bin 0 -> 1231 bytes Resources/Freetime.entitlements | 4 --- 19 files changed, 65 insertions(+), 39 deletions(-) create mode 100644 Resources/Assets.xcassets/actions.imageset/Contents.json create mode 100644 Resources/Assets.xcassets/actions.imageset/actions@2x.png create mode 100644 Resources/Assets.xcassets/actions.imageset/actions@3x.png diff --git a/Classes/Bookmark/BookmarkCloudMigrator.swift b/Classes/Bookmark/BookmarkCloudMigrator.swift index e9bcfeb28..cc12a49ea 100644 --- a/Classes/Bookmark/BookmarkCloudMigrator.swift +++ b/Classes/Bookmark/BookmarkCloudMigrator.swift @@ -45,7 +45,7 @@ final class BookmarkCloudMigrator { init(username: String, oldBookmarks: [Bookmark], client: BookmarkCloudMigratorClient) { self.bookmarks = oldBookmarks.compactMap { switch $0.type { - case .commit, .release, .securityVulnerability: return nil + case .commit, .release, .securityVulnerability, .ci_activity: return nil case .issue, .pullRequest: return .issueOrPullRequest(owner: $0.owner, name: $0.name, number: $0.number) case .repo: diff --git a/Classes/Notifications/NewFeaturesController.swift b/Classes/Notifications/NewFeaturesController.swift index b328cdf51..edc898b59 100644 --- a/Classes/Notifications/NewFeaturesController.swift +++ b/Classes/Notifications/NewFeaturesController.swift @@ -59,13 +59,12 @@ final class NewFeaturesController { } } } - + // fetches for the latest changes func fetch(success: @escaping () -> Void) { guard let url = fetchURL, (testing == true || hasFetchedLatest == false) else { return } hasFetchedLatest = true - let task = session.dataTask(with: url) { (data, response, _) in if let response = response as? HTTPURLResponse, response.statusCode == 200, diff --git a/Classes/Notifications/Notification+NotificationViewModel.swift b/Classes/Notifications/Notification+NotificationViewModel.swift index fd02e3b40..8482bf92c 100644 --- a/Classes/Notifications/Notification+NotificationViewModel.swift +++ b/Classes/Notifications/Notification+NotificationViewModel.swift @@ -19,17 +19,21 @@ func CreateNotificationViewModels( var models = [NotificationViewModel]() for notification in v3notifications { - guard let type = NotificationType(rawValue: notification.subject.type.rawValue), - let identifier = notification.subject.identifier + guard let type = NotificationType(rawValue: notification.subject.type.rawValue) else { continue } - let number: NotificationViewModel.Number - switch identifier { - case .hash(let h): number = .hash(h) - case .number(let n): number = .number(n) - case .release(let r): number = .release(r) + + if notification.subject.identifier != nil { + guard let identifier = notification.subject.identifier + else {continue} + switch identifier { + case .hash(let h): number = .hash(h) + case .number(let n): number = .number(n) + case .release(let r): number = .release(r) + } + } else { + number = .number(1) } - models.append(NotificationViewModel( v3id: notification.id, repo: notification.repository.name, @@ -47,8 +51,9 @@ func CreateNotificationViewModels( branch: "master", issuesEnabled: true )) + } - + DispatchQueue.main.async { completion(models) } diff --git a/Classes/Notifications/NotificationCell.swift b/Classes/Notifications/NotificationCell.swift index 50447c90c..a3a42a326 100644 --- a/Classes/Notifications/NotificationCell.swift +++ b/Classes/Notifications/NotificationCell.swift @@ -171,7 +171,7 @@ final class NotificationCell: SelectableCell, CAAnimationDelegate { titleAttributes[.font] = Styles.Text.secondary.preferredFont switch model.number { case .number(let number): - guard model.type != .securityVulnerability else { break } + guard model.type != .securityVulnerability || model.type != .ci_activity else { break } title.append(NSAttributedString(string: "#\(number)", attributes: titleAttributes)) default: break } @@ -184,10 +184,11 @@ final class NotificationCell: SelectableCell, CAAnimationDelegate { case .open: tintColor = Styles.Colors.Green.medium.color case .pending: tintColor = Styles.Colors.Blue.medium.color } - iconImageView.tintColor = tintColor + + iconImageView.tintColor = tintColor + iconImageView.image = model.type.icon(merged: model.state == .merged)? .withRenderingMode(.alwaysTemplate) - let hasComments = model.comments > 0 commentButton.alpha = hasComments ? 1 : 0.3 commentButton.setTitle(hasComments ? model.comments.abbreviated : "", for: .normal) diff --git a/Classes/Notifications/NotificationModelController.swift b/Classes/Notifications/NotificationModelController.swift index 9a962eb9a..1b1481265 100644 --- a/Classes/Notifications/NotificationModelController.swift +++ b/Classes/Notifications/NotificationModelController.swift @@ -94,6 +94,7 @@ final class NotificationModelController { } } else { githubClient.client.send(V3NotificationRequest(all: all, page: page)) { [weak self] result in + switch result { case .success(let response): self?.handle( @@ -244,6 +245,7 @@ final class NotificationModelController { case .created: mapped = .created } + // Seems important githubClient.client.send(V3IssuesRequest(filter: mapped, page: page), completion: { result in // iterate result data, convert to InboxDashboardModel switch result { diff --git a/Classes/Notifications/NotificationSectionController.swift b/Classes/Notifications/NotificationSectionController.swift index f49914139..e1c10f431 100644 --- a/Classes/Notifications/NotificationSectionController.swift +++ b/Classes/Notifications/NotificationSectionController.swift @@ -75,13 +75,18 @@ final class NotificationSectionController: ListSwiftSectionController - - com.apple.security.application-groups - - group.com.whoisryannystrom.freetime - - + diff --git a/Local Pods/GitHubAPI/GitHubAPI/V3DataResponse.swift b/Local Pods/GitHubAPI/GitHubAPI/V3DataResponse.swift index 672f86c4b..05027ae9f 100644 --- a/Local Pods/GitHubAPI/GitHubAPI/V3DataResponse.swift +++ b/Local Pods/GitHubAPI/GitHubAPI/V3DataResponse.swift @@ -21,7 +21,6 @@ public struct V3DataResponse: EntityResponse { // https://developer.github.com/v3/#schema decoder.dateDecodingStrategy = .iso8601 - self.data = try decoder.decode(T.self, from: input) self.next = (response?.allHeaderFields["Link"] as? String)?.httpNextPageNumber } diff --git a/Local Pods/GitHubAPI/GitHubAPI/V3Notification.swift b/Local Pods/GitHubAPI/GitHubAPI/V3Notification.swift index 4e2f5a96b..fd567830e 100644 --- a/Local Pods/GitHubAPI/GitHubAPI/V3Notification.swift +++ b/Local Pods/GitHubAPI/GitHubAPI/V3Notification.swift @@ -22,6 +22,7 @@ public struct V3Notification: Codable { case teamMention = "team_mention" case reviewRequested = "review_requested" case securityAlert = "security_alert" + case ci_activity = "ci_activity" } public let id: String diff --git a/Local Pods/GitHubAPI/GitHubAPI/V3NotificationSubject.swift b/Local Pods/GitHubAPI/GitHubAPI/V3NotificationSubject.swift index 494902488..284d56dce 100644 --- a/Local Pods/GitHubAPI/GitHubAPI/V3NotificationSubject.swift +++ b/Local Pods/GitHubAPI/GitHubAPI/V3NotificationSubject.swift @@ -18,6 +18,7 @@ public struct V3NotificationSubject: Codable { case release = "Release" case invitation = "RepositoryInvitation" case vulnerabilityAlert = "RepositoryVulnerabilityAlert" + case ci_activity = "CheckSuite" } public let title: String diff --git a/Resources/Assets.xcassets/actions.imageset/Contents.json b/Resources/Assets.xcassets/actions.imageset/Contents.json new file mode 100644 index 000000000..ca796ce21 --- /dev/null +++ b/Resources/Assets.xcassets/actions.imageset/Contents.json @@ -0,0 +1,22 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "filename" : "actions@2x.png", + "scale" : "2x" + }, + { + "idiom" : "universal", + "filename" : "actions@3x.png", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Resources/Assets.xcassets/actions.imageset/actions@2x.png b/Resources/Assets.xcassets/actions.imageset/actions@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..7bed2571379b0833b04ce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A!b_~e5$YOhmgnl~u8Q@@ z*`08~bq!$CIXKUzNE9E}rqI~Y^J4@+R3tAii7R@RA1O5whf^tzl`>+a4 zGQbiK3hnO|5J51wF!s_y=mNDdOEa-y5U{Y;40^5q zxBNA3Syf1}d$2#oaG$8A zLFWk;FbVX|a!HiJip(jeyQv6U_G~q$JIkHjlGhIl?C5SXFg2X+taWPD4tj<&f5H{i zcnDNE8I<1=(4x@=a}LG+{{f%=O>N#W@Hxag}$Z7 zR8ReTW6I7kH5b~e`o9QEc84}GhI;C|6V{v>LxZ6_s^88qoZP}tW^%5hKGkn8%s8EM zlcBt+&mbtN63SGLb<|%_EU1=aqkTO+22H6^?Aij07F3;C$)NAInZtSYkpy}fZeb2h zU+O`= com.apple.developer.ubiquity-kvstore-identifier $(TeamIdentifierPrefix)$(CFBundleIdentifier) - com.apple.security.application-groups - - group.com.whoisryannystrom.freetime -