Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit 20ba8ac

Browse files
authored
Show PR CI status inline with title (#2325)
* remove unused gql * show PR CI status in list * update StyledTextKit
1 parent 80d1255 commit 20ba8ac

12 files changed

+335
-1124
lines changed

Classes/Repository/GQL+RepositoryIssueSummaryType.swift

Lines changed: 11 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,53 +8,6 @@
88

99
import Foundation
1010

11-
extension RepoIssuePagesQuery.Data.Repository.Issue.Node: RepositoryIssueSummaryType {
12-
13-
var labelableFields: LabelableFields {
14-
return fragments.labelableFields
15-
}
16-
17-
var repoEventFields: RepoEventFields {
18-
return fragments.repoEventFields
19-
}
20-
21-
var pullRequest: Bool {
22-
return false
23-
}
24-
25-
var status: IssueStatus {
26-
switch state {
27-
case .closed: return .closed
28-
case .open, .__unknown: return .open
29-
}
30-
}
31-
32-
}
33-
34-
extension RepoPullRequestPagesQuery.Data.Repository.PullRequest.Node: RepositoryIssueSummaryType {
35-
36-
var labelableFields: LabelableFields {
37-
return fragments.labelableFields
38-
}
39-
40-
var repoEventFields: RepoEventFields {
41-
return fragments.repoEventFields
42-
}
43-
44-
var pullRequest: Bool {
45-
return true
46-
}
47-
48-
var status: IssueStatus {
49-
switch state {
50-
case .closed: return .closed
51-
case .merged: return .merged
52-
case .open, .__unknown: return .open
53-
}
54-
}
55-
56-
}
57-
5811
extension RepoSearchPagesQuery.Data.Search.Node.AsIssue: RepositoryIssueSummaryType {
5912

6013
var labelableFields: LabelableFields {
@@ -76,6 +29,10 @@ extension RepoSearchPagesQuery.Data.Search.Node.AsIssue: RepositoryIssueSummaryT
7629
}
7730
}
7831

32+
var ciStatus: RepositoryIssueCIStatus? {
33+
return nil
34+
}
35+
7936
}
8037

8138
extension RepoSearchPagesQuery.Data.Search.Node.AsPullRequest: RepositoryIssueSummaryType {
@@ -100,4 +57,11 @@ extension RepoSearchPagesQuery.Data.Search.Node.AsPullRequest: RepositoryIssueSu
10057
}
10158
}
10259

60+
var ciStatus: RepositoryIssueCIStatus? {
61+
guard let node = commits.nodes?.first,
62+
let status = node?.commit.status
63+
else { return nil }
64+
return RepositoryIssueCIStatus(rawValue: status.state.rawValue)
65+
}
66+
10367
}

Classes/Repository/RepositoryClient.swift

Lines changed: 35 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -17,36 +17,6 @@ protocol RepositoryQuery {
1717
func nextPageToken(from data: GraphQLSelectionSet) -> String?
1818
}
1919

20-
extension RepoIssuePagesQuery: RepositoryQuery {
21-
22-
func summaryTypes(from data: GraphQLSelectionSet) -> [RepositoryIssueSummaryType] {
23-
guard let issues = data as? Data else { return [] }
24-
return issues.repository?.issues.nodes?.compactMap { $0 } ?? []
25-
}
26-
27-
func nextPageToken(from data: GraphQLSelectionSet) -> String? {
28-
guard let issues = data as? Data else { return nil }
29-
guard let pageInfo = issues.repository?.issues.pageInfo, pageInfo.hasNextPage else { return nil }
30-
return pageInfo.endCursor
31-
}
32-
33-
}
34-
35-
extension RepoPullRequestPagesQuery: RepositoryQuery {
36-
37-
func summaryTypes(from data: GraphQLSelectionSet) -> [RepositoryIssueSummaryType] {
38-
guard let prs = data as? RepoPullRequestPagesQuery.Data else { return [] }
39-
return prs.repository?.pullRequests.nodes?.compactMap { $0 } ?? []
40-
}
41-
42-
func nextPageToken(from data: GraphQLSelectionSet) -> String? {
43-
guard let prs = data as? RepoPullRequestPagesQuery.Data else { return nil }
44-
guard let pageInfo = prs.repository?.pullRequests.pageInfo, pageInfo.hasNextPage else { return nil }
45-
return pageInfo.endCursor
46-
}
47-
48-
}
49-
5020
extension RepoSearchPagesQuery: RepositoryQuery {
5121

5222
func summaryTypes(from data: GraphQLSelectionSet) -> [RepositoryIssueSummaryType] {
@@ -69,12 +39,34 @@ func createSummaryModel(
6939
) -> RepositoryIssueSummaryModel? {
7040
guard let date = node.repoEventFields.createdAt.githubDate else { return nil }
7141

72-
let title = StyledTextBuilder(styledText: StyledText(
42+
let builder = StyledTextBuilder(styledText: StyledText(
7343
text: node.title,
74-
style: Styles.Text.body.with(foreground: Styles.Colors.Gray.dark.color)
75-
)).build()
44+
// style: Styles.Text.body.with(foreground: Styles.Colors.Gray.medium.color)
45+
style: Styles.Text.body
46+
))
47+
if let ciStatus = node.ciStatus {
48+
let iconName: String
49+
let color: UIColor
50+
switch ciStatus {
51+
case .pending:
52+
iconName = "primitive-dot"
53+
color = Styles.Colors.Yellow.medium.color
54+
case .failure:
55+
iconName = "x-small"
56+
color = Styles.Colors.Red.medium.color
57+
case .success:
58+
iconName = "check-small"
59+
color = Styles.Colors.Green.medium.color
60+
}
61+
if let icon = UIImage(named: iconName)?.withRenderingMode(.alwaysTemplate) {
62+
builder.save()
63+
.add(text: "\u{00A0}")
64+
.add(image: icon, attributes: [.foregroundColor: color])
65+
.restore()
66+
}
67+
}
7668
let string = StyledTextRenderer(
77-
string: title,
69+
string: builder.build(),
7870
contentSizeCategory: contentSizeCategory,
7971
inset: RepositorySummaryCell.titleInset
8072
).warm(width: containerWidth)
@@ -87,7 +79,8 @@ func createSummaryModel(
8779
author: node.repoEventFields.author?.login ?? Constants.Strings.unknown,
8880
status: node.status,
8981
pullRequest: node.pullRequest,
90-
labels: node.labelableFields.issueLabelModels
82+
labels: node.labelableFields.issueLabelModels,
83+
ciStatus: node.ciStatus
9184
)
9285
}
9386

@@ -98,11 +91,13 @@ func createSummaryModel(
9891
containerWidth: CGFloat
9992
) -> (models: [RepositoryIssueSummaryModel], nextPage: String?) {
10093
let nextPage = query.nextPageToken(from: data)
101-
let models: [RepositoryIssueSummaryModel] = query.summaryTypes(from: data).compactMap { (node: RepositoryIssueSummaryType) in
102-
return createSummaryModel(node, contentSizeCategory: contentSizeCategory, containerWidth: containerWidth)
103-
}.sorted(by: {
104-
$0.created > $1.created
105-
})
94+
let models = query.summaryTypes(from: data).compactMap { node in
95+
return createSummaryModel(
96+
node,
97+
contentSizeCategory: contentSizeCategory,
98+
containerWidth: containerWidth
99+
)
100+
}.sorted {$0.created > $1.created }
106101
return (models, nextPage)
107102
}
108103

@@ -155,30 +150,6 @@ final class RepositoryClient {
155150
})
156151
}
157152

