aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2023-07-08 20:30:56 +0800
committercrupest <crupest@outlook.com>2023-07-08 20:30:56 +0800
commit72cdb2d0a93625c3904b7db25bc28d0ecfaf1c1c (patch)
tree9b199e2bbaee545588fa363ce8d122385c032695
parent91e91bc70480e3d7d29ac5f76b40a5a1f768a004 (diff)
downloadcrupest-72cdb2d0a93625c3904b7db25bc28d0ecfaf1c1c.tar.gz
crupest-72cdb2d0a93625c3904b7db25bc28d0ecfaf1c1c.tar.bz2
crupest-72cdb2d0a93625c3904b7db25bc28d0ecfaf1c1c.zip
Now draft issue in todo has correct status.
-rw-r--r--docker/crupest-api/CrupestApi/CrupestApi.Todos/TodosService.cs44
1 files changed, 34 insertions, 10 deletions
diff --git a/docker/crupest-api/CrupestApi/CrupestApi.Todos/TodosService.cs b/docker/crupest-api/CrupestApi/CrupestApi.Todos/TodosService.cs
index ac20af2..5839086 100644
--- a/docker/crupest-api/CrupestApi/CrupestApi.Todos/TodosService.cs
+++ b/docker/crupest-api/CrupestApi/CrupestApi.Todos/TodosService.cs
@@ -33,7 +33,11 @@ public class TodosService
projectV2(number: {{todoConfiguration.ProjectNumber}}) {
items(last: {{todoConfiguration.Count}}) {
nodes {
- __typename
+ fieldValueByName(name: "Status") {
+ ... on ProjectV2ItemFieldSingleSelectValue {
+ name
+ }
+ }
content {
__typename
... on Issue {
@@ -107,23 +111,43 @@ public class TodosService
{
throw new Exception("Fail to get title.");
}
- JsonElement closedElement;
- bool closed;
- if (content.TryGetProperty("closed", out closedElement))
+
+ bool done = false;
+
+ var statusField = node.GetProperty("fieldValueByName");
+ if (statusField.ValueKind != JsonValueKind.Null) // if there is a "Status" field
{
- closed = closedElement.GetBoolean();
+ var statusName = statusField.GetProperty("name").GetString();
+ if (statusName is null)
+ {
+ throw new Exception("Fail to get status.");
+ }
+
+ // if name is "Done", then it is closed, otherwise we check if the issue is closed
+ if (statusName.Equals("Done", StringComparison.OrdinalIgnoreCase))
+ {
+ done = true;
+ }
}
- else
+
+ JsonElement closedElement;
+ // if item has a "closed" field, then it is a pull request or an issue, and we check if it is closed
+ if (content.TryGetProperty("closed", out closedElement) && closedElement.GetBoolean())
{
- closed = false;
+ done = true;
}
+ // If item "Status" field is "Done' or item is a pull request or issue and it is closed, then it is done.
+ // Otherwise it is not closed. Like:
+ // 1. it is a draft issue with no "Status" field or "Status" field is not "Done"
+ // 2. it is a pull request or issue with no "Status" field or "Status" field is not "Done" and it is not closed
+
result.Add(new TodosItem
{
Title = title,
- Status = closed ? "Done" : "Todo",
- Closed = closed,
- Color = closed ? "green" : "blue"
+ Status = done ? "Done" : "Todo",
+ Closed = done,
+ Color = done ? "green" : "blue"
});
}