Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix latestUrl #47

Merged
merged 1 commit into from
Dec 1, 2024
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
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ clean:
schema:
curl -sSfLo Pulse/Github/schema.graphqls https://docs.github.com/public/fpt/schema.docs.graphql

.PHONY: clean-generated
clean-generated:
rm -rf Pulse/Github/{Github.graphql.swift,Operations,Schema}

.PHONY: generate
generate:
generate: clean-generated
./apollo-ios-cli generate
7 changes: 0 additions & 7 deletions Pulse/ContentListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,6 @@ struct ContentListView: View {
.foregroundColor(.primary)
}
}
if let author = pull.commentAuthor {
HStack(spacing: 0) {
Image(systemName: "bubble")
Text("@\(author)")
.font(.footnote)
}
}
}
}
}
Expand Down
27 changes: 19 additions & 8 deletions Pulse/GitHubAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
let repo: String
let title: String
let url: String
let latestUrl: String
let mergeable: Github.MergeableState // NOTE: It might use
let commitUrl: String
let commentAuthor: String?
let commentUrl: String?
let draft: Bool
let approvedCount: Int
let reviewResult: ReviewResult
Expand All @@ -31,10 +30,6 @@
(reviewResult == .pending && checkResult == .success)
}

var latestUrl: String {
commentUrl ?? url
}

enum ReviewResult {
case success
case failure
Expand Down Expand Up @@ -71,7 +66,7 @@
client = ApolloClient(networkTransport: transport, store: store)
}

