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

Commit 1d09284

Browse files
Conditonally loading CheckSuites for only github.com
1 parent 3a82548 commit 1d09284

File tree

3 files changed

+154
-81
lines changed

3 files changed

+154
-81
lines changed

src/GitHub.App/Services/PullRequestService.cs

Lines changed: 100 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -83,59 +83,108 @@ public async Task<Page<PullRequestListItemModel>> ReadPullRequests(
8383
{
8484
if (readPullRequests == null)
8585
{
86-
readPullRequests = new Query()
87-
.Repository(Var(nameof(owner)), Var(nameof(name)))
88-
.PullRequests(
89-
first: 100,
90-
after: Var(nameof(after)),
91-
orderBy: new IssueOrder { Direction = OrderDirection.Desc, Field = IssueOrderField.CreatedAt },
92-
states: Var(nameof(states)))
93-
.Select(page => new Page<PullRequestListItemModel>
94-
{
95-
EndCursor = page.PageInfo.EndCursor,
96-
HasNextPage = page.PageInfo.HasNextPage,
97-
TotalCount = page.TotalCount,
98-
Items = page.Nodes.Select(pr => new ListItemAdapter
86+
if (address.IsGitHubDotCom())
87+
{
88+
readPullRequests = new Query()
89+
.Repository(Var(nameof(owner)), Var(nameof(name)))
90+
.PullRequests(
91+
first: 100,
92+
after: Var(nameof(after)),
93+
orderBy: new IssueOrder { Direction = OrderDirection.Desc, Field = IssueOrderField.CreatedAt },
94+
states: Var(nameof(states)))
95+
.Select(page => new Page<PullRequestListItemModel>
9996
{
100-
Id = pr.Id.Value,
101-
LastCommit = pr.Commits(null, null, 1, null).Nodes.Select(commit =>
102-
new LastCommitSummaryModel
103-
{
104-
CheckSuites = commit.Commit.CheckSuites(null, null, null, null, null).AllPages(10)
105-
.Select(suite => new CheckSuiteSummaryModel
106-
{
107-
CheckRuns = suite.CheckRuns(null, null, null, null, null).AllPages(10)
108-
.Select(run => new CheckRunSummaryModel
109-
{
110-
Conclusion = run.Conclusion.FromGraphQl(),
111-
Status = run.Status.FromGraphQl()
112-
}).ToList()
113-
}).ToList(),
114-
Statuses = commit.Commit.Status
115-
.Select(context =>
116-
context.Contexts.Select(statusContext => new StatusSummaryModel
117-
{
118-
State = statusContext.State.FromGraphQl(),
119-
}).ToList()
120-
).SingleOrDefault()
121-
}).ToList().FirstOrDefault(),
122-
Author = new ActorModel
97+
EndCursor = page.PageInfo.EndCursor,
98+
HasNextPage = page.PageInfo.HasNextPage,
99+
TotalCount = page.TotalCount,
100+
Items = page.Nodes.Select(pr => new ListItemAdapter
123101
{
124-
Login = pr.Author.Login,
125-
AvatarUrl = pr.Author.AvatarUrl(null),
126-
},
127-
CommentCount = pr.Comments(0, null, null, null).TotalCount,
128-
Number = pr.Number,
129-
Reviews = pr.Reviews(null, null, null, null, null, null).AllPages().Select(review => new ReviewAdapter
102+
Id = pr.Id.Value,
103+
LastCommit = pr.Commits(null, null, 1, null).Nodes.Select(commit =>
104+
new LastCommitSummaryAdapter
105+
{
106+
CheckSuites = commit.Commit.CheckSuites(null, null, null, null, null).AllPages(10)
107+
.Select(suite => new CheckSuiteSummaryModel
108+
{
109+
CheckRuns = suite.CheckRuns(null, null, null, null, null).AllPages(10)
110+
.Select(run => new CheckRunSummaryModel
111+
{
112+
Conclusion = run.Conclusion.FromGraphQl(),
113+
Status = run.Status.FromGraphQl()
114+
}).ToList()
115+
}).ToList(),
116+
Statuses = commit.Commit.Status
117+
.Select(context =>
118+
context.Contexts.Select(statusContext => new StatusSummaryModel
119+
{
120+
State = statusContext.State.FromGraphQl(),
121+
}).ToList()
122+
).SingleOrDefault()
123+
}).ToList().FirstOrDefault(),
124+
Author = new ActorModel
125+
{
126+
Login = pr.Author.Login,
127+
AvatarUrl = pr.Author.AvatarUrl(null),
128+
},
129+
CommentCount = pr.Comments(0, null, null, null).TotalCount,
130+
Number = pr.Number,
131+
Reviews = pr.Reviews(null, null, null, null, null, null).AllPages().Select(review => new ReviewAdapter
132+
{
133+
Body = review.Body,
134+
CommentCount = review.Comments(null, null, null, null).TotalCount,
135+
}).ToList(),
136+
State = pr.State.FromGraphQl(),
137+
Title = pr.Title,
138+
UpdatedAt = pr.UpdatedAt,
139+
}).ToList(),
140+
}).Compile();
141+
}
142+
else
143+
{
144+
readPullRequests = new Query()
145+
.Repository(Var(nameof(owner)), Var(nameof(name)))
146+
.PullRequests(
147+
first: 100,
148+
after: Var(nameof(after)),
149+
orderBy: new IssueOrder { Direction = OrderDirection.Desc, Field = IssueOrderField.CreatedAt },
150+
states: Var(nameof(states)))
151+
.Select(page => new Page<PullRequestListItemModel>
152+
{
153+
EndCursor = page.PageInfo.EndCursor,
154+
HasNextPage = page.PageInfo.HasNextPage,
155+
TotalCount = page.TotalCount,
156+
Items = page.Nodes.Select(pr => new ListItemAdapter
130157
{
131-
Body = review.Body,
132-
CommentCount = review.Comments(null, null, null, null).TotalCount,
158+
Id = pr.Id.Value,
159+
LastCommit = pr.Commits(null, null, 1, null).Nodes.Select(commit =>
160+
new LastCommitSummaryAdapter
161+
{
162+
Statuses = commit.Commit.Status
163+
.Select(context =>
164+
context.Contexts.Select(statusContext => new StatusSummaryModel
165+
{
166+
State = statusContext.State.FromGraphQl(),
167+
}).ToList()
168+
).SingleOrDefault()
169+
}).ToList().FirstOrDefault(),
170+
Author = new ActorModel
171+
{
172+
Login = pr.Author.Login,
173+
AvatarUrl = pr.Author.AvatarUrl(null),
174+
},
175+
CommentCount = pr.Comments(0, null, null, null).TotalCount,
176+
Number = pr.Number,
177+
Reviews = pr.Reviews(null, null, null, null, null, null).AllPages().Select(review => new ReviewAdapter
178+
{
179+
Body = review.Body,
180+
CommentCount = review.Comments(null, null, null, null).TotalCount,
181+
}).ToList(),
182+
State = pr.State.FromGraphQl(),
183+
Title = pr.Title,
184+
UpdatedAt = pr.UpdatedAt,
133185
}).ToList(),
134-
State = pr.State.FromGraphQl(),
135-
Title = pr.Title,
136-
UpdatedAt = pr.UpdatedAt,
137-
}).ToList(),
138-
}).Compile();
186+
}).Compile();
187+
}
139188
}
140189

141190
var graphql = await graphqlFactory.CreateConnection(address);
@@ -940,7 +989,7 @@ class ListItemAdapter : PullRequestListItemModel
940989
{
941990
public IList<ReviewAdapter> Reviews { get; set; }
942991

943-
public LastCommitSummaryModel LastCommit { get; set; }
992+
public LastCommitSummaryAdapter LastCommit { get; set; }
944993
}
945994

946995
class ReviewAdapter
@@ -950,7 +999,7 @@ class ReviewAdapter
950999
public int Count => CommentCount + (!string.IsNullOrWhiteSpace(Body) ? 1 : 0);
9511000
}
9521001

