Skip to content

Commit aff38ef

Browse files
authored
Re-enable seQuestering PRs (#374)
* Turn on PR requests * Getting timeline items for a PR has issues Rework the queries so that the queries for PRs don't include timeline items. Including them seems to cause a graph infinite loop in the PR as the "closing PR" is the same PR * fix test to match new behavior
1 parent b517d73 commit aff38ef

File tree

4 files changed

+40
-29
lines changed

4 files changed

+40
-29
lines changed

DotNet.DocsTools/GitHubObjects/QuestIssueOrPullRequest.cs

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,36 @@ ... on User {
130130
query FindUpdatedIssues($organization: String!, $repository: String!, $questlabels: [String!], $cursor: String) {
131131
repository(owner: $organization, name: $repository) {
132132
issues(
133-
""" + EnumerationQueryBody;
133+
""" + EnumerationQueryBody +
134+
"""
135+
timelineItems(last: 5) {
136+
nodes {
137+
... on ClosedEvent {
138+
closer {
139+
... on PullRequest {
140+
url
141+
}
142+
}
143+
}
144+
}
145+
}
146+
}
147+
}
148+
}
149+
}
150+
""";
134151

135152
protected const string EnumerateQuestPullRequestQueryText = """
136153
query FindUpdatedPullRequests($organization: String!, $repository: String!, $questlabels: [String!], $cursor: String) {
137154
repository(owner: $organization, name: $repository) {
138155
pullRequests(
139-
""" + EnumerationQueryBody;
156+
""" + EnumerationQueryBody +
157+
"""
158+
}
159+
}
160+
}
161+
}
162+
""";
140163

141164
private const string EnumerationQueryBody = """
142165
first: 25
@@ -163,17 +186,6 @@ ... on User {
163186
name
164187
}
165188
}
166-
timelineItems(last: 5) {
167-
nodes {
168-
... on ClosedEvent {
169-
closer {
170-
... on PullRequest {
171-
url
172-
}
173-
}
174-
}
175-
}
176-
}
177189
projectItems(first: 25) {
178190
... on ProjectV2ItemConnection {
179191
nodes {
@@ -226,13 +238,9 @@ ... on User {
226238
bodyHTML
227239
}
228240
}
229-
}
230-
}
231-
}
232-
}
233241
""";
234242

235-
private protected QuestIssueOrPullRequest(JsonElement issueNode, string organization, string repository) : base(issueNode)
243+
private protected QuestIssueOrPullRequest(JsonElement issueNode, string organization, string repository, bool includeTimeLine=true) : base(issueNode)
236244
{
237245
var author = Actor.FromJsonElement(ResponseExtractors.GetAuthorChildElement(issueNode));
238246
FormattedAuthorLoginName = (author is not null) ?
@@ -260,10 +268,13 @@ private protected QuestIssueOrPullRequest(JsonElement issueNode, string organiza
260268
ProjectStoryPoints = [ ..points.Where(p => p is not null).ToArray()];
261269

262270
// check state. If re-opened, don't reference the (not correct) closing PR
263-
ClosingPRUrl = ResponseExtractors.GetChildArrayElements(issueNode, "timelineItems", item =>
264-
(item.TryGetProperty("closer", out JsonElement closer) && closer.ValueKind == JsonValueKind.Object) ?
265-
ResponseExtractors.OptionalStringProperty(closer, "url")
266-
: default).LastOrDefault(url => url is not null);
271+
if (includeTimeLine)
272+
{
273+
ClosingPRUrl = ResponseExtractors.GetChildArrayElements(issueNode, "timelineItems", item =>
274+
(item.TryGetProperty("closer", out JsonElement closer) && closer.ValueKind == JsonValueKind.Object) ?
275+
ResponseExtractors.OptionalStringProperty(closer, "url")
276+
: default).LastOrDefault(url => url is not null);
277+
}
267278

268279
LinkText = $"""
269280
<a href = "https://github.com/{organization}/{repository}/issues/{Number}">

DotNet.DocsTools/GitHubObjects/QuestPullRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,5 @@ public static IEnumerable<string> NavigationToNodes(bool isScalar) =>
4848
public static QuestPullRequest FromJsonElement(JsonElement issueNode, QuestIssueOrPullRequestVariables variables) =>
4949
new(issueNode, variables.Organization, variables.Repository);
5050

51-
private QuestPullRequest(JsonElement issueNode, string organization, string repository) : base(issueNode, organization, repository) { }
51+
private QuestPullRequest(JsonElement issueNode, string organization, string repository) : base(issueNode, organization, repository, false) { }
5252
}

DotnetDocsToolsTests/GraphQLProcessingTests/QuestIssueTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ public void ClosedQuestIssueFromJsonNode()
503503
Assert.Equal(2023, points.CalendarYear);
504504
Assert.Equal("Dec", points.Month);
505505
Assert.Equal("🦔 Tiny (4h)", points.Size);
506-
Assert.Equal("https://github.com/dotnet/docs/pull/38584", issue.ClosingPRUrl);
506+
Assert.Null(issue.ClosingPRUrl);
507507
}
508508

509509
[Fact]

actions/sequester/Quest2GitHub/QuestGitHubService.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ public async Task ProcessIssues(string organization, string repository, int dura
7676
var issueQueryEnumerable = QueryIssuesOrPullRequests<QuestIssue>();
7777
await ProcessItems(issueQueryEnumerable);
7878
Console.WriteLine("----- Finished processing issues. --------");
79-
//Console.WriteLine(" ----- Regenerating bearer token ------");
79+
Console.WriteLine(" ----- Regenerating bearer token ------");
8080
await ghClient.RegenerateBearerToken();
81-
//Console.WriteLine("----- Starting processing pull requests. --------");
82-
//var prQueryEnumerable = QueryIssuesOrPullRequests<QuestPullRequest>();
83-
//await ProcessItems(prQueryEnumerable);
84-
//Console.WriteLine("----- Finished processing pull requests. --------");
81+
Console.WriteLine("----- Starting processing pull requests. --------");
82+
var prQueryEnumerable = QueryIssuesOrPullRequests<QuestPullRequest>();
83+
await ProcessItems(prQueryEnumerable);
84+
Console.WriteLine("----- Finished processing pull requests. --------");
8585

8686
async Task ProcessItems(IAsyncEnumerable<QuestIssueOrPullRequest> items)
8787
{

0 commit comments

Comments
 (0)