tslaws 1.3.1 → 1.3.2

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.
@@ -70,6 +70,8 @@ interface ProjectState {
70
70
  lock: Lock | undefined;
71
71
  }
72
72
  export declare function projectState(options: CheckOptions): ProjectState;
73
+ /** The body, cut after its last whole line when it is over the size GitHub takes; the run's summary has it all. */
74
+ export declare function fitComment(body: string): string;
73
75
  /**
74
76
  * Whether `login` has `admin` or `maintain` access: the people who may change tsc-laws.lock by hand or run the merge
75
77
  * job on demand. A bot never counts, and neither does a login whose permission cannot be read.
package/dist/githubCli.js CHANGED
@@ -137,12 +137,31 @@ export function projectState(options) {
137
137
  async function issueComments(api, name, pr) {
138
138
  return all(api, `/repos/${name}/issues/${pr}/comments`);
139
139
  }
140
+ /** Who `GITHUB_TOKEN` writes as: a report job usually has that token, and the `bot` in `github` is the app that writes locks. */
141
+ const actionsBot = 'github-actions[bot]';
142
+ /** The sticky comments under `marker`, oldest first. They only show the report, so either bot may own one; approvals are read by `bot` alone. */
143
+ function stickies(comments, bots, marker) {
144
+ const authors = [...bots, actionsBot];
145
+ return comments.filter((c) => authors.includes(c.user.login) && c.body.startsWith(marker));
146
+ }
147
+ /** The body, cut after its last whole line when it is over the size GitHub takes; the run's summary has it all. */
148
+ export function fitComment(body) {
149
+ const most = 65_536;
150
+ if (Buffer.byteLength(body) <= most)
151
+ return body;
152
+ const note = "\nThe rest does not fit in a comment: see the run's summary.\n";
153
+ const room = Buffer.from(body).subarray(0, most - Buffer.byteLength(note));
154
+ return `${room.subarray(0, room.lastIndexOf(10) + 1).toString('utf8')}${note}`;
155
+ }
156
+ /** Writes the one sticky comment in place, and removes any others an earlier run left under the same marker. */
140
157
  async function upsertSticky(api, name, pr, bots, body, comments, marker) {
141
- const mine = comments.find((c) => bots.includes(c.user.login) && c.body.startsWith(marker));
158
+ const [mine, ...extra] = stickies(comments, bots, marker);
142
159
  if (mine === undefined)
143
160
  await api('POST', `/repos/${name}/issues/${pr}/comments`, { body });
144
161
  else if (mine.body !== body)
145
162
  await api('PATCH', `/repos/${name}/issues/comments/${mine.id}`, { body });
163
+ for (const c of extra)
164
+ await api('DELETE', `/repos/${name}/issues/comments/${c.id}`).catch(() => undefined);
146
165
  }
147
166
  function linkFor(env, sha, project) {
148
167
  const server = env.GITHUB_SERVER_URL ?? 'https://github.com';
@@ -578,16 +597,15 @@ async function report(ctx) {
578
597
  const bots = [...new Set(active.map((a) => a.config.bot))];
579
598
  if (api !== undefined && Number.isInteger(pr) && ctx.flags.has('comment')) {
580
599
  try {
581
- await upsertSticky(api, repo(ctx.env), pr, bots, body, comments, marker);
600
+ await upsertSticky(api, repo(ctx.env), pr, bots, fitComment(body), comments, marker);
582
601
  // A root run's one comment replaces the per-project comments an earlier, per-project workflow left.
583
602
  if (monorepo)
584
603
  for (const { unit } of active) {
585
604
  if (unit.path === rootPath)
586
605
  continue;
587
606
  const old = stickyMarkerFor(unit.path);
588
- for (const c of comments)
589
- if (bots.includes(c.user.login) && c.body.startsWith(old))
590
- await api('DELETE', `/repos/${repo(ctx.env)}/issues/comments/${c.id}`).catch(() => undefined);
607
+ for (const c of stickies(comments, bots, old))
608
+ await api('DELETE', `/repos/${repo(ctx.env)}/issues/comments/${c.id}`).catch(() => undefined);
591
609
  }
592
610
  }
593
611
  catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tslaws",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "description": "Runs and checks `law` declarations compiled by tsc-laws: property tests, SMT proofs, tamper lock.",
5
5
  "bin": {
6
6
  "tslaws": "bin/tslaws.js"
@@ -89,11 +89,11 @@
89
89
  }
90
90
  },
91
91
  "optionalDependencies": {
92
- "tslaws-compiler-darwin-arm64": "1.3.1",
93
- "tslaws-compiler-darwin-x64": "1.3.1",
94
- "tslaws-compiler-linux-arm64-gnu": "1.3.1",
95
- "tslaws-compiler-linux-x64-gnu": "1.3.1",
96
- "tslaws-compiler-win32-x64-msvc": "1.3.1"
92
+ "tslaws-compiler-darwin-arm64": "1.3.2",
93
+ "tslaws-compiler-darwin-x64": "1.3.2",
94
+ "tslaws-compiler-linux-arm64-gnu": "1.3.2",
95
+ "tslaws-compiler-linux-x64-gnu": "1.3.2",
96
+ "tslaws-compiler-win32-x64-msvc": "1.3.2"
97
97
  },
98
98
  "publishConfig": {
99
99
  "access": "public"