pr-report-core 0.0.0-stage → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +71 -2
  3. package/dist/checks.d.mts +146 -0
  4. package/dist/checks.d.mts.map +1 -0
  5. package/dist/checks.mjs +216 -0
  6. package/dist/checks.mjs.map +1 -0
  7. package/dist/claim.d.mts +63 -0
  8. package/dist/claim.d.mts.map +1 -0
  9. package/dist/claim.mjs +84 -0
  10. package/dist/claim.mjs.map +1 -0
  11. package/dist/closing-issues.d.mts +49 -0
  12. package/dist/closing-issues.d.mts.map +1 -0
  13. package/dist/closing-issues.mjs +84 -0
  14. package/dist/closing-issues.mjs.map +1 -0
  15. package/dist/code-owners.d.mts +85 -0
  16. package/dist/code-owners.d.mts.map +1 -0
  17. package/dist/code-owners.mjs +134 -0
  18. package/dist/code-owners.mjs.map +1 -0
  19. package/dist/entry-point.d.mts +2 -0
  20. package/dist/entry-point.d.mts.map +1 -0
  21. package/dist/entry-point.mjs +2 -0
  22. package/dist/entry-point.mjs.map +1 -0
  23. package/dist/index.d.mts +20 -0
  24. package/dist/index.d.mts.map +1 -0
  25. package/dist/index.mjs +20 -0
  26. package/dist/index.mjs.map +1 -0
  27. package/dist/labels.d.mts +72 -0
  28. package/dist/labels.d.mts.map +1 -0
  29. package/dist/labels.mjs +72 -0
  30. package/dist/labels.mjs.map +1 -0
  31. package/dist/merge-after.d.mts +49 -0
  32. package/dist/merge-after.d.mts.map +1 -0
  33. package/dist/merge-after.mjs +133 -0
  34. package/dist/merge-after.mjs.map +1 -0
  35. package/dist/queue-comments.d.mts +42 -0
  36. package/dist/queue-comments.d.mts.map +1 -0
  37. package/dist/queue-comments.mjs +48 -0
  38. package/dist/queue-comments.mjs.map +1 -0
  39. package/dist/queue-order.d.mts +247 -0
  40. package/dist/queue-order.d.mts.map +1 -0
  41. package/dist/queue-order.mjs +317 -0
  42. package/dist/queue-order.mjs.map +1 -0
  43. package/dist/queue-owner.d.mts +85 -0
  44. package/dist/queue-owner.d.mts.map +1 -0
  45. package/dist/queue-owner.mjs +212 -0
  46. package/dist/queue-owner.mjs.map +1 -0
  47. package/dist/report.d.mts +61 -0
  48. package/dist/report.d.mts.map +1 -0
  49. package/dist/report.mjs +128 -0
  50. package/dist/report.mjs.map +1 -0
  51. package/dist/review-hold.d.mts +61 -0
  52. package/dist/review-hold.d.mts.map +1 -0
  53. package/dist/review-hold.mjs +72 -0
  54. package/dist/review-hold.mjs.map +1 -0
  55. package/dist/ruleset.d.mts +500 -0
  56. package/dist/ruleset.d.mts.map +1 -0
  57. package/dist/ruleset.mjs +83 -0
  58. package/dist/ruleset.mjs.map +1 -0
  59. package/dist/set-aside.d.mts +102 -0
  60. package/dist/set-aside.d.mts.map +1 -0
  61. package/dist/set-aside.mjs +116 -0
  62. package/dist/set-aside.mjs.map +1 -0
  63. package/dist/stack.d.mts +40 -0
  64. package/dist/stack.d.mts.map +1 -0
  65. package/dist/stack.mjs +62 -0
  66. package/dist/stack.mjs.map +1 -0
  67. package/dist/start-after.d.mts +133 -0
  68. package/dist/start-after.d.mts.map +1 -0
  69. package/dist/start-after.mjs +100 -0
  70. package/dist/start-after.mjs.map +1 -0
  71. package/dist/summarize.d.mts +12 -0
  72. package/dist/summarize.d.mts.map +1 -0
  73. package/dist/summarize.mjs +21 -0
  74. package/dist/summarize.mjs.map +1 -0
  75. package/dist/timestamp.d.mts +17 -0
  76. package/dist/timestamp.d.mts.map +1 -0
  77. package/dist/timestamp.mjs +62 -0
  78. package/dist/timestamp.mjs.map +1 -0
  79. package/dist/tree.d.mts +32 -0
  80. package/dist/tree.d.mts.map +1 -0
  81. package/dist/tree.mjs +60 -0
  82. package/dist/tree.mjs.map +1 -0
  83. package/dist/tsconfig.json +1 -0
  84. package/dist/types.d.mts +259 -0
  85. package/dist/types.d.mts.map +1 -0
  86. package/dist/types.mjs +3 -0
  87. package/dist/types.mjs.map +1 -0
  88. package/package.json +107 -3
  89. package/src/checks.mts +310 -0
  90. package/src/checks.test.mts +761 -0
  91. package/src/claim.mts +128 -0
  92. package/src/claim.test.mts +134 -0
  93. package/src/closing-issues.mts +127 -0
  94. package/src/closing-issues.test.mts +162 -0
  95. package/src/code-owners.mts +229 -0
  96. package/src/code-owners.test.mts +237 -0
  97. package/src/entry-point.mts +1 -0
  98. package/src/index.mts +19 -0
  99. package/src/labels.mts +79 -0
  100. package/src/merge-after.mts +175 -0
  101. package/src/merge-after.test.mts +221 -0
  102. package/src/queue-comments.mts +101 -0
  103. package/src/queue-comments.test.mts +108 -0
  104. package/src/queue-order.mts +567 -0
  105. package/src/queue-order.test.mts +432 -0
  106. package/src/queue-owner.mts +315 -0
  107. package/src/queue-owner.test.mts +257 -0
  108. package/src/report.mts +253 -0
  109. package/src/report.test.mts +390 -0
  110. package/src/review-hold.mts +115 -0
  111. package/src/review-hold.test.mts +163 -0
  112. package/src/ruleset.mts +140 -0
  113. package/src/ruleset.test.mts +171 -0
  114. package/src/set-aside.mts +173 -0
  115. package/src/set-aside.test.mts +163 -0
  116. package/src/stack.mts +98 -0
  117. package/src/stack.test.mts +124 -0
  118. package/src/start-after.mts +238 -0
  119. package/src/start-after.test.mts +351 -0
  120. package/src/summarize.mts +27 -0
  121. package/src/timestamp.mts +91 -0
  122. package/src/timestamp.test.mts +31 -0
  123. package/src/tree.mts +98 -0
  124. package/src/tree.test.mts +133 -0
  125. package/src/types.mts +269 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,72 @@