158-
func loadIssues(
159-
nextPage: String? = nil,
160-
containerWidth: CGFloat,
161-
completion: @escaping (Result<RepositoryPayload>) -> Void
162-
) {
163-
loadPage(
164-
query: RepoIssuePagesQuery(owner: owner, name: name, after: nextPage, page_size: 30),
165-
containerWidth: containerWidth,
166-
completion: completion
167-
)
168-
}
169-
170-
func loadPullRequests(
171-
nextPage: String? = nil,
172-
containerWidth: CGFloat,
173-
completion: @escaping (Result<RepositoryPayload>) -> Void
174-
) {
175-
loadPage(
176-
query: RepoPullRequestPagesQuery(owner: owner, name: name, after: nextPage, page_size: 30),
177-
containerWidth: containerWidth,
178-
completion: completion
179-
)
180-
}
181-
182153
func searchIssues(
183154
query: String,
184155
nextPage: String? = nil,

Classes/Repository/RepositoryIssueSummaryModel.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class RepositoryIssueSummaryModel: ListDiffable {
2020
let status: IssueStatus
2121
let pullRequest: Bool
2222
let labels: [RepositoryLabel]
23+
let ciStatus: RepositoryIssueCIStatus?
2324

2425
// quicker comparison for diffing rather than scanning the labels array
2526
let labelSummary: String
@@ -32,7 +33,8 @@ class RepositoryIssueSummaryModel: ListDiffable {
3233
author: String,
3334
status: IssueStatus,
3435
pullRequest: Bool,
35-
labels: [RepositoryLabel]
36+
labels: [RepositoryLabel],
37+
ciStatus: RepositoryIssueCIStatus?
3638
) {
3739
self.id = id
3840
self.title = title
@@ -43,6 +45,7 @@ class RepositoryIssueSummaryModel: ListDiffable {
4345
self.pullRequest = pullRequest
4446
self.labels = labels
4547
self.labelSummary = labels.reduce("", { $0 + $1.name })
48+
self.ciStatus = ciStatus
4649
}
4750

4851
// MARK: ListDiffable
@@ -62,5 +65,6 @@ class RepositoryIssueSummaryModel: ListDiffable {
6265
&& created == object.created
6366
&& title.string == object.title.string
6467
&& labelSummary == object.labelSummary
68+
&& ciStatus == object.ciStatus
6569
}
6670
}

Classes/Repository/RepositoryIssueSummaryType.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88

99
import IGListKit
1010

11+
enum RepositoryIssueCIStatus: String {
12+
case pending = "PENDING"
13+
case failure = "FAILURE"
14+
case success = "SUCCESS"
15+
}
16+
1117
protocol RepositoryIssueSummaryType {
1218

1319
var number: Int { get }
@@ -17,5 +23,6 @@ protocol RepositoryIssueSummaryType {
1723
var labelableFields: LabelableFields { get }
1824
var pullRequest: Bool { get }
1925
var title: String { get }
26+
var ciStatus: RepositoryIssueCIStatus? { get }
2027

2128
}

Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ CHECKOUT OPTIONS:
169169
:commit: 88d671bbe86e3c18d54e094fac97df12a3054d53
170170
:git: https://github.com/GitHawkApp/Squawk.git
171171
StyledTextKit:
172-
:commit: d15f77a32203daafd71e14e6f5911528e932aca5
172+
:commit: 8583c80e742f886e541c5ec500b7be6f5e7a233f
173173
:git: https://github.com/GitHawkApp/StyledTextKit.git
174174

175175
SPEC CHECKSUMS:

Pods/Manifest.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pods/StyledTextKit/Source/StyledText.swift

Lines changed: 57 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)