(call: Call)
| 87 | |
| 88 | /** Repeated successful reads of the same projection between events count as polling. */ |
| 89 | export function statusRead(call: Call): string | undefined { |
| 90 | if (call.kind !== "gh" || call.success !== true) return; |
| 91 | const { words, options, fields, help } = command(call.arguments); |
| 92 | if (help) return; |
| 93 | if (words[0] === "pr" && words[1] === "view") { |
| 94 | const fields = options.get("--json")?.split(",").sort(); |
| 95 | if (fields && !fields.some(field => ["reviews", "latestReviews", "reviewDecision", "state", "closed", "closedAt", "mergedAt"].includes(field))) return; |
| 96 | return JSON.stringify(["pr-view", words.slice(2), options.get("--repo") ?? options.get("-R"), fields]); |
| 97 | } |
| 98 | if (words[0] === "api") { |
| 99 | const method = options.get("--method") ?? options.get("-X") |
| 100 | ?? (["-f", "-F", "--field", "--raw-field", "--input"].some(flag => options.has(flag)) ? "POST" : "GET"); |
| 101 | const path = words[1]; |
| 102 | if (method.toUpperCase() === "GET" && path && /(?:^|\/)pulls\/\d+(?:[/?]|$)/.test(path)) { |
| 103 | return `api:${path}`; |
| 104 | } |
| 105 | const query = fields.find(field => field.startsWith("query=")); |
| 106 | if (path === "graphql" && query?.includes("pullRequest") && !/\bmutation\b/.test(query)) { |
| 107 | // The bindings of the query's variables tell apart reads of different pull requests with the same query. |
| 108 | const variables = new Set(Array.from(query.matchAll(/\$(\w+)/g), match => match[1])); |
| 109 | const bindings = fields.filter(field => field !== query && variables.has(field.split("=")[0])).sort(); |
| 110 | return JSON.stringify(["graphql", query, bindings]); |
| 111 | } |
| 112 | } |
| 113 | } |
no test coverage detected