@tahminator/pipeline 1.0.105 → 1.0.106

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.
package/README.md CHANGED
@@ -357,6 +357,14 @@ await client.sendPrMessage({
357
357
  message: "Deployed and healthy.",
358
358
  });
359
359
 
360
+ // returns the comment previously sent with `key` on this PR, or null if there is none
361
+ const existing = await client.getPrMessage({
362
+ owner: "tahminator",
363
+ repository: "pipeline",
364
+ prId: 123,
365
+ key: "deploy-status",
366
+ });
367
+
360
368
  // uploads files as an artifact of the current workflow run; returns { id, url }
361
369
  // requires the Actions runtime token, which the setup action exposes
362
370
  await client.uploadArtifact({
@@ -107,6 +107,26 @@ export declare class GitHubClient {
107
107
  performed_via_github_app?: import("@octokit/openapi-types").components["schemas"]["nullable-integration"];
108
108
  reactions?: import("@octokit/openapi-types").components["schemas"]["reaction-rollup"];
109
109
  }>;
110
+ /**
111
+ * Returns the comment previously posted by `sendPrMessage` with the same `key` on this PR, or
112
+ * `null` if there is none. The returned `body` still starts with the hidden key marker.
113
+ */
114
+ getPrMessage(...args: Parameters<GitHubPRManager["getPrMessage"]>): Promise<{
115
+ id: number;
116
+ node_id: string;
117
+ url: string;
118
+ body?: string;
119
+ body_text?: string;
120
+ body_html?: string;
121
+ html_url: string;
122
+ user: import("@octokit/openapi-types").components["schemas"]["nullable-simple-user"];
123
+ created_at: string;
124
+ updated_at: string;
125
+ issue_url: string;
126
+ author_association: import("@octokit/openapi-types").components["schemas"]["author-association"];
127
+ performed_via_github_app?: import("@octokit/openapi-types").components["schemas"]["nullable-integration"];
128
+ reactions?: import("@octokit/openapi-types").components["schemas"]["reaction-rollup"];
129
+ } | null>;
110
130
  /**
111
131
  * Replaces the body of an existing PR comment, e.g. one returned by `sendPrMessage`.
112
132
  *
package/dist/gh/client.js CHANGED
@@ -123,6 +123,13 @@ export class GitHubClient {
123
123
  sendPrMessage(...args) {
124
124
  return this.prManager.sendPrMessage(...args);
125
125
  }
126
+ /**
127
+ * Returns the comment previously posted by `sendPrMessage` with the same `key` on this PR, or
128
+ * `null` if there is none. The returned `body` still starts with the hidden key marker.
129
+ */
130
+ getPrMessage(...args) {
131
+ return this.prManager.getPrMessage(...args);
132
+ }
126
133
  /**
127
134
  * Replaces the body of an existing PR comment, e.g. one returned by `sendPrMessage`.
128
135
  *
@@ -124,6 +124,29 @@ export declare class GitHubPRManager {
124
124
  performed_via_github_app?: import("@octokit/openapi-types").components["schemas"]["nullable-integration"];
125
125
  reactions?: import("@octokit/openapi-types").components["schemas"]["reaction-rollup"];
126
126
  }>;
127
+ getPrMessage({ prId, owner, repository, key, }: {
128
+ prId: number;
129
+ owner: string;
130
+ repository: string;
131
+ key: string;
132
+ }): Promise<{
133
+ id: number;
134
+ node_id: string;
135
+ url: string;
136
+ body?: string;
137
+ body_text?: string;
138
+ body_html?: string;
139
+ html_url: string;
140
+ user: import("@octokit/openapi-types").components["schemas"]["nullable-simple-user"];
141
+ created_at: string;
142
+ updated_at: string;
143
+ issue_url: string;
144
+ author_association: import("@octokit/openapi-types").components["schemas"]["author-association"];
145
+ performed_via_github_app?: import("@octokit/openapi-types").components["schemas"]["nullable-integration"];
146
+ reactions?: import("@octokit/openapi-types").components["schemas"]["reaction-rollup"];
147
+ } | null>;
148
+ private getPrMessageMarker;
149
+ private findPrMessage;
127
150
  editPrMessage({ commentId, owner, repository, message, }: {
128
151
  commentId: number;
129
152
  owner: string;
@@ -194,22 +194,21 @@ export class GitHubPRManager {
194
194
  });
195
195
  return data;
196
196
  }
197
- if (!/^[a-zA-Z0-9][a-zA-Z0-9_.:-]*$/.test(key)) {
198
- throw new Error("key must start with a letter or digit and contain only letters, digits, '_', '.', ':' or '-'");
199
- }
200
- const marker = `<!-- pipeline-pr-message:${key} -->`;
197
+ const marker = this.getPrMessageMarker(key);
201
198
  const body = `${marker}\n${message}`;
202
- for await (const { data: comments } of this.client.paginate.iterator(this.client.rest.issues.listComments, { owner, repo: repository, issue_number: prId, per_page: 100 })) {
203
- const existing = comments.find((comment) => comment.user?.type === "Bot" &&
204
- comment.body?.startsWith(`${marker}\n`));
205
- if (existing) {
206
- return this.editPrMessage({
207
- commentId: existing.id,
208
- owner,
209
- repository,
210
- message: body,
211
- });
212
- }
199
+ const existing = await this.findPrMessage({
200
+ prId,
201
+ owner,
202
+ repository,
203
+ marker,
204
+ });
205
+ if (existing) {
206
+ return this.editPrMessage({
207
+ commentId: existing.id,
208
+ owner,
209
+ repository,
210
+ message: body,
211
+ });
213
212
  }
214
213
  const { data } = await this.client.rest.issues.createComment({
215
214
  issue_number: prId,
@@ -219,6 +218,30 @@ export class GitHubPRManager {
219
218
  });
220
219
  return data;
221
220
  }
221
+ async getPrMessage({ prId, owner, repository, key, }) {
222
+ return this.findPrMessage({
223
+ prId,
224
+ owner,
225
+ repository,
226
+ marker: this.getPrMessageMarker(key),
227
+ });
228
+ }
229
+ getPrMessageMarker(key) {
230
+ if (!/^[a-zA-Z0-9][a-zA-Z0-9_.:-]*$/.test(key)) {
231
+ throw new Error("key must start with a letter or digit and contain only letters, digits, '_', '.', ':' or '-'");
232
+ }
233
+ return `<!-- pipeline-pr-message:${key} -->`;
234
+ }
235
+ async findPrMessage({ prId, owner, repository, marker, }) {
236
+ for await (const { data: comments } of this.client.paginate.iterator(this.client.rest.issues.listComments, { owner, repo: repository, issue_number: prId, per_page: 100 })) {
237
+ const existing = comments.find((comment) => comment.user?.type === "Bot" &&
238
+ comment.body?.startsWith(`${marker}\n`));
239
+ if (existing) {
240
+ return existing;
241
+ }
242
+ }
243
+ return null;
244
+ }
222
245
  async editPrMessage({ commentId, owner, repository, message, }) {
223
246
  const { data } = await this.client.rest.issues.updateComment({
224
247
  comment_id: commentId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tahminator/pipeline",
3
- "version": "1.0.105",
3
+ "version": "1.0.106",
4
4
  "description": "A collection of Bun shell scripts that can be re-used in various CICD pipelines.",
5
5
  "author": "Tahmid Ahmed",
6
6
  "repository": {