-
Notifications
You must be signed in to change notification settings - Fork 48
/
PullRequestTests.cs
258 lines (231 loc) · 9.91 KB
/
PullRequestTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Octokit.GraphQL.IntegrationTests.Utilities;
using Octokit.GraphQL.Model;
using Xunit;
using static Octokit.GraphQL.Variable;
namespace Octokit.GraphQL.IntegrationTests.Queries
{
public class PullRequestTests : IntegrationTestBase
{
[IntegrationTest]
public async Task Should_Query_Commits()
{
var query = new Query()
.Repository(owner: "octokit", name: "octokit.net")
.PullRequest(number: 1)
.Commits(first: 3)
.Nodes
.Select(pullRequestCommit => new
{
pullRequestCommit.Commit.Id,
pullRequestCommit.Commit.Message,
pullRequestCommit.Commit.Author.Name
});
var results = (await Connection.Run(query)).ToArray();
Assert.Single(results);
Assert.Equal("MDY6Q29tbWl0NzUyODY3OTpkYWZhYjhhZjA0ODM5NDU1ODM4Y2QzZmRlMTFkMTM5MTc0MTYyZmFh", results[0].Id.Value);
var expectedMessage = "Adding README, CONTRIBUTING, LICENSE\n\nWe plan to release this code under the MIT license so might as well get\nthe right things in place early.";
Assert.Equal(expectedMessage, results[0].Message);
Assert.Equal("Haacked", results[0].Name);
}
[IntegrationTest]
public async Task Should_Query_Commits_AllPages_Aliased_Id()
{
var query = new GraphQL.Query().Repository(owner: "octokit", name: "octokit.net")
.PullRequests(last:1).Nodes
.Select(request =>
request.Commits(null, null, null, null)
.AllPages(1)
.Select(pullRequestCommit => new
{
PullRequestCommitId = pullRequestCommit.Id.Value,
pullRequestCommit.Commit.Id,
pullRequestCommit.Commit.Message,
pullRequestCommit.Commit.Author.Name
}).ToList());
var results = (await Connection.Run(query)).ToArray();
}
[IntegrationTest]
public async Task Should_Query_Repository_PullRequest_CheckRun_Normal_Id()
{
var query = new Query()
.Repository(owner: "github", name: "visualstudio")
.PullRequest(1864)
.Commits(last:1).Nodes
.Select(commit => new
{
CheckSuites = commit.Commit.CheckSuites(null, null, null, null, null).AllPages(10)
.Select(suite => new
{
CheckRuns = suite.CheckRuns(null, null, null, null, null).AllPages(10)
.Select(run => new
{
Name = run.Name,
Annotations = run.Annotations(null, null, null, null).AllPages()
.Select(annotation => new
{
Path = annotation.Path,
}).ToList()
}).ToList(),
}).ToList()
});
var results = (await Connection.Run(query)).ToArray();
}
[IntegrationTest]
public async Task Should_Query_Repository_PullRequest_CheckRun_Aliased_Id()
{
var query = new Query()
.Repository(owner: "github", name: "visualstudio")
.PullRequest(1864)
.Commits(last:1).Nodes
.Select(commit => new
{
CheckSuites = commit.Commit.CheckSuites(null, null, null, null, null).AllPages(10)
.Select(suite => new
{
CheckRuns = suite.CheckRuns(null, null, null, null, null).AllPages(10)
.Select(run => new
{
CheckRunId = run.Id.Value,
Name = run.Name,
Annotations = run.Annotations(null, null, null, null).AllPages()
.Select(annotation => new
{
Path = annotation.Path,
}).ToList()
}).ToList(),
}).ToList()
}
);
var results = (await Connection.Run(query)).ToArray();
}
[IntegrationTest]
public async Task Should_Query_Title_With_Vars()
{
var query = new Query()
.Repository(owner: Var("owner"), name: Var("name"))
.PullRequest(number: Var("number"))
.Select(x => x.Title)
.Compile();
var vars = new Dictionary<string, object>
{
{ "owner", "octokit" },
{ "name", "octokit.net" },
{ "number", 1 },
};
var result = await Connection.Run(query, vars);
Assert.Equal("Adding README, CONTRIBUTING, LICENSE", result);
}
[IntegrationTest]
public async Task Can_Use_Conditional_In_BaseRef_Query()
{
var query = new Query()
.Repository(owner: "octokit", name: "octokit.net")
.PullRequest(number: 1)
.Select(pr => new
{
BaseRefName = pr.BaseRef != null ? pr.BaseRef.Name : null,
BaseRefNotNull = pr.BaseRef != null
});
var result = await Connection.Run(query);
if (result.BaseRefNotNull)
{
Assert.Equal("main", result.BaseRefName);
}
else
{
Assert.Null(result.BaseRefName);
}
}
[IntegrationTest]
public async Task Can_Use_Conditional_When_Selecting_Base_Repository_Owner()
{
var query = new Query()
.Repository(owner: "octokit", name: "octokit.net")
.PullRequest(number: 1)
.Select(pr => new
{
Owner = pr.BaseRef != null ? pr.BaseRef.Repository.Owner.Login : null,
BaseRefNotNull = pr.BaseRef != null
});
var result = await Connection.Run(query);
if (result.BaseRefNotNull)
{
Assert.Equal("octokit", result.Owner);
}
else
{
Assert.Null(result.Owner);
}
}
[IntegrationTest]
public async Task Can_AutoPage_Reviews_Comments()
{
// nodegit/nodegit#1331 has a review with >100 comments.
var query = new Query()
.Repository(owner: "nodegit", name: "nodegit")
.PullRequest(number: 1331)
.Select(pr => new
{
pr.Title,
Reviews = pr.Reviews(null, null, null, null, null, null).AllPages().Select(review => new
{
Comments = review.Comments(null, null, null, null).AllPages().Select(comment => new
{
comment.Body,
}).ToList(),
}).ToList(),
}).Compile();
var result = await Connection.Run(query);
Assert.True(result.Reviews.Count > 0);
Assert.True(result.Reviews[0].Comments.Count > 100);
}
[IntegrationTest]
public async Task Can_AutoPage_Reviews_Comments_2()
{
// Microsoft/MixedRealityToolkit-Unity#1884 has >100 reviews, one of which has >100 comments.
var query = new Query()
.Repository(owner: "Microsoft", name: "MixedRealityToolkit-Unity")
.PullRequest(number: 1884)
.Select(pr => new
{
pr.Title,
Reviews = pr.Reviews(null, null, null, null, null, null).AllPages().Select(review => new
{
Comments = review.Comments(null, null, null, null).AllPages().Select(comment => new
{
comment.Id,
comment.Body,
}).ToList(),
}).ToList(),
}).Compile();
var result = await Connection.Run(query);
Assert.True(result.Reviews.Count > 100);
Assert.Contains(result.Reviews, x => x.Comments.Count > 100);
}
[IntegrationTest]
public async Task PullRequest_Status_Context_CanBeNull()
{
var query = new Query()
.Repository(owner: "StanleyGoldman", name: "ConsoleCoreAppWithYamlForNoReason")
.PullRequests(1)
.Select(page =>
page.Nodes.Select(pr => new
{
Id = pr.Id.Value,
LastCommit = pr.Commits(null, null, 1, null).Nodes.Select(commit => new
{
commit.Id,
Statuses = commit.Commit.Status
.Select(status => status.Contexts.Select(context => context.State).ToList())
.SingleOrDefault()
}).ToList().FirstOrDefault(),
}).ToList().First()
).Compile();
var result = await Connection.Run(query);
Assert.Null(result.LastCommit.Statuses);
}
}
}