func fetch(_ githubQuery: String) async throws -> PullRequests {

Check warning on line 69 in Pulse/GitHubAPI.swift

View workflow job for this annotation

GitHub Actions / Lint

Cyclomatic Complexity Violation: Function should have complexity 10 or less; currently complexity is 13 (cyclomatic_complexity)
return try await withCheckedThrowingContinuation { continuation in
let query = Github.SearchPullRequestsQuery(query: githubQuery)

Expand Down Expand Up @@ -111,15 +106,31 @@

let updatedAt = ISO8601DateFormatter().date(from: asPull.updatedAt) ?? Date(timeIntervalSince1970: 0)

let comment = asPull.comments.edges?.first??.node
let review = asPull.reviews?.edges?.first??.node

let latestUrl = if let comment, let review {
if comment.createdAt > review.createdAt {
comment.url
} else {
review.url
}
} else if let comment {
commit.url
} else if let review {
review.url
} else {
asPull.url
}

let pull = PullRequest(
owner: asPull.repository.owner.login,
repo: asPull.repository.name,
title: asPull.title,
url: asPull.url,
latestUrl: latestUrl,
mergeable: asPull.mergeable.value ?? Github.MergeableState.unknown,
commitUrl: commit.url,
commentAuthor: asPull.comments.nodes?.first??.author?.login,
commentUrl: asPull.comments.nodes?.first??.url,
draft: asPull.isDraft,
approvedCount: asPull.approvedReviews?.totalCount ?? 0,
reviewResult: reviewResult,
Expand All @@ -136,7 +147,7 @@
if let err = err as? Apollo.ResponseCodeInterceptor.ResponseCodeError,
case .invalidResponseCode(let respOrNil, _) = err,
let resp = respOrNil
{

Check warning on line 150 in Pulse/GitHubAPI.swift

View workflow job for this annotation

GitHub Actions / Lint

Opening Brace Spacing Violation: Opening braces should be preceded by a single space and on the same line as the declaration (opening_brace)
continuation.resume(throwing: GitHubError.respNotOK(resp))
} else {
continuation.resume(throwing: err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extension Github {
static let operationName: String = "SearchPullRequests"
static let operationDocument: ApolloAPI.OperationDocument = .init(
definition: .init(
#"query SearchPullRequests($query: String!) { search(type: ISSUE, last: 100, query: $query) { __typename nodes { __typename ... on PullRequest { repository { __typename name owner { __typename login } } title url reviewDecision mergeable isDraft updatedAt comments(last: 1) { __typename nodes { __typename author { __typename login } url } } commits(last: 1) { __typename nodes { __typename commit { __typename url statusCheckRollup { __typename state } } } } approvedReviews: reviews(states: APPROVED) { __typename totalCount } } } } }"#
#"query SearchPullRequests($query: String!) { search(type: ISSUE, last: 100, query: $query) { __typename nodes { __typename ... on PullRequest { repository { __typename name owner { __typename login } } title url reviewDecision mergeable isDraft updatedAt comments(last: 1) { __typename edges { __typename node { __typename url createdAt } } } reviews(last: 1) { __typename edges { __typename node { __typename url createdAt } } } commits(last: 1) { __typename nodes { __typename commit { __typename url statusCheckRollup { __typename state } } } } approvedReviews: reviews(states: APPROVED) { __typename totalCount } } } } }"#
))

public var query: String
Expand Down Expand Up @@ -84,6 +84,7 @@ extension Github {
.field("isDraft", Bool.self),
.field("updatedAt", Github.DateTime.self),
.field("comments", Comments.self, arguments: ["last": 1]),
.field("reviews", Reviews?.self, arguments: ["last": 1]),
.field("commits", Commits.self, arguments: ["last": 1]),
.field("reviews", alias: "approvedReviews", ApprovedReviews?.self, arguments: ["states": "APPROVED"]),
] }
Expand All @@ -104,6 +105,8 @@ extension Github {
var updatedAt: Github.DateTime { __data["updatedAt"] }
/// A list of comments associated with the pull request.
var comments: Comments { __data["comments"] }
/// A list of reviews associated with the pull request.
var reviews: Reviews? { __data["reviews"] }
/// A list of commits present in this pull request's head branch not present in the base branch.
var commits: Commits { __data["commits"] }
/// A list of reviews associated with the pull request.
Expand Down Expand Up @@ -156,46 +159,100 @@ extension Github {
static var __parentType: any ApolloAPI.ParentType { Github.Objects.IssueCommentConnection }
static var __selections: [ApolloAPI.Selection] { [
.field("__typename", String.self),
.field("nodes", [Node?]?.self),
.field("edges", [Edge?]?.self),
] }

/// A list of nodes.
var nodes: [Node?]? { __data["nodes"] }
/// A list of edges.
var edges: [Edge?]? { __data["edges"] }

/// Search.Node.AsPullRequest.Comments.Node
/// Search.Node.AsPullRequest.Comments.Edge
///
/// Parent Type: `IssueComment`
struct Node: Github.SelectionSet {
/// Parent Type: `IssueCommentEdge`
struct Edge: Github.SelectionSet {
let __data: DataDict
init(_dataDict: DataDict) { __data = _dataDict }

static var __parentType: any ApolloAPI.ParentType { Github.Objects.IssueComment }
static var __parentType: any ApolloAPI.ParentType { Github.Objects.IssueCommentEdge }
static var __selections: [ApolloAPI.Selection] { [
.field("__typename", String.self),
.field("author", Author?.self),
.field("url", Github.URI.self),
.field("node", Node?.self),
] }

/// The actor who authored the comment.
var author: Author? { __data["author"] }
/// The HTTP URL for this issue comment
var url: Github.URI { __data["url"] }
/// The item at the end of the edge.
var node: Node? { __data["node"] }

/// Search.Node.AsPullRequest.Comments.Node.Author
/// Search.Node.AsPullRequest.Comments.Edge.Node
///
/// Parent Type: `Actor`
struct Author: Github.SelectionSet {
/// Parent Type: `IssueComment`
struct Node: Github.SelectionSet {
let __data: DataDict
init(_dataDict: DataDict) { __data = _dataDict }

static var __parentType: any ApolloAPI.ParentType { Github.Interfaces.Actor }
static var __parentType: any ApolloAPI.ParentType { Github.Objects.IssueComment }
static var __selections: [ApolloAPI.Selection] { [
.field("__typename", String.self),
.field("login", String.self),
.field("url", Github.URI.self),
.field("createdAt", Github.DateTime.self),
] }

/// The username of the actor.
var login: String { __data["login"] }
/// The HTTP URL for this issue comment
var url: Github.URI { __data["url"] }
/// Identifies the date and time when the object was created.
var createdAt: Github.DateTime { __data["createdAt"] }
}
}
}

/// Search.Node.AsPullRequest.Reviews
///
/// Parent Type: `PullRequestReviewConnection`
struct Reviews: Github.SelectionSet {
let __data: DataDict
init(_dataDict: DataDict) { __data = _dataDict }

static var __parentType: any ApolloAPI.ParentType { Github.Objects.PullRequestReviewConnection }
static var __selections: [ApolloAPI.Selection] { [
.field("__typename", String.self),
.field("edges", [Edge?]?.self),
] }

/// A list of edges.
var edges: [Edge?]? { __data["edges"] }

/// Search.Node.AsPullRequest.Reviews.Edge
///
/// Parent Type: `PullRequestReviewEdge`
struct Edge: Github.SelectionSet {
let __data: DataDict
init(_dataDict: DataDict) { __data = _dataDict }

static var __parentType: any ApolloAPI.ParentType { Github.Objects.PullRequestReviewEdge }
static var __selections: [ApolloAPI.Selection] { [
.field("__typename", String.self),
.field("node", Node?.self),
] }

/// The item at the end of the edge.
var node: Node? { __data["node"] }

/// Search.Node.AsPullRequest.Reviews.Edge.Node
///
/// Parent Type: `PullRequestReview`
struct Node: Github.SelectionSet {
let __data: DataDict
init(_dataDict: DataDict) { __data = _dataDict }

static var __parentType: any ApolloAPI.ParentType { Github.Objects.PullRequestReview }
static var __selections: [ApolloAPI.Selection] { [
.field("__typename", String.self),
.field("url", Github.URI.self),
.field("createdAt", Github.DateTime.self),
] }

/// The HTTP URL permalink for this PullRequestReview.
var url: Github.URI { __data["url"] }
/// Identifies the date and time when the object was created.
var createdAt: Github.DateTime { __data["createdAt"] }
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions Pulse/Github/Schema/Objects/IssueCommentEdge.graphql.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// @generated
// This file was automatically generated and should not be edited.

import ApolloAPI

extension Github.Objects {
/// An edge in a connection.
static let IssueCommentEdge = ApolloAPI.Object(
typename: "IssueCommentEdge",
implementedInterfaces: []
)
}
12 changes: 12 additions & 0 deletions Pulse/Github/Schema/Objects/PullRequestReviewEdge.graphql.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// @generated
// This file was automatically generated and should not be edited.

import ApolloAPI

extension Github.Objects {
/// An edge in a connection.
static let PullRequestReviewEdge = ApolloAPI.Object(
typename: "PullRequestReviewEdge",
implementedInterfaces: []
)
}
2 changes: 2 additions & 0 deletions Pulse/Github/Schema/SchemaMetadata.graphql.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ extension Github {
case "Issue": return Github.Objects.Issue
case "IssueComment": return Github.Objects.IssueComment
case "IssueCommentConnection": return Github.Objects.IssueCommentConnection
case "IssueCommentEdge": return Github.Objects.IssueCommentEdge
case "Label": return Github.Objects.Label
case "LabeledEvent": return Github.Objects.LabeledEvent
case "Language": return Github.Objects.Language
Expand Down Expand Up @@ -192,6 +193,7 @@ extension Github {
case "PullRequestReview": return Github.Objects.PullRequestReview
case "PullRequestReviewComment": return Github.Objects.PullRequestReviewComment
case "PullRequestReviewConnection": return Github.Objects.PullRequestReviewConnection
case "PullRequestReviewEdge": return Github.Objects.PullRequestReviewEdge
case "PullRequestReviewThread": return Github.Objects.PullRequestReviewThread
case "PullRequestThread": return Github.Objects.PullRequestThread
case "Push": return Github.Objects.Push
Expand Down
16 changes: 12 additions & 4 deletions Pulse/Github/SearchPullRequests.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,19 @@ query SearchPullRequests($query: String!) {
isDraft
updatedAt
comments(last: 1) {
nodes {
author {
login
edges {
node {
url
createdAt
}
}
}
reviews(last: 1) {
edges {
node {
url
createdAt
}
url
}
}
commits(last: 1) {
Expand Down
Loading