953-
class LastCommitSummaryModel
1002+
class LastCommitSummaryAdapter
9541003
{
9551004
public List<CheckSuiteSummaryModel> CheckSuites { get; set; }
9561005

src/GitHub.InlineReviews/Services/PullRequestSessionService.cs

Lines changed: 53 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -755,37 +755,61 @@ async Task<LastCommitAdapter> GetPullRequestLastCommitAdapter(HostAddress addres
755755
{
756756
if (readCommitStatuses == null)
757757
{
758-
readCommitStatuses = new Query()
759-
.Repository(Var(nameof(owner)), Var(nameof(name)))
760-
.PullRequest(Var(nameof(number))).Commits(last: 1).Nodes.Select(
761-
commit => new LastCommitAdapter
762-
{
763-
CheckSuites = commit.Commit.CheckSuites(null, null, null, null, null).AllPages(10)
764-
.Select(suite => new CheckSuiteModel
765-
{
766-
CheckRuns = suite.CheckRuns(null, null, null, null, null).AllPages(10)
767-
.Select(run => new CheckRunModel
758+
if(address.IsGitHubDotCom())
759+
{
760+
readCommitStatuses = new Query()
761+
.Repository(Var(nameof(owner)), Var(nameof(name)))
762+
.PullRequest(Var(nameof(number))).Commits(last: 1).Nodes.Select(
763+
commit => new LastCommitAdapter
764+
{
765+
CheckSuites = commit.Commit.CheckSuites(null, null, null, null, null).AllPages(10)
766+
.Select(suite => new CheckSuiteModel
767+
{
768+
CheckRuns = suite.CheckRuns(null, null, null, null, null).AllPages(10)
769+
.Select(run => new CheckRunModel
770+
{
771+
Conclusion = run.Conclusion.FromGraphQl(),
772+
Status = run.Status.FromGraphQl(),
773+
Name = run.Name,
774+
DetailsUrl = run.Permalink,
775+
Summary = run.Summary,
776+
}).ToList()
777+
}).ToList(),
778+
Statuses = commit.Commit.Status
779+
.Select(context =>
780+
context.Contexts.Select(statusContext => new StatusModel
768781
{
769-
Conclusion = run.Conclusion.FromGraphQl(),
770-
Status = run.Status.FromGraphQl(),
771-
Name = run.Name,
772-
DetailsUrl = run.Permalink,
773-
Summary = run.Summary,
782+
State = statusContext.State.FromGraphQl(),
783+
Context = statusContext.Context,
784+
TargetUrl = statusContext.TargetUrl,
785+
Description = statusContext.Description,
786+
AvatarUrl = statusContext.Creator.AvatarUrl(null)
774787
}).ToList()
775-
}).ToList(),
776-
Statuses = commit.Commit.Status
777-
.Select(context =>
778-
context.Contexts.Select(statusContext => new StatusModel
779-
{
780-
State = statusContext.State.FromGraphQl(),
781-
Context = statusContext.Context,
782-
TargetUrl = statusContext.TargetUrl,
783-
Description = statusContext.Description,
784-
AvatarUrl = statusContext.Creator.AvatarUrl(null)
785-
}).ToList()
786-
).SingleOrDefault()
787-
}
788-
).Compile();
788+
).SingleOrDefault()
789+
}
790+
).Compile();
791+
}
792+
else
793+
{
794+
readCommitStatuses = new Query()
795+
.Repository(Var(nameof(owner)), Var(nameof(name)))
796+
.PullRequest(Var(nameof(number))).Commits(last: 1).Nodes.Select(
797+
commit => new LastCommitAdapter
798+
{
799+
Statuses = commit.Commit.Status
800+
.Select(context =>
801+
context.Contexts.Select(statusContext => new StatusModel
802+
{
803+
State = statusContext.State.FromGraphQl(),
804+
Context = statusContext.Context,
805+
TargetUrl = statusContext.TargetUrl,
806+
Description = statusContext.Description,
807+
AvatarUrl = statusContext.Creator.AvatarUrl(null)
808+
}).ToList()
809+
).SingleOrDefault()
810+
}
811+
).Compile();
812+
}
789813
}
790814

791815
var vars = new Dictionary<string, object>

src/GitHub.VisualStudio/Views/GitHubPane/PullRequestReviewSummaryView.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
Name="root">
1717

1818
<d:DesignData.DataContext>
19-
<vm:PullRequestReviewSummaryViewModel Id="1" State="Pending" FileCommentCount="2">
19+
<vm:PullRequestReviewSummaryViewModel Id="1" State="Commented" FileCommentCount="2">
2020
<vm:PullRequestReviewSummaryViewModel.User>
2121
<ghfvs:ActorViewModel Login="meaghanlewis"/>
2222
</vm:PullRequestReviewSummaryViewModel.User>

0 commit comments

Comments
 (0)