@ligeti/step-gitlab-mr 0.0.0-stage → 2.1.0
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/LICENSE +201 -0
- package/README.md +225 -2
- package/dist/approve.d.ts +35 -0
- package/dist/approve.d.ts.map +1 -0
- package/dist/approve.js +43 -0
- package/dist/approve.js.map +1 -0
- package/dist/assign.d.ts +23 -0
- package/dist/assign.d.ts.map +1 -0
- package/dist/assign.js +38 -0
- package/dist/assign.js.map +1 -0
- package/dist/await-pipeline.d.ts +33 -0
- package/dist/await-pipeline.d.ts.map +1 -0
- package/dist/await-pipeline.js +183 -0
- package/dist/await-pipeline.js.map +1 -0
- package/dist/client.d.ts +34 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +163 -0
- package/dist/client.js.map +1 -0
- package/dist/comment.d.ts +24 -0
- package/dist/comment.d.ts.map +1 -0
- package/dist/comment.js +27 -0
- package/dist/comment.js.map +1 -0
- package/dist/commit-sha.d.ts +4 -0
- package/dist/commit-sha.d.ts.map +1 -0
- package/dist/commit-sha.js +8 -0
- package/dist/commit-sha.js.map +1 -0
- package/dist/create.d.ts +29 -0
- package/dist/create.d.ts.map +1 -0
- package/dist/create.js +94 -0
- package/dist/create.js.map +1 -0
- package/dist/diff.d.ts +34 -0
- package/dist/diff.d.ts.map +1 -0
- package/dist/diff.js +35 -0
- package/dist/diff.js.map +1 -0
- package/dist/draft.d.ts +4 -0
- package/dist/draft.d.ts.map +1 -0
- package/dist/draft.js +13 -0
- package/dist/draft.js.map +1 -0
- package/dist/find-by-branch.d.ts +52 -0
- package/dist/find-by-branch.d.ts.map +1 -0
- package/dist/find-by-branch.js +67 -0
- package/dist/find-by-branch.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/mark-ready.d.ts +17 -0
- package/dist/mark-ready.d.ts.map +1 -0
- package/dist/mark-ready.js +46 -0
- package/dist/mark-ready.js.map +1 -0
- package/dist/merge.d.ts +36 -0
- package/dist/merge.d.ts.map +1 -0
- package/dist/merge.js +129 -0
- package/dist/merge.js.map +1 -0
- package/dist/notes.d.ts +37 -0
- package/dist/notes.d.ts.map +1 -0
- package/dist/notes.js +25 -0
- package/dist/notes.js.map +1 -0
- package/dist/run-pipeline.d.ts +21 -0
- package/dist/run-pipeline.d.ts.map +1 -0
- package/dist/run-pipeline.js +40 -0
- package/dist/run-pipeline.js.map +1 -0
- package/dist/settings.d.ts +12 -0
- package/dist/settings.d.ts.map +1 -0
- package/dist/settings.js +27 -0
- package/dist/settings.js.map +1 -0
- package/dist/sleep.d.ts +2 -0
- package/dist/sleep.d.ts.map +1 -0
- package/dist/sleep.js +23 -0
- package/dist/sleep.js.map +1 -0
- package/dist/types.d.ts +31 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +61 -0
- package/dist/types.js.map +1 -0
- package/dist/url.d.ts +12 -0
- package/dist/url.d.ts.map +1 -0
- package/dist/url.js +67 -0
- package/dist/url.js.map +1 -0
- package/dist/view.d.ts +53 -0
- package/dist/view.d.ts.map +1 -0
- package/dist/view.js +42 -0
- package/dist/view.js.map +1 -0
- 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,226 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ligeti/step-gitlab-mr
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
View, diff, comment on, approve, merge and drive the pipeline of a GitLab merge request through
|
|
4
|
+
the REST API, as twelve steps. Ten are addressed by the merge request's full web URL
|
|
5
|
+
(`mergeRequestUrl`, e.g. `https://gitlab.example/g/p/-/merge_requests/1`); the other two --
|
|
6
|
+
`create` and `find-by-branch` -- have no merge request iid to be scoped to yet, so
|
|
7
|
+
they take a bare GitLab project web URL (`projectUrl`, e.g. `https://gitlab.example/g/p`) instead.
|
|
8
|
+
|
|
9
|
+
## Steps
|
|
10
|
+
|
|
11
|
+
| Step | Scope | Purpose | Key inputs | Retry |
|
|
12
|
+
| -------------------------- | ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------- |
|
|
13
|
+
| `gitlab-mr.view` | `mergeRequestUrl` | Fetches the merge request's details. | -- | up to 3, 2s apart |
|
|
14
|
+
| `gitlab-mr.diff` | `mergeRequestUrl` | Fetches its per-file diffs, paginating as needed. | -- | up to 3, 2s apart |
|
|
15
|
+
| `gitlab-mr.notes` | `mergeRequestUrl` | Fetches its notes (comments), paginating as needed. | -- | up to 3, 2s apart |
|
|
16
|
+
| `gitlab-mr.approve` | `mergeRequestUrl` | Approves it. | `sha` (optional, guards against a moved head) | 1 (not retried) |
|
|
17
|
+
| `gitlab-mr.comment` | `mergeRequestUrl` | Posts a note (comment) on it. | `body` (required, non-blank) | 1 (not retried) |
|
|
18
|
+
| `gitlab-mr.merge` | `mergeRequestUrl` | Merges it. | `sha`, `squash`, `mergeCommitMessage`, `shouldRemoveSourceBranch`, `mergeWhenPipelineSucceeds` (all optional) | 1 (not retried) |
|
|
19
|
+
| `gitlab-mr.await-pipeline` | `mergeRequestUrl` | Polls until the merge request's own diff head is the given commit and its merge-request pipeline reaches a final status, or the diff head persistently moves to a different commit, or it times out. | `sha` (required, 40- or 64-character lowercase hex), `minPipelineId` (optional, skips older head pipelines), `intervalMs` (default 15000), `timeoutMs` (default 3600000), `mismatchGraceMs` (default 60000) | 1 (not retried) |
|
|
20
|
+
| `gitlab-mr.run-pipeline` | `mergeRequestUrl` | Creates a new merge-request pipeline for the merge request's current head (`POST /merge_requests/:iid/pipelines`), for when a push did not trigger one. Pair it with `await-pipeline`. | -- | 3, 2 s apart |
|
|
21
|
+
| `gitlab-mr.create` | `projectUrl` | Opens a merge request for a pushed branch, as a Draft by default, or recovers the existing one for it. | `sourceBranch`, `title` (required), `targetBranch` (optional, defaults to the project's `default_branch`), `description`, `draft` (optional, default `true`), `removeSourceBranch` (optional) | up to 3, 2s apart (see below) |
|
|
22
|
+
| `gitlab-mr.mark-ready` | `mergeRequestUrl` | Un-drafts it (GitLab's own "mark as ready" action). | -- | up to 3, 2s apart (see below) |
|
|
23
|
+
| `gitlab-mr.assign` | `mergeRequestUrl` | Makes the owner of the GitLab token the step authenticates with the merge request's only assignee, replacing any existing assignees. Looks the owner up with `GET /api/v4/user`; throws if GitLab's response does not list them as an assignee. | none beyond `mergeRequestUrl` | up to 3, 2s apart |
|
|
24
|
+
| `gitlab-mr.find-by-branch` | `projectUrl` | Finds a merge request by its source branch. | `sourceBranch` (required), `state` (optional, defaults to `opened`) | up to 3, 2s apart |
|
|
25
|
+
|
|
26
|
+
`gitlab-mr.view` outputs the merge request's `iid`, `title`, `description`, `state`, `draft`,
|
|
27
|
+
`author`, `source_branch`, `target_branch`, `sha`, `merge_status`, `web_url` and, when GitLab sends them, `detailed_merge_status`,
|
|
28
|
+
`has_conflicts` and `head_pipeline` (`{ id, ... }` or `null`).
|
|
29
|
+
`gitlab-mr.diff` outputs `{ files: [...] }`, one entry per changed file.
|
|
30
|
+
`gitlab-mr.notes` outputs `{ notes: [...] }`. `gitlab-mr.comment` outputs the created note.
|
|
31
|
+
`gitlab-mr.approve` and `gitlab-mr.merge` output GitLab's own approval/merge-result shape, with
|
|
32
|
+
every approval-related field optional since GitLab's approvals API reports different subsets per
|
|
33
|
+
license tier. `gitlab-mr.merge` returns `state: "need_rebase"` instead of throwing when GitLab
|
|
34
|
+
refuses the merge (405, 406 or 422) and the merge request is still `opened` with its head still at
|
|
35
|
+
the `sha` the caller passed. It does not look at `detailed_merge_status`: a project that
|
|
36
|
+
fast-forwards refuses every merge request whose source branch is no longer on top of its target,
|
|
37
|
+
and right after the target branch moves GitLab reports `checking` or `unchecked` for a while
|
|
38
|
+
instead of `need_rebase`. The caller's next rebase decides whether anything actually moved, so a
|
|
39
|
+
caller that merges beside other merge requests branches on this state and bounds its own loop. A
|
|
40
|
+
refusal with no `sha` passed, a moved head, a closed merge request, or any other status code still
|
|
41
|
+
throws. GitLab's merge request API documents 405 (the merge request cannot merge), 409 (`sha` does not
|
|
42
|
+
match the source head), 422 (branch cannot be merged), 401 and, with the require-a-commit-sha
|
|
43
|
+
setting, 400 as the failure codes of `PUT /merge_requests/:iid/merge`. It does not document 406;
|
|
44
|
+
this step still treats 406 as a refusal because older GitLab versions have been observed to answer
|
|
45
|
+
it, not because the docs list it.
|
|
46
|
+
`gitlab-mr.await-pipeline` outputs `{ id, status, web_url, sha, mergeRequestSha }`:
|
|
47
|
+
the pipeline fields describe the merge-request pipeline it awaited, and `mergeRequestSha` is the
|
|
48
|
+
merge request's own diff-head sha (lowercased) at the moment this step returned. This step reads
|
|
49
|
+
the merge request itself (`GET /merge_requests/:iid`), not the pipelines endpoint, because a
|
|
50
|
+
merged-results pipeline's own `sha` is an ephemeral merge-ref commit that never equals the
|
|
51
|
+
source-branch commit a caller pushed -- comparing against it directly would never match. Instead
|
|
52
|
+
this step compares the awaited sha against the merge request's own `sha` (its diff head), and once
|
|
53
|
+
that matches, waits for `head_pipeline` to be a pipeline GitLab built for the merge request itself
|
|
54
|
+
-- `source === "merge_request_event"` and/or a `ref` under `refs/merge-requests/` (GitLab's
|
|
55
|
+
merge-request API docs: https://docs.gitlab.com/api/merge_requests/) -- rather than an ordinary
|
|
56
|
+
branch (`push`) pipeline that happens to attach first. A merge-request pipeline running on a
|
|
57
|
+
merged-results ref (`refs/merge-requests/<iid>/merge` or `/train`) is accepted regardless of its
|
|
58
|
+
own `sha`, since that sha is an ephemeral merge-ref commit, never the source-branch commit awaited.
|
|
59
|
+
**Known limitation:** because a merged-results pipeline is accepted purely on its ref and never
|
|
60
|
+
compared against `targetSha`, a stale merged-results pipeline that GitLab has not yet superseded
|
|
61
|
+
can be accepted right after a push to an existing merge request -- there is no field on the merged
|
|
62
|
+
pipeline itself this step can compare against the awaited commit to rule that out, unlike the
|
|
63
|
+
non-merged-results case below.
|
|
64
|
+
Any OTHER merge-request pipeline -- one on the source branch itself, or on a detached
|
|
65
|
+
`refs/merge-requests/<iid>/head` ref -- must have its own `sha` equal to the awaited commit before
|
|
66
|
+
it counts: right after a push to an existing merge request, `head_pipeline` can still be the
|
|
67
|
+
PREVIOUS commit's own final-status merge-request pipeline for a little while, and accepting it on
|
|
68
|
+
sight would report success for a pipeline GitLab built for a commit that is not the one this step
|
|
69
|
+
was asked to wait for. A non-success final status (`failed`, `canceled`, `skipped`, `manual`,
|
|
70
|
+
`scheduled`) is returned, not thrown: it is expected, routine traffic a workflow branches on (e.g.
|
|
71
|
+
a gate-fix pass on `failed`), not an incident (see
|
|
72
|
+
[ADR-0005](../../adr/0005-steps-throw-results-are-for-expected-traffic.md)). `manual` and
|
|
73
|
+
`scheduled` are treated as final too, even though nothing failed and nothing succeeded: both block
|
|
74
|
+
on a human, and waiting longer would only run the step out its timeout instead of surfacing that.
|
|
75
|
+
GitLab creates a merge request's pipeline for a push asynchronously, so right after a push (or a
|
|
76
|
+
merge request's own creation) `head_pipeline` can briefly still be `null`, or can still be an
|
|
77
|
+
ordinary branch pipeline attached from before this push -- neither is a sign anything went wrong,
|
|
78
|
+
so this step keeps waiting through both. This step requires the target project's CI configuration
|
|
79
|
+
to actually create `merge_request_event` pipelines for the branch being awaited (GitLab's
|
|
80
|
+
`rules: if: '$CI_PIPELINE_SOURCE == "merge_request_event"'` or an equivalent `workflow:` rule) --
|
|
81
|
+
without one, `head_pipeline` never becomes a merge-request pipeline and this step always times out;
|
|
82
|
+
the timeout error names the last non-merge-request `head_pipeline` it saw (id, source, ref) to make
|
|
83
|
+
that misconfiguration diagnosable. What ends the wait early is the merge request's own diff head
|
|
84
|
+
persistently differing from the awaited sha: right after a caller pushes a new commit to an
|
|
85
|
+
existing merge request, GitLab updates the merge request's own `sha` asynchronously, so a poll
|
|
86
|
+
landing in that window can briefly still see the previous commit -- not a sign that someone else
|
|
87
|
+
pushed a different commit. Only once that mismatch has lasted at least `mismatchGraceMs`
|
|
88
|
+
(default 60 seconds) does this step give up: it returns immediately with `mergeRequestSha` set to
|
|
89
|
+
the mismatched commit and every pipeline field `null`, so the caller compares `mergeRequestSha`
|
|
90
|
+
against the sha it awaited and treats the mismatch as its own failure signal -- this step does not
|
|
91
|
+
throw on it, because losing a race to a later push is routine traffic here too, not an incident.
|
|
92
|
+
This can happen at any point during the wait, not only before a pipeline for the awaited sha was
|
|
93
|
+
ever seen. A merge request whose diff head GitLab has not computed yet reports `sha: null`; this
|
|
94
|
+
step treats that as "not yet known" rather than a mismatch and keeps polling, CLEARING the
|
|
95
|
+
mismatch-grace clock if one was already running -- a diff head reverting to `null` between two
|
|
96
|
+
mismatched polls means GitLab is (re)computing it, so the earlier mismatch is stale rather than a
|
|
97
|
+
confirmed, ongoing one; a later mismatched poll starts the clock fresh.
|
|
98
|
+
|
|
99
|
+
`gitlab-mr.run-pipeline` outputs `{ id, status, web_url, sha }`, the pipeline GitLab created, with `sha`
|
|
100
|
+
lowercased. Creating a pipeline is not idempotent -- a second POST creates a second pipeline -- but a duplicate
|
|
101
|
+
pipeline for the same head is harmless, so it retries up to 3 times, 2 seconds apart; the Rule is in
|
|
102
|
+
[`test/gitlab-mr.feature`](test/gitlab-mr.feature). Pass the created pipeline's `id` to
|
|
103
|
+
`await-pipeline` as `minPipelineId`: GitLab updates a merge request's `head_pipeline` asynchronously,
|
|
104
|
+
so right after creation it may still report an older pipeline with the same sha in a final status.
|
|
105
|
+
|
|
106
|
+
`gitlab-mr.create` outputs `{ mergeRequestUrl, iid }`, mirroring `find-by-branch`'s `found: true`
|
|
107
|
+
shape so a workflow can treat both the same, for the merge request it opened or the existing open
|
|
108
|
+
one it recovered on a 409 -- see the replay-safety paragraph below. `gitlab-mr.mark-ready` outputs
|
|
109
|
+
`{ mergeRequestUrl, title }`. `gitlab-mr.assign` outputs `{ mergeRequestUrl, assignee: { id, username } }`, the token's owner;
|
|
110
|
+
use a human's personal token if the merge request should land with a human.
|
|
111
|
+
`gitlab-mr.find-by-branch` outputs a discriminated union:
|
|
112
|
+
`{ found: true, mergeRequestUrl, iid }`, or `{ found: false }` when no merge request matches --
|
|
113
|
+
"not found" is likewise expected, routine traffic, never treated as an error here.
|
|
114
|
+
|
|
115
|
+
`gitlab-mr.create` and `gitlab-mr.mark-ready` retry up to 3 times, 2 seconds apart, like the
|
|
116
|
+
read-only steps, because each handles its one re-execution case explicitly rather than failing it.
|
|
117
|
+
Re-execution here means workflow recovery re-running a step whose checkpoint was never recorded --
|
|
118
|
+
not a DBOS retry of a step that is still in flight.
|
|
119
|
+
|
|
120
|
+
For `gitlab-mr.create`, re-execution after GitLab already created the merge request (but before
|
|
121
|
+
the checkpoint recorded it) lands on a 409: another open merge request already exists for that
|
|
122
|
+
source/target branch pair, in the same project. On a 409, this step looks up that existing open
|
|
123
|
+
merge request (reusing `find-by-branch`'s own query, narrowed to the same target branch, and
|
|
124
|
+
excluding merge requests sourced from a fork) and returns it instead of throwing. Any other failure
|
|
125
|
+
throws as usual.
|
|
126
|
+
|
|
127
|
+
For `gitlab-mr.mark-ready`, re-execution is safe because each attempt starts with a fresh GET:
|
|
128
|
+
GitLab's own `draft` field on the merge request, not a title snapshot from a previous attempt,
|
|
129
|
+
decides whether there is anything to do.
|
|
130
|
+
|
|
131
|
+
When `draft` is `true` (the default), `gitlab-mr.create` prefixes `title` with `Draft: `, unless
|
|
132
|
+
`title` already carries a recognized draft prefix (`Draft:`, `[Draft]`, `(Draft)`, repeated and
|
|
133
|
+
matched case-insensitively) -- GitLab's REST API has no separate `draft` field on create; draft
|
|
134
|
+
status is conveyed entirely through the title. `gitlab-mr.mark-ready` reads the merge request's
|
|
135
|
+
`draft` field; if `false` (already ready), it is a no-op that skips the write entirely. Otherwise it
|
|
136
|
+
strips that same prefix and writes the stripped title, then verifies the response's `draft` field is
|
|
137
|
+
now `false`.
|
|
138
|
+
|
|
139
|
+
A transient failure mid-poll (a 5xx or 429 response, or a network-level failure that never got a
|
|
140
|
+
response at all) does not end `await-pipeline`'s wait early -- it is retried on the next tick, same
|
|
141
|
+
as any other not-yet-caught-up response. A malformed or unexpectedly-shaped response (one that
|
|
142
|
+
fails schema validation) is a different matter: retrying it would never produce a different
|
|
143
|
+
result, so it is thrown immediately instead of being treated as transient. See
|
|
144
|
+
`isTransientGitLabError` (`src/client.ts`) for the exact classification, and `GitLabNetworkError`
|
|
145
|
+
for the type that distinguishes "no response at all" from a `GitLabHttpError` GitLab did send.
|
|
146
|
+
|
|
147
|
+
See [`test/gitlab-mr.feature`](test/gitlab-mr.feature) for the authoritative Rules on when
|
|
148
|
+
`gitlab-mr.merge`, `gitlab-mr.comment` and `gitlab-mr.await-pipeline` retry, replay or return
|
|
149
|
+
instead of throwing; the paragraphs below explain the mechanism behind them.
|
|
150
|
+
|
|
151
|
+
Replaying `gitlab-mr.merge` after a crash whose earlier success was never recorded (the workflow
|
|
152
|
+
process died between GitLab returning success and that outcome being persisted), or after a
|
|
153
|
+
transient failure whose response was simply lost in transit even though GitLab performed the
|
|
154
|
+
merge, does not fail the replay: GitLab responds to a second merge attempt on an already-merged
|
|
155
|
+
merge request with 405, 406 or 422, and a 5xx, 429, or network-level failure
|
|
156
|
+
(`isTransientGitLabError`) leaves this step unable to tell "GitLab never got the request" apart
|
|
157
|
+
from "GitLab did it but the response never arrived" -- in every one of these cases, this step
|
|
158
|
+
recognizes the ambiguity and re-fetches the merge request. The failed PUT may itself be the merge
|
|
159
|
+
GitLab is still performing in the background -- it reports that merge request as `state: "locked"`
|
|
160
|
+
(or `detailed_merge_status: "merging"` on GitLab versions that populate it) while the merge is in
|
|
161
|
+
flight, so a single re-fetch landing in that window sees neither "merged" nor "still open" and
|
|
162
|
+
would otherwise give up on a merge that was seconds from completing. This step polls the re-fetch
|
|
163
|
+
for up to 30 seconds, a few seconds apart, while it keeps seeing "locked"/"merging" before deciding
|
|
164
|
+
anything. If the re-fetch (after that polling) reports `state: "merged"` and -- when this call was
|
|
165
|
+
given a `sha` -- that merge request's own `sha` matches it, the earlier success is returned instead
|
|
166
|
+
of failing a step that, from the caller's perspective, did exactly what it was asked. Any other
|
|
167
|
+
settled outcome (still open, or merged at a different sha, e.g. because someone else merged it or a
|
|
168
|
+
rebase moved the head after this step's real failure) means the original error was a genuine
|
|
169
|
+
failure, and it is rethrown as-is -- including when the locked-poll budget (30 seconds) is
|
|
170
|
+
exhausted while the merge request is still reported as `"locked"`/`"merging"`: that is the re-fetch
|
|
171
|
+
succeeding with an inconclusive answer, not the re-fetch failing, so the original PUT failure is
|
|
172
|
+
rethrown plain, with nothing attached. If the re-fetch itself fails outright (its own network
|
|
173
|
+
error, or a non-2xx response), the ORIGINAL PUT failure is still what gets thrown -- it's the one
|
|
174
|
+
that reflects what this step's own merge attempt actually did, and keeps its own type (e.g.
|
|
175
|
+
`GitLabHttpError`/`GitLabNetworkError`) recognisable to a caller -- but the re-fetch's own failure
|
|
176
|
+
is attached under a `recoveryError` property, not `cause`: a `GitLabNetworkError` already sets
|
|
177
|
+
`cause` to the network failure IT wraps, and overwriting that would silently lose it. A 409 (the
|
|
178
|
+
sha given no longer matches the merge request's head) is never treated as a possible replay --
|
|
179
|
+
GitLab returns 409 specifically because it looked at the shas and they disagreed, so there is
|
|
180
|
+
nothing to check for by re-fetching.
|
|
181
|
+
|
|
182
|
+
Six of the twelve steps are read-only (`view`, `diff`, `notes`, `find-by-branch`, `await-pipeline`,
|
|
183
|
+
and `mark-ready`'s own GET) and change nothing server-side, but only `view`, `diff`, `notes` and
|
|
184
|
+
`find-by-branch` retry a failed attempt outright: they retry up to 3 times, 2 seconds
|
|
185
|
+
apart, because a transient network or 5xx failure is safe to retry blind. `gitlab-mr.await-pipeline`
|
|
186
|
+
does not, even though it is also read-only: it already polls internally against its own
|
|
187
|
+
`intervalMs`/`timeoutMs`, and already tolerates a transient failure (5xx, 429, network) _inside_
|
|
188
|
+
that internal poll without giving up -- a DBOS-level retry on top would instead restart the whole
|
|
189
|
+
bounded wait from zero on every blip along the way, silently multiplying the effective timeout by
|
|
190
|
+
`maxAttempts`. A failed attempt (including a timeout, or a non-transient failure such as a 4xx)
|
|
191
|
+
surfaces as one step failure instead.
|
|
192
|
+
|
|
193
|
+
`gitlab-mr.assign` retries blind too: its GET of the token's owner is read-only and its PUT sets an
|
|
194
|
+
absolute assignee list, so repeating it is idempotent.
|
|
195
|
+
|
|
196
|
+
`approve`, `comment` and `merge` use `maxAttempts: 1` -- no retry at all, for the reasons pinned as
|
|
197
|
+
executable Rules in [`test/gitlab-mr.feature`](test/gitlab-mr.feature). `gitlab-mr.create` is the
|
|
198
|
+
exception among the non-idempotent group, together with `run-pipeline` (see above): it retries up to 3 times, 2 seconds apart, because the
|
|
199
|
+
one way it can be re-run (an unrecorded crash-replay after GitLab already created the merge
|
|
200
|
+
request) lands on the 409 recovery path described above rather than opening a duplicate merge
|
|
201
|
+
request.
|
|
202
|
+
|
|
203
|
+
## Response schemas
|
|
204
|
+
|
|
205
|
+
Every schema in this package that describes a _GitLab response_ is declared `.loose()`, so unknown
|
|
206
|
+
keys survive into a step's output instead of being stripped -- GitLab's responses differ by version
|
|
207
|
+
and by tier (approval fields, for instance, only exist on paid tiers), and a field this package has
|
|
208
|
+
not heard of is still worth handing to the caller. Only the fields a step actually relies on are
|
|
209
|
+
declared and required. A schema describing a shape this package itself invents (a step's input, or
|
|
210
|
+
a wrapper like `{ notes: [...] }`) stays strict.
|
|
211
|
+
|
|
212
|
+
## Environment variables
|
|
213
|
+
|
|
214
|
+
| Variable | Required | Default | Purpose |
|
|
215
|
+
| -------------- | -------- | ------- | -------------------------------------------- |
|
|
216
|
+
| `GITLAB_TOKEN` | yes | -- | `PRIVATE-TOKEN` sent to the GitLab REST API. |
|
|
217
|
+
|
|
218
|
+
`loadGitLabSettings` (`src/settings.ts`) throws naming `GITLAB_TOKEN` when it is unset or blank.
|
|
219
|
+
`GITLAB_ACCESS_TOKEN` is not supported: use `GITLAB_TOKEN`.
|
|
220
|
+
|
|
221
|
+
This settings logic is deliberately duplicated, byte-for-byte, in
|
|
222
|
+
[`steps/gitlab-registry`](../gitlab-registry/README.md)'s own `src/settings.ts` rather than
|
|
223
|
+
shared. That is not an oversight: [ADR-0001](../../adr/0001-package-boundaries-and-dependency-rules.md)
|
|
224
|
+
forbids one step package importing another, and with exactly two callers there is no package that
|
|
225
|
+
correctly owns a shared home for the logic — introducing one would be a third package existing
|
|
226
|
+
solely to break a boundary the record decided on purpose.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { z } from "@ligeti/sdk";
|
|
2
|
+
export declare const ApproveInput: z.ZodObject<{
|
|
3
|
+
mergeRequestUrl: z.ZodString;
|
|
4
|
+
sha: z.ZodOptional<z.ZodString>;
|
|
5
|
+
}, z.core.$strip>;
|
|
6
|
+
export type ApproveInput = z.infer<typeof ApproveInput>;
|
|
7
|
+
export declare const ApproveOutput: z.ZodObject<{
|
|
8
|
+
approved: z.ZodOptional<z.ZodBoolean>;
|
|
9
|
+
approved_by: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
10
|
+
user: z.ZodObject<{
|
|
11
|
+
id: z.ZodNumber;
|
|
12
|
+
username: z.ZodString;
|
|
13
|
+
name: z.ZodString;
|
|
14
|
+
}, z.core.$loose>;
|
|
15
|
+
}, z.core.$loose>>>;
|
|
16
|
+
approvals_left: z.ZodOptional<z.ZodNumber>;
|
|
17
|
+
approvals_required: z.ZodOptional<z.ZodNumber>;
|
|
18
|
+
}, z.core.$loose>;
|
|
19
|
+
export type ApproveOutput = z.infer<typeof ApproveOutput>;
|
|
20
|
+
export declare const gitlabMrApprove: import("@ligeti/sdk").StepDefinition<z.ZodObject<{
|
|
21
|
+
mergeRequestUrl: z.ZodString;
|
|
22
|
+
sha: z.ZodOptional<z.ZodString>;
|
|
23
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
24
|
+
approved: z.ZodOptional<z.ZodBoolean>;
|
|
25
|
+
approved_by: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
26
|
+
user: z.ZodObject<{
|
|
27
|
+
id: z.ZodNumber;
|
|
28
|
+
username: z.ZodString;
|
|
29
|
+
name: z.ZodString;
|
|
30
|
+
}, z.core.$loose>;
|
|
31
|
+
}, z.core.$loose>>>;
|
|
32
|
+
approvals_left: z.ZodOptional<z.ZodNumber>;
|
|
33
|
+
approvals_required: z.ZodOptional<z.ZodNumber>;
|
|
34
|
+
}, z.core.$loose>>;
|
|
35
|
+
//# sourceMappingURL=approve.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"approve.d.ts","sourceRoot":"","sources":["../src/approve.ts"],"names":[],"mappings":"AAEA,OAAO,EAAc,CAAC,EAAE,MAAM,aAAa,CAAC;AAM5C,eAAO,MAAM,YAAY;;;iBAQvB,CAAC;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AAExD,eAAO,MAAM,aAAa;;;;;;;;;;;iBAOhB,CAAC;AACX,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AAE1D,eAAO,MAAM,eAAe;;;;;;;;;;;;;;kBAsB1B,CAAC"}
|
package/dist/approve.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// ABOUTME: gitlabMrApprove, the step that approves a GitLab merge request, optionally guarded
|
|
2
|
+
// ABOUTME: against a moved head via an expected sha.
|
|
3
|
+
import { defineStep, z } from "@ligeti/sdk";
|
|
4
|
+
import pkg from "../package.json" with { type: "json" };
|
|
5
|
+
import { createClientForMergeRequest } from "./client.js";
|
|
6
|
+
import { GitLabUser, MergeRequestInput } from "./types.js";
|
|
7
|
+
import { GITLAB_ENV_VARS } from "./settings.js";
|
|
8
|
+
export const ApproveInput = MergeRequestInput.extend({
|
|
9
|
+
sha: z
|
|
10
|
+
.string()
|
|
11
|
+
.min(1)
|
|
12
|
+
.optional()
|
|
13
|
+
.describe("Guards against approving a merge request whose head has moved since the caller last looked at it."),
|
|
14
|
+
});
|
|
15
|
+
export const ApproveOutput = z
|
|
16
|
+
.object({
|
|
17
|
+
approved: z.boolean().optional(),
|
|
18
|
+
approved_by: z.array(z.object({ user: GitLabUser }).loose()).optional(),
|
|
19
|
+
approvals_left: z.number().optional(),
|
|
20
|
+
approvals_required: z.number().optional(),
|
|
21
|
+
})
|
|
22
|
+
.loose();
|
|
23
|
+
export const gitlabMrApprove = defineStep({
|
|
24
|
+
name: "gitlab-mr.approve",
|
|
25
|
+
envVars: GITLAB_ENV_VARS,
|
|
26
|
+
description: "Approves a GitLab merge request.",
|
|
27
|
+
package: { name: pkg.name, version: pkg.version },
|
|
28
|
+
input: ApproveInput,
|
|
29
|
+
output: ApproveOutput,
|
|
30
|
+
retry: { maxAttempts: 1 },
|
|
31
|
+
async run(sctx, input) {
|
|
32
|
+
const { client, iid } = createClientForMergeRequest(input.mergeRequestUrl, sctx.signal);
|
|
33
|
+
const body = {};
|
|
34
|
+
if (input.sha !== undefined) {
|
|
35
|
+
body.sha = input.sha;
|
|
36
|
+
}
|
|
37
|
+
const result = await client.request("POST", `/merge_requests/${String(iid)}/approve`, {
|
|
38
|
+
body: Object.keys(body).length > 0 ? body : undefined,
|
|
39
|
+
});
|
|
40
|
+
return ApproveOutput.parse(result);
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
//# sourceMappingURL=approve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"approve.js","sourceRoot":"","sources":["../src/approve.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,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,2BAA2B,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,MAAM,CAAC,MAAM,YAAY,GAAG,iBAAiB,CAAC,MAAM,CAAC;IACnD,GAAG,EAAE,CAAC;SACH,MAAM,EAAE;SACR,GAAG,CAAC,CAAC,CAAC;SACN,QAAQ,EAAE;SACV,QAAQ,CACP,mGAAmG,CACpG;CACJ,CAAC,CAAC;AAGH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC;KAC3B,MAAM,CAAC;IACN,QAAQ,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IAChC,WAAW,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,QAAQ,EAAE;IACvE,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACrC,kBAAkB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC1C,CAAC;KACD,KAAK,EAAE,CAAC;AAGX,MAAM,CAAC,MAAM,eAAe,GAAG,UAAU,CAAC;IACxC,IAAI,EAAE,mBAAmB;IACzB,OAAO,EAAE,eAAe;IACxB,WAAW,EAAE,kCAAkC;IAC/C,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,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,2BAA2B,CAAC,KAAK,CAAC,eAAe,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QAExF,MAAM,IAAI,GAA4B,EAAE,CAAC;QACzC,IAAI,KAAK,CAAC,GAAG,KAAK,SAAS,EAAE,CAAC;YAC5B,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC;QACvB,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,mBAAmB,MAAM,CAAC,GAAG,CAAC,UAAU,EAAE;YACpF,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;SACtD,CAAC,CAAC;QACH,OAAO,aAAa,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACrC,CAAC;CACF,CAAC,CAAC"}
|
package/dist/assign.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { z } from "@ligeti/sdk";
|
|
2
|
+
export declare const AssignInput: z.ZodObject<{
|
|
3
|
+
mergeRequestUrl: z.ZodString;
|
|
4
|
+
}, z.core.$strip>;
|
|
5
|
+
export type AssignInput = z.infer<typeof AssignInput>;
|
|
6
|
+
export declare const AssignOutput: z.ZodObject<{
|
|
7
|
+
mergeRequestUrl: z.ZodString;
|
|
8
|
+
assignee: z.ZodObject<{
|
|
9
|
+
id: z.ZodNumber;
|
|
10
|
+
username: z.ZodString;
|
|
11
|
+
}, z.core.$strip>;
|
|
12
|
+
}, z.core.$strip>;
|
|
13
|
+
export type AssignOutput = z.infer<typeof AssignOutput>;
|
|
14
|
+
export declare const gitlabMrAssign: import("@ligeti/sdk").StepDefinition<z.ZodObject<{
|
|
15
|
+
mergeRequestUrl: z.ZodString;
|
|
16
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
17
|
+
mergeRequestUrl: z.ZodString;
|
|
18
|
+
assignee: z.ZodObject<{
|
|
19
|
+
id: z.ZodNumber;
|
|
20
|
+
username: z.ZodString;
|
|
21
|
+
}, z.core.$strip>;
|
|
22
|
+
}, z.core.$strip>>;
|
|
23
|
+
//# sourceMappingURL=assign.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assign.d.ts","sourceRoot":"","sources":["../src/assign.ts"],"names":[],"mappings":"AAEA,OAAO,EAAc,CAAC,EAAE,MAAM,aAAa,CAAC;AAM5C,eAAO,MAAM,WAAW;;iBAAoB,CAAC;AAC7C,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AAEtD,eAAO,MAAM,YAAY;;;;;;iBAGvB,CAAC;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AAIxD,eAAO,MAAM,cAAc;;;;;;;;kBAiCzB,CAAC"}
|
package/dist/assign.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// ABOUTME: gitlab-mr.assign, the step that makes the owner of the GitLab token it authenticates
|
|
2
|
+
// ABOUTME: with the one assignee of a merge request, replacing any existing assignees.
|
|
3
|
+
import { defineStep, z } from "@ligeti/sdk";
|
|
4
|
+
import pkg from "../package.json" with { type: "json" };
|
|
5
|
+
import { createClientForMergeRequest } from "./client.js";
|
|
6
|
+
import { GitLabUser, MergeRequestInput } from "./types.js";
|
|
7
|
+
import { GITLAB_ENV_VARS } from "./settings.js";
|
|
8
|
+
export const AssignInput = MergeRequestInput;
|
|
9
|
+
export const AssignOutput = z.object({
|
|
10
|
+
mergeRequestUrl: z.string(),
|
|
11
|
+
assignee: z.object({ id: z.number(), username: z.string() }),
|
|
12
|
+
});
|
|
13
|
+
const UpdatedMergeRequest = z.object({ assignees: z.array(GitLabUser) }).loose();
|
|
14
|
+
export const gitlabMrAssign = defineStep({
|
|
15
|
+
name: "gitlab-mr.assign",
|
|
16
|
+
envVars: GITLAB_ENV_VARS,
|
|
17
|
+
description: "Assigns a GitLab merge request to the owner of the GitLab token, replacing any existing assignees.",
|
|
18
|
+
package: { name: pkg.name, version: pkg.version },
|
|
19
|
+
input: AssignInput,
|
|
20
|
+
output: AssignOutput,
|
|
21
|
+
retry: { maxAttempts: 3, intervalSeconds: 2 },
|
|
22
|
+
async run(sctx, input) {
|
|
23
|
+
const { client, iid } = createClientForMergeRequest(input.mergeRequestUrl, sctx.signal);
|
|
24
|
+
const owner = GitLabUser.parse(await client.request("GET", "/user", { scope: "instance" }));
|
|
25
|
+
const updated = UpdatedMergeRequest.parse(await client.request("PUT", `/merge_requests/${String(iid)}`, {
|
|
26
|
+
body: { assignee_ids: [owner.id] },
|
|
27
|
+
}));
|
|
28
|
+
if (!updated.assignees.some((assignee) => assignee.id === owner.id)) {
|
|
29
|
+
throw new Error(`gitlab-mr: assign for "${input.mergeRequestUrl}" asked GitLab to assign user ` +
|
|
30
|
+
`"${owner.username}" but the merge request's assignees do not include them`);
|
|
31
|
+
}
|
|
32
|
+
return AssignOutput.parse({
|
|
33
|
+
mergeRequestUrl: input.mergeRequestUrl,
|
|
34
|
+
assignee: { id: owner.id, username: owner.username },
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
//# sourceMappingURL=assign.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assign.js","sourceRoot":"","sources":["../src/assign.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAChG,uFAAuF;AACvF,OAAO,EAAE,UAAU,EAAE,CAAC,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,GAAG,MAAM,iBAAiB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AACxD,OAAO,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,MAAM,CAAC,MAAM,WAAW,GAAG,iBAAiB,CAAC;AAG7C,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,eAAe,EAAE,CAAC,CAAC,MAAM,EAAE;IAC3B,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC;CAC7D,CAAC,CAAC;AAGH,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC;AAEjF,MAAM,CAAC,MAAM,cAAc,GAAG,UAAU,CAAC;IACvC,IAAI,EAAE,kBAAkB;IACxB,OAAO,EAAE,eAAe;IACxB,WAAW,EACT,oGAAoG;IACtG,OAAO,EAAE,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE;IACjD,KAAK,EAAE,WAAW;IAClB,MAAM,EAAE,YAAY;IACpB,KAAK,EAAE,EAAE,WAAW,EAAE,CAAC,EAAE,eAAe,EAAE,CAAC,EAAE;IAE7C,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK;QACnB,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,2BAA2B,CAAC,KAAK,CAAC,eAAe,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QAExF,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,MAAM,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC;QAE5F,MAAM,OAAO,GAAG,mBAAmB,CAAC,KAAK,CACvC,MAAM,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,mBAAmB,MAAM,CAAC,GAAG,CAAC,EAAE,EAAE;YAC5D,IAAI,EAAE,EAAE,YAAY,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE;SACnC,CAAC,CACH,CAAC;QAEF,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE,KAAK,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC;YACpE,MAAM,IAAI,KAAK,CACb,0BAA0B,KAAK,CAAC,eAAe,gCAAgC;gBAC7E,IAAI,KAAK,CAAC,QAAQ,yDAAyD,CAC9E,CAAC;QACJ,CAAC;QAED,OAAO,YAAY,CAAC,KAAK,CAAC;YACxB,eAAe,EAAE,KAAK,CAAC,eAAe;YACtC,QAAQ,EAAE,EAAE,EAAE,EAAE,KAAK,CAAC,EAAE,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE;SACrD,CAAC,CAAC;IACL,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { z } from "@ligeti/sdk";
|
|
2
|
+
export declare const AwaitPipelineInput: z.ZodObject<{
|
|
3
|
+
mergeRequestUrl: z.ZodString;
|
|
4
|
+
sha: z.ZodString;
|
|
5
|
+
minPipelineId: z.ZodOptional<z.ZodNumber>;
|
|
6
|
+
intervalMs: z.ZodOptional<z.ZodNumber>;
|
|
7
|
+
timeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
8
|
+
mismatchGraceMs: z.ZodOptional<z.ZodNumber>;
|
|
9
|
+
}, z.core.$strip>;
|
|
10
|
+
export type AwaitPipelineInput = z.infer<typeof AwaitPipelineInput>;
|
|
11
|
+
export declare const AwaitPipelineOutput: z.ZodObject<{
|
|
12
|
+
id: z.ZodNullable<z.ZodNumber>;
|
|
13
|
+
status: z.ZodNullable<z.ZodString>;
|
|
14
|
+
web_url: z.ZodNullable<z.ZodString>;
|
|
15
|
+
sha: z.ZodNullable<z.ZodString>;
|
|
16
|
+
mergeRequestSha: z.ZodString;
|
|
17
|
+
}, z.core.$loose>;
|
|
18
|
+
export type AwaitPipelineOutput = z.infer<typeof AwaitPipelineOutput>;
|
|
19
|
+
export declare const gitlabMrAwaitPipeline: import("@ligeti/sdk").StepDefinition<z.ZodObject<{
|
|
20
|
+
mergeRequestUrl: z.ZodString;
|
|
21
|
+
sha: z.ZodString;
|
|
22
|
+
minPipelineId: z.ZodOptional<z.ZodNumber>;
|
|
23
|
+
intervalMs: z.ZodOptional<z.ZodNumber>;
|
|
24
|
+
timeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
25
|
+
mismatchGraceMs: z.ZodOptional<z.ZodNumber>;
|
|
26
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
27
|
+
id: z.ZodNullable<z.ZodNumber>;
|
|
28
|
+
status: z.ZodNullable<z.ZodString>;
|
|
29
|
+
web_url: z.ZodNullable<z.ZodString>;
|
|
30
|
+
sha: z.ZodNullable<z.ZodString>;
|
|
31
|
+
mergeRequestSha: z.ZodString;
|
|
32
|
+
}, z.core.$loose>>;
|
|
33
|
+
//# sourceMappingURL=await-pipeline.d.ts.map
|