@ligeti/step-github-issue 0.0.0-stage → 1.0.1

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 (47) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +74 -2
  3. package/dist/add-label.d.ts +17 -0
  4. package/dist/add-label.d.ts.map +1 -0
  5. package/dist/add-label.js +44 -0
  6. package/dist/add-label.js.map +1 -0
  7. package/dist/client.d.ts +19 -0
  8. package/dist/client.d.ts.map +1 -0
  9. package/dist/client.js +132 -0
  10. package/dist/client.js.map +1 -0
  11. package/dist/comment.d.ts +19 -0
  12. package/dist/comment.d.ts.map +1 -0
  13. package/dist/comment.js +41 -0
  14. package/dist/comment.js.map +1 -0
  15. package/dist/index.d.ts +8 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +10 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/label.d.ts +4 -0
  20. package/dist/label.d.ts.map +1 -0
  21. package/dist/label.js +12 -0
  22. package/dist/label.js.map +1 -0
  23. package/dist/list-labelled.d.ts +25 -0
  24. package/dist/list-labelled.d.ts.map +1 -0
  25. package/dist/list-labelled.js +56 -0
  26. package/dist/list-labelled.js.map +1 -0
  27. package/dist/remove-label.d.ts +17 -0
  28. package/dist/remove-label.d.ts.map +1 -0
  29. package/dist/remove-label.js +55 -0
  30. package/dist/remove-label.js.map +1 -0
  31. package/dist/repository-url.d.ts +14 -0
  32. package/dist/repository-url.d.ts.map +1 -0
  33. package/dist/repository-url.js +51 -0
  34. package/dist/repository-url.js.map +1 -0
  35. package/dist/settings.d.ts +17 -0
  36. package/dist/settings.d.ts.map +1 -0
  37. package/dist/settings.js +50 -0
  38. package/dist/settings.js.map +1 -0
  39. package/dist/url.d.ts +7 -0
  40. package/dist/url.d.ts.map +1 -0
  41. package/dist/url.js +16 -0
  42. package/dist/url.js.map +1 -0
  43. package/dist/view.d.ts +59 -0
  44. package/dist/view.d.ts.map +1 -0
  45. package/dist/view.js +79 -0
  46. package/dist/view.js.map +1 -0
  47. package/package.json +26 -3
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 2026 Viktor "Bika" Nagy
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,75 @@
1
- # Temporary Holding Version
1
+ # @ligeti/step-github-issue
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
+ Reads a GitHub issue through the REST API, adds and removes labels on it, comments on it, and lists a
4
+ repository's open issues carrying a label, as steps addressed by the issue's or the repository's
5
+ github.com web URL. Only github.com is supported: the API base is fixed at `https://api.github.com`
6
+ and GitHub Enterprise Server is out of scope.
7
+
8
+ ## Vocabulary
9
+
10
+ This package says **repository** where the project glossary says project, because GitHub does. An
11
+ **issue** is addressed by its web URL, whose last segment is its number. A **label** is a name:
12
+ GitHub compares label names case-insensitively, so the steps do too.
13
+
14
+ ## Steps
15
+
16
+ | Step | Purpose | Input | Retry |
17
+ | ---------------------------- | -------------------------------------------------- | ------------------------ | ----------------- |
18
+ | `github-issue.view` | Fetches the issue's details. | `issueUrl` | up to 3, 2s apart |
19
+ | `github-issue.add-label` | Adds a label to the issue. | `issueUrl`, `label` | up to 3, 2s apart |
20
+ | `github-issue.remove-label` | Removes a label from the issue. | `issueUrl`, `label` | up to 3, 2s apart |
21
+ | `github-issue.comment` | Posts a comment on the issue. | `issueUrl`, `body` | none |
22
+ | `github-issue.list-labelled` | Lists the repository's open issues with the label. | `repositoryUrl`, `label` | up to 3, 2s apart |
23
+
24
+ `issueUrl` is `https://github.com/<owner>/<repo>/issues/<number>` and `repositoryUrl` is
25
+ `https://github.com/<owner>/<repo>`. Any other host, a port, `http`, a sub-page, a trailing slash, a
26
+ query string or a fragment is rejected, and so is a pull request URL (`/pull/<n>`).
27
+
28
+ `github-issue.view` outputs `number`, `title`, `body` (nullable), `state` (`open` or `closed`), `labels`
29
+ (names), `author` (the author's login) and `htmlUrl`. A URL that names a pull request rather than an issue (GitHub serves both on the issues
30
+ endpoint) throws.
31
+
32
+ `github-issue.add-label` sends `POST /repos/{owner}/{repo}/issues/{number}/labels` with the one label,
33
+ which adds it to the issue's existing labels and creates the label in the repository when it does not
34
+ exist yet -- a typo in `label` creates a new label rather than failing. It outputs the issue's resulting
35
+ `labels` and throws naming the label when the response does not include it. `label` is a trimmed,
36
+ non-blank string without a comma; names are compared case-insensitively.
37
+
38
+ `github-issue.remove-label` sends `DELETE .../labels/{name}` with the name URL-encoded. GitHub answers
39
+ 404 when the issue does not carry the label; the step then reads the issue and succeeds with its labels,
40
+ so removing an absent label is a no-op. A 404 for the issue itself still throws, because that read
41
+ fails too. It throws naming the label when the resulting labels still include it.
42
+
43
+ `github-issue.comment` sends `POST .../comments` and outputs the created comment (`id`, `body`, and any
44
+ further field GitHub returns). Posting a comment is not idempotent, so the step is never retried
45
+ (`maxAttempts: 1`); a worker crash between GitHub accepting the post and the step's checkpoint can
46
+ still repeat it on recovery.
47
+
48
+ `github-issue.list-labelled` sends `GET .../issues` with `state=open`, `labels=<label>` and
49
+ `per_page=100`, following the `Link: <...>; rel="next"` header until it is absent, and outputs
50
+ `{ issues: [{ number, title, issueUrl }] }`. GitHub's issues endpoint also returns pull requests, each
51
+ carrying a `pull_request` key; the step drops them. A next-page link to a host other than the API
52
+ host is refused, so the token is never sent elsewhere. Each `issueUrl` is built as
53
+ `https://github.com/<owner>/<repo>/issues/<number>`, so every other step in the package accepts it.
54
+
55
+ Every step except `github-issue.comment` retries up to 3 times, 2 seconds apart: listing and reading
56
+ change nothing, and adding and removing a label are idempotent. A missing token, an unparsable URL, a
57
+ non-2xx response or a response missing a required field all throw
58
+ ([ADR-0005](../../adr/0005-steps-throw-results-are-for-expected-traffic.md)); the token never appears in
59
+ a thrown message. Requests carry `Authorization: Bearer <token>`, `Accept: application/vnd.github+json`
60
+ and `X-GitHub-Api-Version: 2022-11-28`.
61
+
62
+ ## Environment variables
63
+
64
+ | Variable | Required | Default | Purpose |
65
+ | ----------------------- | -------- | ------------------------ | -------------------------------------------------------------------------------- |
66
+ | `GITHUB_TOKEN` | yes | -- | Bearer token sent to the GitHub REST API. |
67
+ | `LIGETI_GITHUB_API_URL` | no | `https://api.github.com` | API base URL. Test-only: points the steps at `startFakeGitHub()`; do not set it. |
68
+
69
+ `loadGitHubSettings` (`src/settings.ts`) throws naming `GITHUB_TOKEN` when it is unset or blank. A
70
+ fine-grained personal access token needs **Issues: read and write** on the repository; reading an issue
71
+ and listing need only read. The token is the same one the `github-pr` steps use; git does not use it.
72
+
73
+ The REST client is deliberately duplicated from the sibling packages rather than shared:
74
+ [ADR-0001](../../adr/0001-package-boundaries-and-dependency-rules.md) forbids one step package importing
75
+ another.
@@ -0,0 +1,17 @@
1
+ import { z } from "@ligeti/sdk";
2
+ export declare const AddLabelInput: z.ZodObject<{
3
+ issueUrl: z.ZodString;
4
+ label: z.ZodString;
5
+ }, z.core.$strip>;
6
+ export type AddLabelInput = z.infer<typeof AddLabelInput>;
7
+ export declare const AddLabelOutput: z.ZodObject<{
8
+ labels: z.ZodArray<z.ZodString>;
9
+ }, z.core.$strip>;
10
+ export type AddLabelOutput = z.infer<typeof AddLabelOutput>;
11
+ export declare const githubIssueAddLabel: import("@ligeti/sdk").StepDefinition<z.ZodObject<{
12
+ issueUrl: z.ZodString;
13
+ label: z.ZodString;
14
+ }, z.core.$strip>, z.ZodObject<{
15
+ labels: z.ZodArray<z.ZodString>;
16
+ }, z.core.$strip>>;
17
+ //# sourceMappingURL=add-label.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"add-label.d.ts","sourceRoot":"","sources":["../src/add-label.ts"],"names":[],"mappings":"AAEA,OAAO,EAAc,CAAC,EAAE,MAAM,aAAa,CAAC;AAQ5C,eAAO,MAAM,aAAa;;;iBAGxB,CAAC;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AAE1D,eAAO,MAAM,cAAc;;iBAEzB,CAAC;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AAE5D,eAAO,MAAM,mBAAmB;;;;;kBA8B9B,CAAC"}
@@ -0,0 +1,44 @@
1
+ // ABOUTME: github-issue.add-label, the step that adds a label to a GitHub issue via the REST API's labels
2
+ // ABOUTME: endpoint, returning the issue's resulting label names.
3
+ import { defineStep, z } from "@ligeti/sdk";
4
+ import pkg from "../package.json" with { type: "json" };
5
+ import { createGitHubClient } from "./client.js";
6
+ import { Label, sameLabel } from "./label.js";
7
+ import { loadGitHubSettings, GITHUB_ENV_VARS } from "./settings.js";
8
+ import { parseIssueUrl } from "./url.js";
9
+ import { GitHubLabel, IssueUrl } from "./view.js";
10
+ export const AddLabelInput = z.object({
11
+ issueUrl: IssueUrl,
12
+ label: Label,
13
+ });
14
+ export const AddLabelOutput = z.object({
15
+ labels: z.array(z.string()),
16
+ });
17
+ export const githubIssueAddLabel = defineStep({
18
+ name: "github-issue.add-label",
19
+ envVars: GITHUB_ENV_VARS,
20
+ description: "Adds a label to a GitHub issue.",
21
+ package: { name: pkg.name, version: pkg.version },
22
+ input: AddLabelInput,
23
+ output: AddLabelOutput,
24
+ retry: { maxAttempts: 3, intervalSeconds: 2 },
25
+ async run(sctx, input) {
26
+ const settings = loadGitHubSettings();
27
+ const { owner, repo, number } = parseIssueUrl(input.issueUrl);
28
+ const client = createGitHubClient({
29
+ token: settings.token,
30
+ apiUrl: settings.apiUrl,
31
+ owner,
32
+ repo,
33
+ signal: sctx.signal,
34
+ });
35
+ const data = await client.post(`/issues/${String(number)}/labels`, { labels: [input.label] });
36
+ const labels = z.array(GitHubLabel).parse(data);
37
+ if (!labels.some((name) => sameLabel(name, input.label))) {
38
+ throw new Error(`github-issue: POST /issues/${String(number)}/labels succeeded but label "${input.label}" is not ` +
39
+ "on the issue (missing permission?)");
40
+ }
41
+ return { labels };
42
+ },
43
+ });
44
+ //# sourceMapping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M,QAAQ,GAAG,kBAAkB,EAAE,CAAC;QACtC,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,aAAa,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAC9D,MAAM,MAAM,GAAG,kBAAkB,CAAC;YAChC,KAAK,EAAE,QAAQ,CAAC,KAAK;YACrB,MAAM,EAAE,QAAQ,CAAC,MAAM;YACvB,KAAK;YACL,IAAI;YACJ,MAAM,EAAE,IAAI,CAAC,MAAM;SACpB,CAAC,CAAC;QAEH,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,WAAW,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE,MAAM,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAC9F,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAChD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;YACzD,MAAM,IAAI,KAAK,CACb,8BAA8B,MAAM,CAAC,MAAM,CAAC,gCAAgC,KAAK,CAAC,KAAK,WAAW;gBAChG,oCAAoC,CACvC,CAAC;QACJ,CAAC;QACD,OAAO,EAAE,MAAM,EAAE,CAAC;IACpB,CAAC;CACF,CAAC,CAAC"}
@@ -0,0 +1,19 @@
1
+ export declare class GitHubHttpError extends Error {
2
+ readonly status: number;
3
+ constructor(message: string, status: number);
4
+ }
5
+ export interface GitHubClientOptions {
6
+ readonly token: string;
7
+ readonly apiUrl: string;
8
+ readonly owner: string;
9
+ readonly repo: string;
10
+ readonly signal?: AbortSignal;
11
+ }
12
+ export interface GitHubClient {
13
+ get(path: string): Promise<unknown>;
14
+ getAll(path: string, query: Readonly<Record<string, string>>): Promise<unknown[]>;
15
+ post(path: string, body: unknown): Promise<unknown>;
16
+ delete(path: string): Promise<unknown>;
17
+ }
18
+ export declare function createGitHubClient(options: GitHubClientOptions): GitHubClient;
19
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AASA,qBAAa,eAAgB,SAAQ,KAAK;IACxC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAEZ,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;CAK5C;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC/B;AAED,MAAM,WAAW,YAAY;IAC3B,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACpC,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IAClF,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACpD,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACxC;AAkDD,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,mBAAmB,GAAG,YAAY,CAwF7E"}
package/dist/client.js ADDED
@@ -0,0 +1,132 @@
1
+ // ABOUTME: Minimal fetch wrapper around one GitHub repository's REST API: get(), getAll(), post() and delete(), all
2
+ // ABOUTME: sending a bearer token and GitHub's recommended headers, shaping a non-2xx response into a token-free Error.
3
+ const MAX_BODY_SNIPPET = 200;
4
+ const PER_PAGE = 100;
5
+ const MAX_PAGES = 1000;
6
+ const API_VERSION = "2022-11-28";
7
+ const USER_AGENT = "ligeti-step-github-issue";
8
+ export class GitHubHttpError extends Error {
9
+ status;
10
+ constructor(message, status) {
11
+ super(message);
12
+ this.name = "GitHubHttpError";
13
+ this.status = status;
14
+ }
15
+ }
16
+ function snippet(text) {
17
+ const collapsed = text.replace(/\s+/g, " ").trim();
18
+ if (collapsed.length === 0) {
19
+ return undefined;
20
+ }
21
+ return collapsed.length > MAX_BODY_SNIPPET
22
+ ? `${collapsed.slice(0, MAX_BODY_SNIPPET)}...`
23
+ : collapsed;
24
+ }
25
+ function describeErrorBody(body) {
26
+ if (typeof body === "string") {
27
+ return snippet(body);
28
+ }
29
+ if (typeof body !== "object" || body === null) {
30
+ return undefined;
31
+ }
32
+ const message = body.message;
33
+ return typeof message === "string" ? message : undefined;
34
+ }
35
+ async function parseBody(response) {
36
+ const text = await response.text();
37
+ if (text.length === 0) {
38
+ return undefined;
39
+ }
40
+ try {
41
+ return JSON.parse(text);
42
+ }
43
+ catch {
44
+ return text;
45
+ }
46
+ }
47
+ function nextLink(header) {
48
+ if (header === null) {
49
+ return undefined;
50
+ }
51
+ for (const part of header.split(",")) {
52
+ const match = /^\s*<([^>]*)>\s*;\s*rel="next"\s*$/.exec(part);
53
+ if (match?.[1] !== undefined) {
54
+ return match[1];
55
+ }
56
+ }
57
+ return undefined;
58
+ }
59
+ export function createGitHubClient(options) {
60
+ const { token, apiUrl, owner, repo, signal } = options;
61
+ const apiOrigin = new URL(apiUrl).origin;
62
+ const repoPath = `/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}`;
63
+ async function send(method, url, body) {
64
+ const headers = {
65
+ Authorization: `Bearer ${token}`,
66
+ Accept: "application/vnd.github+json",
67
+ "X-GitHub-Api-Version": API_VERSION,
68
+ "User-Agent": USER_AGENT,
69
+ };
70
+ const init = { method, headers };
71
+ if (body !== undefined) {
72
+ headers["Content-Type"] = "application/json";
73
+ init.body = JSON.stringify(body);
74
+ }
75
+ if (signal !== undefined) {
76
+ init.signal = signal;
77
+ }
78
+ const where = `${method} ${url.pathname}`;
79
+ let response;
80
+ try {
81
+ response = await fetch(url, init);
82
+ }
83
+ catch (err) {
84
+ if (err instanceof Error && err.name === "AbortError") {
85
+ throw err;
86
+ }
87
+ throw new Error(`github-issue: ${where} failed`, { cause: err });
88
+ }
89
+ const data = await parseBody(response);
90
+ if (!response.ok) {
91
+ const detail = describeErrorBody(data);
92
+ const suffix = detail !== undefined ? `: ${detail}` : "";
93
+ throw new GitHubHttpError(`github-issue: ${where} returned ${String(response.status)}${suffix}`, response.status);
94
+ }
95
+ return { data, headers: response.headers };
96
+ }
97
+ function repoUrl(path, query = {}) {
98
+ const url = new URL(`${apiUrl}${repoPath}${path}`);
99
+ for (const [key, value] of Object.entries(query)) {
100
+ url.searchParams.set(key, value);
101
+ }
102
+ return url;
103
+ }
104
+ return {
105
+ get: async (path) => (await send("GET", repoUrl(path))).data,
106
+ async getAll(path, query) {
107
+ const results = [];
108
+ let url = repoUrl(path, { ...query, per_page: String(PER_PAGE) });
109
+ let pages = 0;
110
+ while (url !== undefined) {
111
+ pages += 1;
112
+ if (pages > MAX_PAGES) {
113
+ throw new Error(`github-issue: GET ${path} exceeded the ${String(MAX_PAGES)}-page pagination cap`);
114
+ }
115
+ const { data, headers } = await send("GET", url);
116
+ if (!Array.isArray(data)) {
117
+ throw new Error(`github-issue: GET ${path} expected a JSON array response`);
118
+ }
119
+ results.push(...data);
120
+ const next = nextLink(headers.get("link"));
121
+ url = next === undefined ? undefined : new URL(next);
122
+ if (url !== undefined && url.origin !== apiOrigin) {
123
+ throw new Error(`github-issue: GET ${path} paginated to ${url.origin}, which is not the API host`);
124
+ }
125
+ }
126
+ return results;
127
+ },
128
+ post: async (path, body) => (await send("POST", repoUrl(path), body)).data,
129
+ delete: async (path) => (await send("DELETE", repoUrl(path))).data,
130
+ };
131
+ }
132
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,oHAAoH;AACpH,wHAAwH;AAExH,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAC7B,MAAM,QAAQ,GAAG,GAAG,CAAC;AACrB,MAAM,SAAS,GAAG,IAAI,CAAC;AACvB,MAAM,WAAW,GAAG,YAAY,CAAC;AACjC,MAAM,UAAU,GAAG,0BAA0B,CAAC;AAE9C,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAC/B,MAAM,CAAS;IAExB,YAAY,OAAe,EAAE,MAAc;QACzC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAmBD,SAAS,OAAO,CAAC,IAAY;IAC3B,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;IACnD,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC3B,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,SAAS,CAAC,MAAM,GAAG,gBAAgB;QACxC,CAAC,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,gBAAgB,CAAC,KAAK;QAC9C,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC;AAED,SAAS,iBAAiB,CAAC,IAAa;IACtC,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,CAAC;IACD,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QAC9C,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,OAAO,GAAI,I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gBACD,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,MAAM,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;gBACjD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;oBACzB,MAAM,IAAI,KAAK,CAAC,qBAAqB,IAAI,iCAAiC,CAAC,CAAC;gBAC9E,CAAC;gBACD,OAAO,CAAC,IAAI,CAAC,GAAI,IAAkB,CAAC,CAAC;gBACrC,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;gBAC3C,GAAG,GAAG,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC;gBACrD,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;oBAClD,MAAM,IAAI,KAAK,CACb,qBAAqB,IAAI,iBAAiB,GAAG,CAAC,MAAM,6BAA6B,CAClF,CAAC;gBACJ,CAAC;YACH,CAAC;YACD,OAAO,OAAO,CAAC;QACjB,CAAC;QACD,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,MAAM,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI;QAC1E,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,MAAM,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI;KACnE,CAAC;AACJ,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { z } from "@ligeti/sdk";
2
+ export declare const CommentInput: z.ZodObject<{
3
+ issueUrl: z.ZodString;
4
+ body: z.ZodString;
5
+ }, z.core.$strip>;
6
+ export type CommentInput = z.infer<typeof CommentInput>;
7
+ export declare const CommentOutput: z.ZodObject<{
8
+ id: z.ZodNumber;
9
+ body: z.ZodString;
10
+ }, z.core.$loose>;
11
+ export type CommentOutput = z.infer<typeof CommentOutput>;
12
+ export declare const githubIssueComment: import("@ligeti/sdk").StepDefinition<z.ZodObject<{
13
+ issueUrl: z.ZodString;
14
+ body: z.ZodString;
15
+ }, z.core.$strip>, z.ZodObject<{
16
+ id: z.ZodNumber;
17
+ body: z.ZodString;
18
+ }, z.core.$loose>>;
19
+ //# sourceMappingURL=comment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"comment.d.ts","sourceRoot":"","sources":["../src/comment.ts"],"names":[],"mappings":"AAEA,OAAO,EAAc,CAAC,EAAE,MAAM,aAAa,CAAC;AAO5C,eAAO,MAAM,YAAY;;;iBAGvB,CAAC;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AAExD,eAAO,MAAM,aAAa;;;iBAKhB,CAAC;AACX,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AAE1D,eAAO,MAAM,kBAAkB;;;;;;kBAuB7B,CAAC"}
@@ -0,0 +1,41 @@
1
+ // ABOUTME: github-issue.comment, the step that posts a comment on a GitHub issue via the REST API's comments
2
+ // ABOUTME: endpoint and returns the created comment.
3
+ import { defineStep, z } from "@ligeti/sdk";
4
+ import pkg from "../package.json" with { type: "json" };
5
+ import { createGitHubClient } from "./client.js";
6
+ import { loadGitHubSettings, GITHUB_ENV_VARS } from "./settings.js";
7
+ import { parseIssueUrl } from "./url.js";
8
+ import { IssueUrl } from "./view.js";
9
+ export const CommentInput = z.object({
10
+ issueUrl: IssueUrl,
11
+ body: z.string().trim().min(1, "comment body must not be empty or whitespace-only"),
12
+ });
13
+ export const CommentOutput = z
14
+ .object({
15
+ id: z.number(),
16
+ body: z.string(),
17
+ })
18
+ .loose();
19
+ export const githubIssueComment = defineStep({
20
+ name: "github-issue.comment",
21
+ envVars: GITHUB_ENV_VARS,
22
+ description: "Posts a comment on a GitHub issue.",
23
+ package: { name: pkg.name, version: pkg.version },
24
+ input: CommentInput,
25
+ output: CommentOutput,
26
+ retry: { maxAttempts: 1 },
27
+ async run(sctx, input) {
28
+ const settings = loadGitHubSettings();
29
+ const { owner, repo, number } = parseIssueUrl(input.issueUrl);
30
+ const client = createGitHubClient({
31
+ token: settings.token,
32
+ apiUrl: settings.apiUrl,
33
+ owner,
34
+ repo,
35
+ signal: sctx.signal,
36
+ });
37
+ const data = await client.post(`/issues/${String(number)}/comments`, { body: input.body });
38
+ return CommentOutput.parse(data);
39
+ },
40
+ });
41
+ //# sourceMappingURL=comment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"comment.js","sourceRoot":"","sources":["../src/comment.ts"],"names":[],"mappings":"AAAA,6GAA6G;AAC7G,qDAAqD;AACrD,OAAO,EAAE,UAAU,EAAE,CAAC,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,GAAG,MAAM,iBAAiB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,QAAQ,EAAE,QAAQ;IAClB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,mDAAmD,CAAC;CACpF,CAAC,CAAC;AAGH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC;KAC3B,MAAM,CAAC;IACN,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;IACd,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;CACjB,CAAC;KACD,KAAK,EAAE,CAAC;AAGX,MAAM,CAAC,MAAM,kBAAkB,GAAG,UAAU,CAAC;IAC3C,IAAI,EAAE,sBAAsB;IAC5B,OAAO,EAAE,eAAe;IACxB,WAAW,EAAE,oCAAoC;IACjD,OAAO,EAAE,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE;IACjD,KAAK,EAAE,YAAY;IACnB,MAAM,EAAE,aAAa;IACrB,KAAK,EAAE,EAAE,WAAW,EAAE,CAAC,EAAE;IAEzB,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK;QACnB,MAAM,QAAQ,GAAG,kBAAkB,EAAE,CAAC;QACtC,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,aAAa,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAC9D,MAAM,MAAM,GAAG,kBAAkB,CAAC;YAChC,KAAK,EAAE,QAAQ,CAAC,KAAK;YACrB,MAAM,EAAE,QAAQ,CAAC,MAAM;YACvB,KAAK;YACL,IAAI;YACJ,MAAM,EAAE,IAAI,CAAC,MAAM;SACpB,CAAC,CAAC;QAEH,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,WAAW,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;QAC3F,OAAO,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;CACF,CAAC,CAAC"}
@@ -0,0 +1,8 @@
1
+ export { githubIssueView, IssueUrl, IssueViewInput, IssueView } from "./view.js";
2
+ export { githubIssueAddLabel, AddLabelInput, AddLabelOutput } from "./add-label.js";
3
+ export { githubIssueComment, CommentInput, CommentOutput } from "./comment.js";
4
+ export { githubIssueRemoveLabel, RemoveLabelInput, RemoveLabelOutput } from "./remove-label.js";
5
+ export { githubIssueListLabelled, ListLabelledInput, ListLabelledOutput } from "./list-labelled.js";
6
+ export { parseIssueUrl, type IssueUrlParts } from "./url.js";
7
+ export { parseRepositoryUrl, RepositoryUrl, type RepositoryUrlParts } from "./repository-url.js";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACjF,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACpF,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC/E,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAChG,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACpG,OAAO,EAAE,aAAa,EAAE,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,KAAK,kBAAkB,EAAE,MAAM,qBAAqB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ // ABOUTME: Public entry point of @ligeti/step-github-issue: the github-issue.view, .add-label, .remove-label,
2
+ // ABOUTME: .comment and .list-labelled steps, their schemas, and the issue and repository URL parsers.
3
+ export { githubIssueView, IssueUrl, IssueViewInput, IssueView } from "./view.js";
4
+ export { githubIssueAddLabel, AddLabelInput, AddLabelOutput } from "./add-label.js";
5
+ export { githubIssueComment, CommentInput, CommentOutput } from "./comment.js";
6
+ export { githubIssueRemoveLabel, RemoveLabelInput, RemoveLabelOutput } from "./remove-label.js";
7
+ export { githubIssueListLabelled, ListLabelledInput, ListLabelledOutput } from "./list-labelled.js";
8
+ export { parseIssueUrl } from "./url.js";
9
+ export { parseRepositoryUrl, RepositoryUrl } from "./repository-url.js";
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8GAA8G;AAC9G,uGAAuG;AACvG,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACjF,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACpF,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC/E,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAChG,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACpG,OAAO,EAAE,aAAa,EAAsB,MAAM,UAAU,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAA2B,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { z } from "@ligeti/sdk";
2
+ export declare const Label: z.ZodString;
3
+ export declare function sameLabel(a: string, b: string): boolean;
4
+ //# sourceMappingURL=label.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"label.d.ts","sourceRoot":"","sources":["../src/label.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,aAAa,CAAC;AAEhC,eAAO,MAAM,KAAK,aAI6B,CAAC;AAEhD,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAEvD"}
package/dist/label.js ADDED
@@ -0,0 +1,12 @@
1
+ // ABOUTME: The Zod schema of a GitHub label name as the label steps accept it: trimmed, non-blank and
2
+ // ABOUTME: comma-free, because the issue list endpoint reads a comma as a separator between labels.
3
+ import { z } from "@ligeti/sdk";
4
+ export const Label = z
5
+ .string()
6
+ .trim()
7
+ .min(1)
8
+ .regex(/^[^,]+$/, "must not contain a comma");
9
+ export function sameLabel(a, b) {
10
+ return a.toLowerCase() === b.toLowerCase();
11
+ }
12
+ //# sourceMappingURL=label.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"label.js","sourceRoot":"","sources":["../src/label.ts"],"names":[],"mappings":"AAAA,sGAAsG;AACtG,oGAAoG;AACpG,OAAO,EAAE,CAAC,EAAE,MAAM,aAAa,CAAC;AAEhC,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC;KACnB,MAAM,EAAE;KACR,IAAI,EAAE;KACN,GAAG,CAAC,CAAC,CAAC;KACN,KAAK,CAAC,SAAS,EAAE,0BAA0B,CAAC,CAAC;AAEhD,MAAM,UAAU,SAAS,CAAC,CAAS,EAAE,CAAS;IAC5C,OAAO,CAAC,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC;AAC7C,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { z } from "@ligeti/sdk";
2
+ export declare const ListLabelledInput: z.ZodObject<{
3
+ repositoryUrl: z.ZodString;
4
+ label: z.ZodString;
5
+ }, z.core.$strip>;
6
+ export type ListLabelledInput = z.infer<typeof ListLabelledInput>;
7
+ export declare const ListLabelledOutput: z.ZodObject<{
8
+ issues: z.ZodArray<z.ZodObject<{
9
+ number: z.ZodNumber;
10
+ title: z.ZodString;
11
+ issueUrl: z.ZodString;
12
+ }, z.core.$strip>>;
13
+ }, z.core.$strip>;
14
+ export type ListLabelledOutput = z.infer<typeof ListLabelledOutput>;
15
+ export declare const githubIssueListLabelled: import("@ligeti/sdk").StepDefinition<z.ZodObject<{
16
+ repositoryUrl: z.ZodString;
17
+ label: z.ZodString;
18
+ }, z.core.$strip>, z.ZodObject<{
19
+ issues: z.ZodArray<z.ZodObject<{
20
+ number: z.ZodNumber;
21
+ title: z.ZodString;
22
+ issueUrl: z.ZodString;
23
+ }, z.core.$strip>>;
24
+ }, z.core.$strip>>;
25
+ //# sourceMappingURL=list-labelled.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"list-labelled.d.ts","sourceRoot":"","sources":["../src/list-labelled.ts"],"names":[],"mappings":"AAEA,OAAO,EAAc,CAAC,EAAE,MAAM,aAAa,CAAC;AAQ5C,eAAO,MAAM,iBAAiB;;;iBAG5B,CAAC;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAElE,eAAO,MAAM,kBAAkB;;;;;;iBAQ7B,CAAC;AACH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAQpE,eAAO,MAAM,uBAAuB;;;;;;;;;kBA+BlC,CAAC"}
@@ -0,0 +1,56 @@
1
+ // ABOUTME: github-issue.list-labelled, the step that lists a GitHub repository's open issues carrying one
2
+ // ABOUTME: label, skipping pull requests and following Link pagination, as issue URLs other steps accept.
3
+ import { defineStep, z } from "@ligeti/sdk";
4
+ import pkg from "../package.json" with { type: "json" };
5
+ import { createGitHubClient } from "./client.js";
6
+ import { Label } from "./label.js";
7
+ import { RepositoryUrl, parseRepositoryUrl } from "./repository-url.js";
8
+ import { loadGitHubSettings, GITHUB_ENV_VARS } from "./settings.js";
9
+ import { IssueUrl } from "./view.js";
10
+ export const ListLabelledInput = z.object({
11
+ repositoryUrl: RepositoryUrl,
12
+ label: Label,
13
+ });
14
+ export const ListLabelledOutput = z.object({
15
+ issues: z.array(z.object({
16
+ number: z.number(),
17
+ title: z.string(),
18
+ issueUrl: IssueUrl,
19
+ })),
20
+ });
21
+ const ListedItem = z.object({
22
+ number: z.number(),
23
+ title: z.string(),
24
+ pull_request: z.unknown().optional(),
25
+ });
26
+ export const githubIssueListLabelled = defineStep({
27
+ name: "github-issue.list-labelled",
28
+ envVars: GITHUB_ENV_VARS,
29
+ description: "Lists a GitHub repository's open issues that carry a label.",
30
+ package: { name: pkg.name, version: pkg.version },
31
+ input: ListLabelledInput,
32
+ output: ListLabelledOutput,
33
+ retry: { maxAttempts: 3, intervalSeconds: 2 },
34
+ async run(sctx, input) {
35
+ const settings = loadGitHubSettings();
36
+ const { owner, repo } = parseRepositoryUrl(input.repositoryUrl);
37
+ const client = createGitHubClient({
38
+ token: settings.token,
39
+ apiUrl: settings.apiUrl,
40
+ owner,
41
+ repo,
42
+ signal: sctx.signal,
43
+ });
44
+ const items = await client.getAll("/issues", { state: "open", labels: input.label });
45
+ const issues = items
46
+ .map((item) => ListedItem.parse(item))
47
+ .filter((item) => item.pull_request === undefined)
48
+ .map(({ number, title }) => ({
49
+ number,
50
+ title,
51
+ issueUrl: `https://github.com/${owner}/${repo}/issues/${String(number)}`,
52
+ }));
53
+ return ListLabelledOutput.parse({ issues });
54
+ },
55
+ });
56
+ //# sourceMappingURL=list-labelled.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"list-labelled.js","sourceRoot":"","sources":["../src/list-labelled.ts"],"names":[],"mappings":"AAAA,0GAA0G;AAC1G,0GAA0G;AAC1G,OAAO,EAAE,UAAU,EAAE,CAAC,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,GAAG,MAAM,iBAAiB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,aAAa,EAAE,aAAa;IAC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;SACpB,CAAC,CAAC;QAEH,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;QACrF,MAAM,MAAM,GAAG,KAAK;aACjB,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;aACrC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,YAAY,KAAK,SAAS,CAAC;aACjD,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC;YAC3B,MAAM;YACN,KAAK;YACL,QAAQ,EAAE,sBAAsB,KAAK,IAAI,IAAI,WAAW,MAAM,CAAC,MAAM,CAAC,EAAE;SACzE,CAAC,CAAC,CAAC;QACN,OAAO,kBAAkB,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;IAC9C,CAAC;CACF,CAAC,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { z } from "@ligeti/sdk";
2
+ export declare const RemoveLabelInput: z.ZodObject<{
3
+ issueUrl: z.ZodString;
4
+ label: z.ZodString;
5
+ }, z.core.$strip>;
6
+ export type RemoveLabelInput = z.infer<typeof RemoveLabelInput>;
7
+ export declare const RemoveLabelOutput: z.ZodObject<{
8
+ labels: z.ZodArray<z.ZodString>;
9
+ }, z.core.$strip>;
10
+ export type RemoveLabelOutput = z.infer<typeof RemoveLabelOutput>;
11
+ export declare const githubIssueRemoveLabel: import("@ligeti/sdk").StepDefinition<z.ZodObject<{
12
+ issueUrl: z.ZodString;
13
+ label: z.ZodString;
14
+ }, z.core.$strip>, z.ZodObject<{
15
+ labels: z.ZodArray<z.ZodString>;
16
+ }, z.core.$strip>>;
17
+ //# sourceMappingURL=remove-label.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remove-label.d.ts","sourceRoot":"","sources":["../src/remove-label.ts"],"names":[],"mappings":"AAEA,OAAO,EAAc,CAAC,EAAE,MAAM,aAAa,CAAC;AAQ5C,eAAO,MAAM,gBAAgB;;;iBAG3B,CAAC;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAEhE,eAAO,MAAM,iBAAiB;;iBAE5B,CAAC;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAIlE,eAAO,MAAM,sBAAsB;;;;;kBAwCjC,CAAC"}
@@ -0,0 +1,55 @@
1
+ // ABOUTME: github-issue.remove-label, the step that removes a label from a GitHub issue via the REST API,
2
+ // ABOUTME: succeeding when the issue does not carry it, and returning the issue's resulting label names.
3
+ import { defineStep, z } from "@ligeti/sdk";
4
+ import pkg from "../package.json" with { type: "json" };
5
+ import { createGitHubClient, GitHubHttpError } from "./client.js";
6
+ import { Label, sameLabel } from "./label.js";
7
+ import { loadGitHubSettings, GITHUB_ENV_VARS } from "./settings.js";
8
+ import { parseIssueUrl } from "./url.js";
9
+ import { GitHubLabel, IssueUrl } from "./view.js";
10
+ export const RemoveLabelInput = z.object({
11
+ issueUrl: IssueUrl,
12
+ label: Label,
13
+ });
14
+ export const RemoveLabelOutput = z.object({
15
+ labels: z.array(z.string()),
16
+ });
17
+ const IssueLabels = z.object({ labels: z.array(GitHubLabel) });
18
+ export const githubIssueRemoveLabel = defineStep({
19
+ name: "github-issue.remove-label",
20
+ envVars: GITHUB_ENV_VARS,
21
+ description: "Removes a label from a GitHub issue.",
22
+ package: { name: pkg.name, version: pkg.version },
23
+ input: RemoveLabelInput,
24
+ output: RemoveLabelOutput,
25
+ retry: { maxAttempts: 3, intervalSeconds: 2 },
26
+ async run(sctx, input) {
27
+ const settings = loadGitHubSettings();
28
+ const { owner, repo, number } = parseIssueUrl(input.issueUrl);
29
+ const client = createGitHubClient({
30
+ token: settings.token,
31
+ apiUrl: settings.apiUrl,
32
+ owner,
33
+ repo,
34
+ signal: sctx.signal,
35
+ });
36
+ const issuePath = `/issues/${String(number)}`;
37
+ let labels;
38
+ try {
39
+ const data = await client.delete(`${issuePath}/labels/${encodeURIComponent(input.label)}`);
40
+ labels = z.array(GitHubLabel).parse(data);
41
+ }
42
+ catch (err) {
43
+ if (!(err instanceof GitHubHttpError) || err.status !== 404) {
44
+ throw err;
45
+ }
46
+ labels = IssueLabels.parse(await client.get(issuePath)).labels;
47
+ }
48
+ if (labels.some((name) => sameLabel(name, input.label))) {
49
+ throw new Error(`github-issue: DELETE ${issuePath}/labels/... succeeded but label "${input.label}" is still ` +
50
+ "on the issue (missing permission?)");
51
+ }
52
+ return { labels };
53
+ },
54
+ });
55
+ //# sourceMappingURL=remove-label.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remove-label.js","sourceRoot":"","sources":["../src/remove-label.ts"],"names":[],"mappings":"AAAA,0GAA0G;AAC1G,yGAAyG;AACzG,OAAO,EAAE,UAAU,EAAE,CAAC,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,GAAG,MAAM,iBAAiB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAElD,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,QAAQ,EAAE,QAAQ;IAClB,KAAK,EAAE,KAAK;CACb,CAAC,CAAC;AAGH,MAAM,CAAC,MAAM,iBAAiB,GAAG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G,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC5C,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,CAAC,CAAC,GAAG,YAAY,eAAe,CAAC,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;gBAC5D,MAAM,GAAG,CAAC;YACZ,CAAC;YACD,MAAM,GAAG,WAAW,CAAC,KAAK,CAAC,MAAM,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC;QACjE,CAAC;QAED,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;YACxD,MAAM,IAAI,KAAK,CACb,wBAAwB,SAAS,oCAAoC,KAAK,CAAC,KAAK,aAAa;gBAC3F,oCAAoC,CACvC,CAAC;QACJ,CAAC;QACD,OAAO,EAAE,MAAM,EAAE,CAAC;IACpB,CAAC;CACF,CAAC,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { z } from "@ligeti/sdk";
2
+ export declare const GITHUB_HOST = "github.com";
3
+ export interface RepositoryUrlParts {
4
+ readonly owner: string;
5
+ readonly repo: string;
6
+ }
7
+ export declare function parseGitHubUrl(url: string, kind: string): {
8
+ segments: string[];
9
+ };
10
+ export declare function ownerAndRepo(url: string, kind: string, segments: string[]): RepositoryUrlParts;
11
+ export declare function parseRepositoryUrl(url: string): RepositoryUrlParts;
12
+ export declare const RepositoryUrl: z.ZodString;
13
+ export type RepositoryUrl = z.infer<typeof RepositoryUrl>;
14
+ //# sourceMappingURL=repository-url.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repository-url.d.ts","sourceRoot":"","sources":["../src/repository-url.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,aAAa,CAAC;AAEhC,eAAO,MAAM,WAAW,eAAe,CAAC;AAExC,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAID,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG;IAAE,QAAQ,EAAE,MAAM,EAAE,CAAA;CAAE,CAiBhF;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,kBAAkB,CAM9F;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,kBAAkB,CAQlE;AAED,eAAO,MAAM,aAAa,aAavB,CAAC;AACJ,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC"}
@@ -0,0 +1,51 @@
1
+ // ABOUTME: Parses a github.com repository URL, e.g. https://github.com/owner/repo, into the owner and repository
2
+ // ABOUTME: name the REST API needs, and exposes it as the RepositoryUrl schema.
3
+ import { z } from "@ligeti/sdk";
4
+ export const GITHUB_HOST = "github.com";
5
+ const NAME = /^[A-Za-z0-9._-]+$/;
6
+ export function parseGitHubUrl(url, kind) {
7
+ let parsed;
8
+ try {
9
+ parsed = new URL(url);
10
+ }
11
+ catch (err) {
12
+ throw new Error(`invalid ${kind} URL: "${url}" is not a valid URL`, { cause: err });
13
+ }
14
+ if (parsed.protocol !== "https:" || parsed.hostname !== GITHUB_HOST || parsed.port !== "") {
15
+ throw new Error(`invalid ${kind} URL: "${url}" must be an https://${GITHUB_HOST} URL`);
16
+ }
17
+ if (parsed.search.length > 0 || parsed.hash.length > 0) {
18
+ throw new Error(`invalid ${kind} URL: "${url}" must not include a query string or fragment`);
19
+ }
20
+ if (parsed.pathname.endsWith("/")) {
21
+ throw new Error(`invalid ${kind} URL: "${url}" must not end in a slash`);
22
+ }
23
+ return { segments: parsed.pathname.slice(1).split("/") };
24
+ }
25
+ export function ownerAndRepo(url, kind, segments) {
26
+ const [owner, repo] = segments;
27
+ if (owner === undefined || repo === undefined || !NAME.test(owner) || !NAME.test(repo)) {
28
+ throw new Error(`invalid ${kind} URL: "${url}" must have an owner and a repository name`);
29
+ }
30
+ return { owner, repo };
31
+ }
32
+ export function parseRepositoryUrl(url) {
33
+ const { segments } = parseGitHubUrl(url, "repository");
34
+ if (segments.length !== 2) {
35
+ throw new Error(`invalid repository URL: "${url}" must be the repository's own URL, not a sub-page`);
36
+ }
37
+ return ownerAndRepo(url, "repository", segments);
38
+ }
39
+ export const RepositoryUrl = z
40
+ .string()
41
+ .min(1)
42
+ .refine((value) => {
43
+ try {
44
+ parseRepositoryUrl(value);
45
+ return true;
46
+ }
47
+ catch {
48
+ return false;
49
+ }
50
+ }, { message: "must be a full GitHub repository URL, e.g. https://github.com/owner/repo" });
51
+ //# sourceMappingURL=repository-url.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repository-url.js","sourceRoot":"","sources":["../src/repository-url.ts"],"names":[],"mappings":"AAAA,iHAAiH;AACjH,gFAAgF;AAChF,OAAO,EAAE,CAAC,EAAE,MAAM,aAAa,CAAC;AAEhC,MAAM,CAAC,MAAM,WAAW,GAAG,YAAY,CAAC;AAOxC,MAAM,IAAI,GAAG,mBAAmB,CAAC;AAEjC,MAAM,UAAU,cAAc,CAAC,GAAW,EAAE,IAAY;IACtD,IAAI,MAAW,CAAC;IAChB,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,WAAW,IAAI,UAAU,GAAG,sBAAsB,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;IACtF,CAAC;IACD,IAAI,MAAM,CAAC,QAAQ,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,KAAK,WAAW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,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CACb,4BAA4B,GAAG,oDAAoD,CACpF,CAAC;IACJ,CAAC;IACD,OAAO,YAAY,CAAC,GAAG,EAAE,YAAY,EAAE,QAAQ,CAAC,CAAC;AACnD,CAAC;AAED,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC;KAC3B,MAAM,EAAE;KACR,GAAG,CAAC,CAAC,CAAC;KACN,MAAM,CACL,CAAC,KAAK,EAAE,EAAE;IACR,IAAI,CAAC;QACH,kBAAkB,CAAC,KAAK,CAAC,CAAC;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC,EACD,EAAE,OAAO,EAAE,0EAA0E,EAAE,CACxF,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { z } from "@ligeti/sdk";
2
+ export declare const GITHUB_ENV_VARS: {
3
+ required: string[];
4
+ optional: string[];
5
+ public: string[];
6
+ };
7
+ export declare const DEFAULT_API_URL = "https://api.github.com";
8
+ export declare const settingsSchema: z.ZodObject<{
9
+ GITHUB_TOKEN: z.ZodOptional<z.ZodString>;
10
+ LIGETI_GITHUB_API_URL: z.ZodOptional<z.ZodString>;
11
+ }, z.core.$strip>;
12
+ export interface GitHubSettings {
13
+ readonly token: string;
14
+ readonly apiUrl: string;
15
+ }
16
+ export declare function loadGitHubSettings(env?: NodeJS.ProcessEnv): GitHubSettings;
17
+ //# sourceMappingURL=settings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../src/settings.ts"],"names":[],"mappings":"AAEA,OAAO,EAAwB,CAAC,EAA2B,MAAM,aAAa,CAAC;AAE/E,eAAO,MAAM,eAAe;;;;CAIE,CAAC;AAE/B,eAAO,MAAM,eAAe,2BAA2B,CAAC;AAExD,eAAO,MAAM,cAAc;;;iBAGzB,CAAC;AAEH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,wBAAgB,kBAAkB,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,cAAc,CAevF"}
@@ -0,0 +1,50 @@
1
+ // ABOUTME: @ligeti/step-github-issue settings loaded from the environment: the bearer token sent to the GitHub
2
+ // ABOUTME: REST API, read from GITHUB_TOKEN, and the API base URL, fixed unless a test points it at a fake.
3
+ import { defineSettingsSchema, z } from "@ligeti/sdk";
4
+ export const GITHUB_ENV_VARS = {
5
+ required: ["GITHUB_TOKEN"],
6
+ optional: ["LIGETI_GITHUB_API_URL"],
7
+ public: ["LIGETI_GITHUB_API_URL"],
8
+ };
9
+ export const DEFAULT_API_URL = "https://api.github.com";
10
+ export const settingsSchema = defineSettingsSchema({
11
+ GITHUB_TOKEN: z.string().optional().meta({ sensitivity: "secret" }),
12
+ LIGETI_GITHUB_API_URL: z.string().optional().meta({ sensitivity: "public" }),
13
+ });
14
+ export function loadGitHubSettings(env = process.env) {
15
+ const result = settingsSchema.safeParse(env);
16
+ if (!result.success) {
17
+ const issues = result.error.issues
18
+ .map((issue) => ` - ${issue.path.join(".")}: ${issue.message}`)
19
+ .join("\n");
20
+ throw new Error(`invalid github-issue step environment:\n${issues}`);
21
+ }
22
+ const token = nonBlank(result.data.GITHUB_TOKEN);
23
+ if (token === undefined) {
24
+ throw new Error("github-issue: no GitHub access token found -- set GITHUB_TOKEN");
25
+ }
26
+ return { token, apiUrl: apiUrlFrom(result.data.LIGETI_GITHUB_API_URL) };
27
+ }
28
+ function apiUrlFrom(raw) {
29
+ const value = nonBlank(raw);
30
+ if (value === undefined) {
31
+ return DEFAULT_API_URL;
32
+ }
33
+ let parsed;
34
+ try {
35
+ parsed = new URL(value);
36
+ }
37
+ catch (err) {
38
+ throw new Error(`github-issue: LIGETI_GITHUB_API_URL "${value}" is not a valid URL`, {
39
+ cause: err,
40
+ });
41
+ }
42
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
43
+ throw new Error(`github-issue: LIGETI_GITHUB_API_URL "${value}" must use http or https, got "${parsed.protocol}"`);
44
+ }
45
+ return value.replace(/\/+$/, "");
46
+ }
47
+ function nonBlank(value) {
48
+ return value !== undefined && value.trim().length > 0 ? value.trim() : undefined;
49
+ }
50
+ //# sourceMappingURL=settings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settings.js","sourceRoot":"","sources":["../src/settings.ts"],"names":[],"mappings":"AAAA,+GAA+G;AAC/G,4GAA4G;AAC5G,OAAO,EAAE,oBAAoB,EAAE,CAAC,EAA2B,MAAM,aAAa,CAAC;AAE/E,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,QAAQ,EAAE,CAAC,cAAc,CAAC;IAC1B,QAAQ,EAAE,CAAC,uBAAuB,CAAC;IACnC,MAAM,EAAE,CAAC,uBAAuB,CAAC;CACL,CAAC;AAE/B,MAAM,CAAC,MAAM,eAAe,GAAG,wBAAwB,CAAC;AAExD,MAAM,CAAC,MAAM,cAAc,GAAG,oBAAoB,CAAC;IACjD,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC;IACnE,qBAAqB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC;CAC7E,CAAC,CAAC;AAOH,MAAM,UAAU,kBAAkB,CAAC,MAAyB,OAAO,CAAC,GAAG;IACrE,MAAM,MAAM,GAAG,cAAc,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IAC7C,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM;aAC/B,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,C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AAI,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AACnF,CAAC"}
package/dist/url.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ export interface IssueUrlParts {
2
+ readonly owner: string;
3
+ readonly repo: string;
4
+ readonly number: number;
5
+ }
6
+ export declare function parseIssueUrl(url: string): IssueUrlParts;
7
+ //# sourceMappingURL=url.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../src/url.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,CAaxD"}
package/dist/url.js ADDED
@@ -0,0 +1,16 @@
1
+ // ABOUTME: Parses a github.com issue URL, https://github.com/<owner>/<repo>/issues/<number>, into the
2
+ // ABOUTME: owner, repository and issue number needed to call the REST API.
3
+ import { ownerAndRepo, parseGitHubUrl } from "./repository-url.js";
4
+ export function parseIssueUrl(url) {
5
+ const { segments } = parseGitHubUrl(url, "issue");
6
+ const [, , marker, numberSegment, ...rest] = segments;
7
+ if (segments.length !== 4 || marker !== "issues" || rest.length > 0) {
8
+ throw new Error(`invalid issue URL: "${url}" must look like https://github.com/owner/repo/issues/1`);
9
+ }
10
+ if (numberSegment === undefined || !/^[1-9][0-9]*$/.test(numberSegment)) {
11
+ throw new Error(`invalid issue URL: "${url}" does not end in an issue number`);
12
+ }
13
+ const { owner, repo } = ownerAndRepo(url, "issue", segments);
14
+ return { owner, repo, number: Number.parseInt(numberSegment, 10) };
15
+ }
16
+ //# sourceMappingURL=url.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url.js","sourceRoot":"","sources":["../src/url.ts"],"names":[],"mappings":"AAAA,sGAAsG;AACtG,2EAA2E;AAC3E,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAQnE,MAAM,UAAU,aAAa,CAAC,GAAW;IACvC,MAAM,EAAE,QAAQ,EAAE,GAAG,cAAc,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAClD,MAAM,CAAC,EAAE,AAAD,EAAG,MAAM,EAAE,aAAa,EAAE,GAAG,IAAI,CAAC,GAAG,QAAQ,CAAC;IACtD,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,IAAI,MAAM,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACpE,MAAM,IAAI,KAAK,CACb,uBAAuB,GAAG,yDAAyD,CACpF,CAAC;IACJ,CAAC;IACD,IAAI,aAAa,KAAK,SAAS,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC;QACxE,MAAM,IAAI,KAAK,CAAC,uBAAuB,GAAG,mCAAmC,CAAC,CAAC;IACjF,CAAC;IACD,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,YAAY,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;IAC7D,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,aAAa,EAAE,EAAE,CAAC,EAAE,CAAC;AACrE,CAAC"}
package/dist/view.d.ts ADDED
@@ -0,0 +1,59 @@
1
+ import { z } from "@ligeti/sdk";
2
+ export declare const IssueUrl: z.ZodString;
3
+ export type IssueUrl = z.infer<typeof IssueUrl>;
4
+ export declare const IssueViewInput: z.ZodObject<{
5
+ issueUrl: z.ZodString;
6
+ }, z.core.$strip>;
7
+ export type IssueViewInput = z.infer<typeof IssueViewInput>;
8
+ export declare const GitHubLabel: z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodObject<{
9
+ name: z.ZodString;
10
+ }, z.core.$strip>, z.ZodTransform<string, {
11
+ name: string;
12
+ }>>]>;
13
+ export declare const GitHubIssue: z.ZodObject<{
14
+ number: z.ZodNumber;
15
+ title: z.ZodString;
16
+ body: z.ZodNullable<z.ZodString>;
17
+ state: z.ZodEnum<{
18
+ open: "open";
19
+ closed: "closed";
20
+ }>;
21
+ pull_request: z.ZodOptional<z.ZodUnknown>;
22
+ labels: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodObject<{
23
+ name: z.ZodString;
24
+ }, z.core.$strip>, z.ZodTransform<string, {
25
+ name: string;
26
+ }>>]>>;
27
+ user: z.ZodObject<{
28
+ login: z.ZodString;
29
+ }, z.core.$strip>;
30
+ html_url: z.ZodString;
31
+ }, z.core.$strip>;
32
+ export declare const IssueView: z.ZodObject<{
33
+ number: z.ZodNumber;
34
+ title: z.ZodString;
35
+ body: z.ZodNullable<z.ZodString>;
36
+ state: z.ZodEnum<{
37
+ open: "open";
38
+ closed: "closed";
39
+ }>;
40
+ labels: z.ZodArray<z.ZodString>;
41
+ author: z.ZodString;
42
+ htmlUrl: z.ZodString;
43
+ }, z.core.$strip>;
44
+ export type IssueView = z.infer<typeof IssueView>;
45
+ export declare const githubIssueView: import("@ligeti/sdk").StepDefinition<z.ZodObject<{
46
+ issueUrl: z.ZodString;
47
+ }, z.core.$strip>, z.ZodObject<{
48
+ number: z.ZodNumber;
49
+ title: z.ZodString;
50
+ body: z.ZodNullable<z.ZodString>;
51
+ state: z.ZodEnum<{
52
+ open: "open";
53
+ closed: "closed";
54
+ }>;
55
+ labels: z.ZodArray<z.ZodString>;
56
+ author: z.ZodString;
57
+ htmlUrl: z.ZodString;
58
+ }, z.core.$strip>>;
59
+ //# sourceMappingURL=view.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"view.d.ts","sourceRoot":"","sources":["../src/view.ts"],"names":[],"mappings":"AAEA,OAAO,EAAc,CAAC,EAAE,MAAM,aAAa,CAAC;AAM5C,eAAO,MAAM,QAAQ,aAalB,CAAC;AACJ,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,QAAQ,CAAC,CAAC;AAEhD,eAAO,MAAM,cAAc;;iBAEzB,CAAC;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AAE5D,eAAO,MAAM,WAAW;;;;KAGtB,CAAC;AAEH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;iBAStB,CAAC;AAEH,eAAO,MAAM,SAAS;;;;;;;;;;;iBAQpB,CAAC;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,SAAS,CAAC,CAAC;AAElD,eAAO,MAAM,eAAe;;;;;;;;;;;;;kBAoC1B,CAAC"}
package/dist/view.js ADDED
@@ -0,0 +1,79 @@
1
+ // ABOUTME: github-issue.view, the step that fetches a GitHub issue's details -- number, title, body, state,
2
+ // ABOUTME: label names, author and web URL -- from the GitHub REST API.
3
+ import { defineStep, z } from "@ligeti/sdk";
4
+ import pkg from "../package.json" with { type: "json" };
5
+ import { createGitHubClient } from "./client.js";
6
+ import { loadGitHubSettings, GITHUB_ENV_VARS } from "./settings.js";
7
+ import { parseIssueUrl } from "./url.js";
8
+ export const IssueUrl = z
9
+ .string()
10
+ .min(1)
11
+ .refine((value) => {
12
+ try {
13
+ parseIssueUrl(value);
14
+ return true;
15
+ }
16
+ catch {
17
+ return false;
18
+ }
19
+ }, { message: "must be a full GitHub issue URL, e.g. https://github.com/owner/repo/issues/1" });
20
+ export const IssueViewInput = z.object({
21
+ issueUrl: IssueUrl,
22
+ });
23
+ export const GitHubLabel = z.union([
24
+ z.string(),
25
+ z.object({ name: z.string() }).transform((label) => label.name),
26
+ ]);
27
+ export const GitHubIssue = z.object({
28
+ number: z.number(),
29
+ title: z.string(),
30
+ body: z.string().nullable(),
31
+ state: z.enum(["open", "closed"]),
32
+ pull_request: z.unknown().optional(),
33
+ labels: z.array(GitHubLabel),
34
+ user: z.object({ login: z.string() }),
35
+ html_url: z.string(),
36
+ });
37
+ export const IssueView = z.object({
38
+ number: z.number(),
39
+ title: z.string(),
40
+ body: z.string().nullable(),
41
+ state: z.enum(["open", "closed"]),
42
+ labels: z.array(z.string()),
43
+ author: z.string(),
44
+ htmlUrl: z.string(),
45
+ });
46
+ export const githubIssueView = defineStep({
47
+ name: "github-issue.view",
48
+ envVars: GITHUB_ENV_VARS,
49
+ description: "Fetches a GitHub issue's details.",
50
+ package: { name: pkg.name, version: pkg.version },
51
+ input: IssueViewInput,
52
+ output: IssueView,
53
+ retry: { maxAttempts: 3, intervalSeconds: 2 },
54
+ async run(sctx, input) {
55
+ const settings = loadGitHubSettings();
56
+ const { owner, repo, number } = parseIssueUrl(input.issueUrl);
57
+ const client = createGitHubClient({
58
+ token: settings.token,
59
+ apiUrl: settings.apiUrl,
60
+ owner,
61
+ repo,
62
+ signal: sctx.signal,
63
+ });
64
+ const issue = GitHubIssue.parse(await client.get(`/issues/${String(number)}`));
65
+ if (issue.pull_request !== undefined) {
66
+ throw new Error(`github-issue: ${input.issueUrl} is a pull request, not an issue; use the github-pr steps`);
67
+ }
68
+ return {
69
+ number: issue.number,
70
+ title: issue.title,
71
+ body: issue.body,
72
+ state: issue.state,
73
+ labels: issue.labels,
74
+ author: issue.user.login,
75
+ htmlUrl: issue.html_url,
76
+ };
77
+ },
78
+ });
79
+ //# sourceMappingURL=view.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"view.js","sourceRoot":"","sources":["../src/view.ts"],"names":[],"mappings":"AAAA,4GAA4G;AAC5G,wEAAwE;AACxE,OAAO,EAAE,UAAU,EAAE,CAAC,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,GAAG,MAAM,iBAAiB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MA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K;YACrB,MAAM,EAAE,QAAQ,CAAC,MAAM;YACvB,KAAK;YACL,IAAI;YACJ,MAAM,EAAE,IAAI,CAAC,MAAM;SACpB,CAAC,CAAC;QAEH,MAAM,KAAK,GAAG,WAAW,CAAC,KAAK,CAAC,MAAM,MAAM,CAAC,GAAG,CAAC,WAAW,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;QAC/E,IAAI,KAAK,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;YACrC,MAAM,IAAI,KAAK,CACb,iBAAiB,KAAK,CAAC,QAAQ,2DAA2D,CAC3F,CAAC;QACJ,CAAC;QACD,OAAO;YACL,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,KAAK;YACxB,OAAO,EAAE,KAAK,CAAC,QAAQ;SACxB,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,29 @@
1
1
  {
2
2
  "name": "@ligeti/step-github-issue",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.0.1",
4
+ "description": "Ligeti step package: reads a GitHub issue through the REST API, labels and comments on it, and lists a repository's labelled issues.",
5
+ "type": "module",
6
+ "license": "Apache-2.0",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://gitlab.com/nagyv-projects/ligeti.git",
10
+ "directory": "steps/github-issue"
11
+ },
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "default": "./dist/index.js"
16
+ }
17
+ },
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "peerDependencies": {
22
+ "@ligeti/sdk": "^2.3.0"
23
+ },
24
+ "devDependencies": {
25
+ "@ligeti/sdk": "2.3.0",
26
+ "@ligeti/testing": "2.0.6"
27
+ },
28
+ "scripts": {}
6
29
  }