1
- # Temporary Holding Version
1
+ # `pr-report-core`
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ What a merge queue run by labels and `Merge-After:` trailers decides about a
4
+ repository's open pull requests: whether each one's checks pass by what the
5
+ branch requires, the order they may merge in, which is stacked on which, and
6
+ who moves each one next. Nothing here talks to GitHub; a reader fetches what
7
+ these functions need, its own way, and hands it over.
8
+
9
+ ```sh
10
+ npm add pr-report-core
11
+ ```
12
+
13
+ Two readers share it, so they cannot disagree:
14
+
15
+ | reader | reads GitHub through | runs in |
16
+ | :---------------------------------------------------------------------------------- | :------------------- | :------------------------- |
17
+ | [GitHub Pull Requests Manager](https://noshiro-pf.github.io/mono/pr-manager/) | GraphQL | the browser, on every read |
18
+ | `unblock-prs`, `open-pr` and `pr-report` (`noshiro-pf/mono`'s `tools/scripts/cmd/`) | REST and GraphQL | a terminal, or an agent |
19
+
20
+ ## Example
21
+
22
+ ```ts
23
+ import { findMergeAfterCycles, parseMergeAfter } from 'pr-report-core';
24
+
25
+ const body = [
26
+ 'Adds the second half of the parser.',
27
+ '',
28
+ 'Merge-After: #12, #14',
29
+ ].join('\n');
30
+
31
+ assert.deepStrictEqual(parseMergeAfter(body), [12, 14]);
32
+
33
+ // #12 waits for #14 and #14 for #12: neither can ever merge first.
34
+ const cycles = findMergeAfterCycles(
35
+ new Map([
36
+ [12, [14]],
37
+ [14, [12]],
38
+ ]),
39
+ );
40
+
41
+ assert.deepStrictEqual(cycles, [[12, 14]]);
42
+ ```
43
+
44
+ ## What is here
45
+
46
+ - **`checks.mts`** — the verdict over the contexts the branch requires, from
47
+ the check runs and commit statuses on a head commit. Which of two runs of
48
+ one name counts, and why it is the later suite rather than the later run,
49
+ is written there.
50
+ - **`merge-after.mts`**, **`start-after.mts`** — reading the `Merge-After:`
51
+ trailers out of a pull request's body and `Start-After:` out of an issue's,
52
+ and finding the cycles in them.
53
+ - **`stack.mts`** — which pull request is stacked on which: one opened onto
54
+ another open pull request's branch waits for it as if it had declared
55
+ `Merge-After:` on it.
56
+ - **`tree.mts`** and **`report.mts`** — the declarations and the stacks as the
57
+ forest they describe, and everything read arranged into a report.
58
+ - **`summarize.mts`** — the counts a report leads with.
59
+ - **`ruleset.mts`** — what a ruleset requires: the contexts, and whether code
60
+ owners have to approve. **`code-owners.mts`**, **`review-hold.mts`** — who
61
+ owns a change, and whether a review holds a pull request.
62
+ - **`queue-owner.mts`**, **`queue-order.mts`** — who moves each queued pull
63
+ request next, and the order the queue picks them in.
64
+ - **`set-aside.mts`**, **`claim.mts`** — the comments `unblock-prs` and a
65
+ session leave on a pull request: the hidden record each starts with, read
66
+ back by the worker and the page.
67
+ - **`labels.mts`** — `skip-ci`, `merge-queued`, `blocks-release`,
68
+ `auto-rebase`, `pending` and the `priority:*` labels.
69
+
70
+ The conventions themselves — what to write, and what the page shows for it —
71
+ are in the
72
+ [GitHub Pull Requests Manager's README](https://github.com/noshiro-pf/mono/tree/main/apps/pr-manager-app#what-your-repository-can-add).
@@ -0,0 +1,146 @@
1
+ /** What the checks on a head commit add up to. */
2
+ import type { ChecksSummary, ContextState } from './types.mjs';
3
+ /**
4
+ * What every context reported, from a head commit's check runs.
5
+ *
6
+ * A name appears more than once whenever two check suites reported it, and on
7
+ * a queued pull request that is the normal case rather than the odd one: the
8
+ * run the `opened` event starts is cancelled by the `labeled` event's, and
9
+ * both stay on the commit — the cancelled one leaving its `*-result`
10
+ * aggregate concluded `failure`, because an `if: always()` job that asserts
11
+ * on cancelled `needs` fails.
12
+ *
13
+ * **The newest check suite wins, and that is not the same as the newest
14
+ * run.** GitHub resolves a required context to the run in the suite with the
15
+ * greatest id, so where the cancelled suite happens to have been created
16
+ * after the one that superseded it, the stale red is what holds the merge —
17
+ * however much later the green one finished. Every suite of one push is
18
+ * created in the same second, so which of them got the higher id is not
19
+ * something the repository decides.
20
+ *
21
+ * This is why the rule is not "the newest `started_at`", which reads more
22
+ * natural and would call such a pull request green while GitHub blocks it.
23
+ * A report that says a blocked pull request will merge is worse than one
24
+ * that says a green one will not: `CLAUDE.md`'s "Commits and pull requests"
25
+ * says to ignore the red the cancelled run leaves, and this is the case where
26
+ * GitHub does not.
27
+ *
28
+ * **A run whose workflow has a newer round still going is pending.** An
29
+ * aggregate has no run in a round until the jobs it waits on are done, so
30
+ * until then the only run of its name is the previous round's — on a pull
31
+ * request whose label events started two rounds, the red the second left on
32
+ * the first (#2191). That run is what GitHub shows, but not what it will
33
+ * answer with: the newer round is in the suite with the greater id, and its
34
+ * aggregate will be the newest run of the name. Where the newer round has
35
+ * finished without one, the older run stands, as it does on GitHub.
36
+ */
37
+ export declare const statesFromCheckRuns: (runs: readonly CheckRunReport[]) => ReadonlyMap<string, ContextState>;
38
+ /** One check run, in the terms the decision above is made in. */
39
+ export type CheckRunReport = Readonly<{
40
+ name: string;
41
+ status: string;
42
+ conclusion: string | undefined;
43
+ /** The suite it belongs to. Greatest wins, which is what GitHub does. */
44
+ checkSuiteId: number;
45
+ /** Ascending, so it orders two runs of one name inside one suite. */
46
+ id: number;
47
+ /**
48
+ * The workflow run its suite is, where it is one: the workflow, so that a
49
+ * newer round of it can be told from an unrelated suite, and whether the
50
+ * round has finished, which its runs alone do not say — an aggregate's run
51
+ * is created only once every job before it has completed. `undefined` for
52
+ * a run no workflow made, or where the workflow runs could not be read.
53
+ */
54
+ round: Readonly<{
55
+ workflowId: number;
56
+ completed: boolean;
57
+ }> | undefined;
58
+ }>;
59
+ /**
60
+ * What one check run has reported.
61
+ *
62
+ * A run that has not completed is pending whatever it concluded last — the
63
+ * conclusion of a re-run is the previous verdict until the new one finishes.
64
+ * A `skipped` conclusion is reported as `skipped` and counted as met by
65
+ * {@link summarizeChecks}, because GitHub counts it as met: the gated jobs
66
+ * skip on `skip-ci` and on a diff the workflow does not read, and reading
67
+ * that as a failure would call every gated pull request red.
68
+ * Everything else that finished — `cancelled`, `stale`, `timed_out`,
69
+ * `action_required` — is something a reader has to act on, so it is a
70
+ * failure here even where GitHub is vaguer about it.
71
+ */
72
+ export declare const classifyCheckRun: (status: string, conclusion: string | undefined) => ContextState;
73
+ /**
74
+ * Whether any run on the head commit has not finished, or any round has not.
75
+ *
76
+ * Every run, not only the required ones: the aggregates are `if: always()`
77
+ * and have no run in the newest round until the jobs they wait on are done,
78
+ * so "every required context has reported" is true of a commit halfway
79
+ * through a round — with the reports coming from the round before. And the
80
+ * round, not only its runs: between the last job finishing and the aggregate
81
+ * being created, every run there is has completed.
82
+ */
83
+ export declare const anyRunInProgress: (runs: readonly CheckRunReport[]) => boolean;
84
+ /**
85
+ * What every context has reported on one commit, from both places GitHub
86
+ * keeps them. The aggregate jobs are check runs; `no-skip-ci-label` is a
87
+ * commit status, so reading only the first would report the context that
88
+ * holds every labelled pull request as missing.
89
+ *
90
+ * `state` is a commit status's as the REST API spells it, in lower case.
91
+ */
92
+ export declare const reportedContexts: (runs: readonly CheckRunReport[], statuses: readonly Readonly<{
93
+ context: string;
94
+ state: string;
95
+ }>[]) => ReadonlyMap<string, ContextState>;
96
+ /**
97
+ * What a context reported that is both a check run and a commit status.
98
+ *
99
+ * Not "the status wins", which is what this used to assume. GitHub's own
100
+ * answer is that neither does: "If a check and a commit status have the same
101
+ * name, both must pass when that name is required." So the stricter of the
102
+ * two is the verdict, and a green status cannot cover a red check run of the
103
+ * same name. A skip beside a pass is a skip: both are met, but only one of
104
+ * them ran.
105
+ */
106
+ export declare const combineContextStates: (a: ContextState, b: ContextState) => ContextState;
107
+ /**
108
+ * What one commit status has reported. `no-skip-ci-label` is one of these
109
+ * rather than a check run, so a report that read only check runs would call
110
+ * the context that holds every labelled pull request "missing".
111
+ */
112
+ export declare const classifyCommitStatus: (state: string) => ContextState;
113
+ /**
114
+ * The verdict on one pull request, reached over the contexts the ruleset
115
+ * requires and no others: a failing job nothing requires does not block a
116
+ * merge, and listing it would bury the one that does.
117
+ *
118
+ * `paused` outranks the rest. While `skip-ci` is on, the checks a reader
119
+ * sees are whatever survived from before the label went on — typically the
120
+ * red left by the `opened` run that the `labeled` run cancelled. Calling
121
+ * that "failing" would make every queued pull request look broken; the
122
+ * failures are still listed, because they are what a reader asks about.
123
+ *
124
+ * `running` is the third thing that makes a verdict provisional, beside a
125
+ * required context that is pending and one that has not reported. Without it
126
+ * a commit mid-round reads as settled out of the round before — which is how
127
+ * a failing pull request (#2031) came to show a tick.
128
+ *
129
+ * **Off the covered base, a context that never reported is not awaited.**
130
+ * The contexts are the ones the ruleset asks of `main`, and a workflow that
131
+ * runs only on pull requests into `main` never reports on a stacked one —
132
+ * which kept #2103, every check of it green, "running" until it was moved
133
+ * onto `main`. Such a context is {@link ChecksSummary.notRun} instead, but
134
+ * only once some required context has reported: before the first check
135
+ * suite, nothing having come is not a pass over zero contexts.
136
+ */
137
+ export declare const summarizeChecks: ({ required, reported, paused, running, baseCovered, }: Readonly<{
138
+ required: readonly string[];
139
+ reported: ReadonlyMap<string, ContextState>;
140
+ paused: boolean;
141
+ /** Whether anything at all is still going on the head commit. */
142
+ running: boolean;
143
+ /** Whether the ruleset applies to the pull request's base branch. */
144
+ baseCovered: boolean;
145
+ }>) => ChecksSummary;
146
+ //# sourceMappingURL=checks.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checks.d.mts","sourceRoot":"","sources":["../src/checks.mts"],"names":[],"mappings":"AAAA,kDAAkD;AAGlD,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,eAAO,MAAM,mBAAmB,SACxB,SAAS,cAAc,EAAE,KAC9B,WAAW,CAAC,MAAM,EAAE,YAAY,CAgDlC,CAAC;AAEF,iEAAiE;AACjE,MAAM,MAAM,cAAc,GAAG,QAAQ,CAAC;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,yEAAyE;IACzE,YAAY,EAAE,MAAM,CAAC;IACrB,qEAAqE;IACrE,EAAE,EAAE,MAAM,CAAC;IACX;;;;;;OAMG;IACH,KAAK,EAAE,QAAQ,CAAC;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,OAAO,CAAA;KAAE,CAAC,GAAG,SAAS,CAAC;CACzE,CAAC,CAAC;AAEH;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,gBAAgB,WACnB,MAAM,cACF,MAAM,GAAG,SAAS,KAC7B,YAOe,CAAC;AAOnB;;;;;;;;;GASG;AACH,eAAO,MAAM,gBAAgB,SAAU,SAAS,cAAc,EAAE,KAAG,OAGhE,CAAC;AAYJ;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,SACrB,SAAS,cAAc,EAAE,YACrB,SAAS,QAAQ,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,EAAE,KAChE,WAAW,CAAC,MAAM,EAAE,YAAY,CAoBlC,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,oBAAoB,MAC5B,YAAY,KACZ,YAAY,KACd,YAOe,CAAC;AAEnB;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,UAAW,MAAM,KAAG,YAWpD,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,eAAe,0DAMzB,QAAQ,CAAC;IACV,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IAC5C,MAAM,EAAE,OAAO,CAAC;IAChB,iEAAiE;IACjE,OAAO,EAAE,OAAO,CAAC;IACjB,qEAAqE;IACrE,WAAW,EAAE,OAAO,CAAC;CACtB,CAAC,KAAG,aAiCJ,CAAC"}
@@ -0,0 +1,216 @@
1
+
2
+ import { Arr } from 'ts-data-forge';
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
+ export const statesFromCheckRuns = (runs) => {
38
+ const mut_winner = new Map();
39
+ const mut_latestRound = new Map();
40
+ for (const run of runs) {
41
+ const previous = mut_winner.get(run.name);
42
+ if (previous === undefined || outranks(run, previous)) {
43
+ mut_winner.set(run.name, run);
44
+ }
45
+ if (run.round === undefined) {
46
+ continue;
47
+ }
48
+ const latest = mut_latestRound.get(run.round.workflowId);
49
+ if (latest === undefined || run.checkSuiteId > latest.checkSuiteId) {
50
+ mut_latestRound.set(run.round.workflowId, {
51
+ checkSuiteId: run.checkSuiteId,
52
+ completed: run.round.completed,
53
+ });
54
+ }
55
+ }
56
+ const mut_states = new Map();
57
+ for (const [name, run] of mut_winner) {
58
+ const latest = run.round === undefined
59
+ ? undefined
60
+ : mut_latestRound.get(run.round.workflowId);
61
+ mut_states.set(name, latest !== undefined &&
62
+ latest.checkSuiteId !== run.checkSuiteId &&
63
+ !latest.completed
64
+ ? 'pending'
65
+ : classifyCheckRun(run.status, run.conclusion));
66
+ }
67
+ return mut_states;
68
+ };
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+
82
+ export const classifyCheckRun = (status, conclusion) => status !== 'completed'
83
+ ? 'pending'
84
+ : conclusion === 'skipped'
85
+ ? 'skipped'
86
+ : conclusion !== undefined && PASSING_CONCLUSIONS.has(conclusion)
87
+ ? 'passed'
88
+ : 'failed';
89
+ const PASSING_CONCLUSIONS = new Set([
90
+ 'neutral',
91
+ 'success',
92
+ ]);
93
+
94
+
95
+
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+ export const anyRunInProgress = (runs) => runs.some((run) => run.status !== 'completed' || run.round?.completed === false);
104
+
105
+
106
+
107
+
108
+
109
+ const outranks = (run, previous) => run.checkSuiteId === previous.checkSuiteId
110
+ ? run.id > previous.id
111
+ : run.checkSuiteId > previous.checkSuiteId;
112
+
113
+
114
+
115
+
116
+
117
+
118
+
119
+
120
+ export const reportedContexts = (runs, statuses) => {
121
+
122
+
123
+
124
+ const mut_states = new Map(statesFromCheckRuns(runs));
125
+ for (const { context, state } of statuses) {
126
+ const fromStatus = classifyCommitStatus(state);
127
+ const reported = mut_states.get(context);
128
+ mut_states.set(context, reported === undefined
129
+ ? fromStatus
130
+ : combineContextStates(reported, fromStatus));
131
+ }
132
+ return mut_states;
133
+ };
134
+
135
+
136
+
137
+
138
+
139
+
140
+
141
+
142
+
143
+
144
+ export const combineContextStates = (a, b) => a === 'failed' || b === 'failed'
145
+ ? 'failed'
146
+ : a === 'pending' || b === 'pending'
147
+ ? 'pending'
148
+ : a === 'skipped' || b === 'skipped'
149
+ ? 'skipped'
150
+ : 'passed';
151
+
152
+
153
+
154
+
155
+
156
+ export const classifyCommitStatus = (state) => {
157
+ switch (state) {
158
+ case 'success':
159
+ return 'passed';
160
+ case 'pending':
161
+ return 'pending';
162
+ default:
163
+ return 'failed';
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
+ export const summarizeChecks = ({ required, reported, paused, running, baseCovered, }) => {
191
+ const passed = required.filter((c) => reported.get(c) === 'passed');
192
+ const failed = required.filter((c) => reported.get(c) === 'failed');
193
+ const pending = required.filter((c) => reported.get(c) === 'pending');
194
+ const skipped = required.filter((c) => reported.get(c) === 'skipped');
195
+ const unreported = required.filter((c) => !reported.has(c));
196
+ const awaited = baseCovered || unreported.length === required.length;
197
+ const missing = awaited ? unreported : [];
198
+ const notRun = awaited ? [] : unreported;
199
+ return {
200
+ verdict: paused
201
+ ? 'paused'
202
+ : Arr.isNonEmpty(failed)
203
+ ? 'failing'
204
+ : running || Arr.isNonEmpty(pending) || Arr.isNonEmpty(missing)
205
+ ? 'pending'
206
+ : 'passed',
207
+ passed,
208
+ failed,
209
+ pending,
210
+ skipped,
211
+ missing,
212
+ notRun,
213
+ required: required.length,
214
+ };
215
+ };
216
+ //# sourceMappingURL=checks.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checks.mjs","sourceR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