@coderabbitai/config 0.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 +202 -0
- package/README.md +85 -0
- package/dist/define-config.d.ts +222 -0
- package/dist/define-config.d.ts.map +1 -0
- package/dist/define-config.js +81 -0
- package/dist/define-config.js.map +1 -0
- package/dist/index.d.ts +1567 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +58 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# @coderabbitai/config
|
|
2
|
+
|
|
3
|
+
Typed, programmatic authoring for [CodeRabbit](https://coderabbit.ai)
|
|
4
|
+
configuration — write your `.coderabbit.config.ts` in TypeScript instead of
|
|
5
|
+
`.coderabbit.yaml`, with editor autocomplete and author-time type-checking.
|
|
6
|
+
|
|
7
|
+
> **Beta.** This SDK is published under the `next` tag while we stabilize it. A
|
|
8
|
+
> committed `.coderabbit.yaml` always takes precedence over `.coderabbit.config.ts`.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
npm install --save-dev @coderabbitai/config@next
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
Create a `.coderabbit.config.ts` at the root of your repository:
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { defineConfig } from "@coderabbitai/config"
|
|
22
|
+
|
|
23
|
+
export default defineConfig({
|
|
24
|
+
language: "en-US",
|
|
25
|
+
reviews: { profile: "chill" },
|
|
26
|
+
})
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
`defineConfig` also accepts a factory that receives repository / organization /
|
|
30
|
+
pull-request and invocation context, so your config can adapt to _where_, _what_,
|
|
31
|
+
and _how_ it runs — something a static YAML file cannot do:
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import { defineConfig } from "@coderabbitai/config"
|
|
35
|
+
|
|
36
|
+
export default defineConfig(ctx => ({
|
|
37
|
+
reviews: {
|
|
38
|
+
// Keep local CLI reviews focused; use normal policy in the repository.
|
|
39
|
+
profile: ctx.invocation.source === "cli" ? "chill" : "assertive",
|
|
40
|
+
},
|
|
41
|
+
}))
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
`ctx.invocation.source` is `"cli"` for a local `coderabbit review` and
|
|
45
|
+
`"review"` for reviews initiated through an SCM provider or another review
|
|
46
|
+
client.
|
|
47
|
+
|
|
48
|
+
### Composing configs
|
|
49
|
+
|
|
50
|
+
`mergeConfig` deep-merges fragments (objects merge, arrays concatenate, later
|
|
51
|
+
scalars win), and `includeRemote` pulls a shared fragment from your
|
|
52
|
+
organization's `coderabbit` repository:
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import { defineConfig, mergeConfig, includeRemote } from "@coderabbitai/config"
|
|
56
|
+
|
|
57
|
+
const orgBase = includeRemote({ path: "base.ts" })
|
|
58
|
+
|
|
59
|
+
export default defineConfig(
|
|
60
|
+
mergeConfig(orgBase, { reviews: { profile: "assertive" } }),
|
|
61
|
+
)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## How it works
|
|
65
|
+
|
|
66
|
+
Your config is evaluated by CodeRabbit in an isolated, network-free sandbox and
|
|
67
|
+
validated against the same schema a `.coderabbit.yaml` uses. This package is
|
|
68
|
+
**author-time only** — it gives you types and autocomplete; the actual
|
|
69
|
+
evaluation happens server-side, so your config works whether or not the package
|
|
70
|
+
is installed. Installing it just makes your editor and CI aware of the config
|
|
71
|
+
shape.
|
|
72
|
+
|
|
73
|
+
## API
|
|
74
|
+
|
|
75
|
+
- `defineConfig(config | (ctx) => config)` — typed identity for your config.
|
|
76
|
+
- `mergeConfig(...fragments)` — deep-merge fragments (arrays concatenate).
|
|
77
|
+
- `includeRemote({ path, ref? })` — include a shared file from your org's
|
|
78
|
+
`coderabbit` repository.
|
|
79
|
+
- Types: `CodeRabbitConfig`, `CodeRabbitContext`,
|
|
80
|
+
`CodeRabbitInvocationContext`, `CodeRabbitInvocationSource`,
|
|
81
|
+
`ResolvedCodeRabbitContext`, `RemoteInclude`.
|
|
82
|
+
|
|
83
|
+
## License
|
|
84
|
+
|
|
85
|
+
[Apache-2.0](./LICENSE)
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
import type { getSchemaForExport } from "@coderabbitai/schemas";
|
|
3
|
+
/**
|
|
4
|
+
* The CodeRabbit configuration object, as authored in a `.coderabbit.config.ts`.
|
|
5
|
+
*
|
|
6
|
+
* This is exactly the surface of a `.coderabbit.yaml` file expressed as a
|
|
7
|
+
* TypeScript type. Every key is optional — you only specify what you want to
|
|
8
|
+
* override. It is the Zod *input* type for the production schema, so defaulted
|
|
9
|
+
* fields are not required.
|
|
10
|
+
*
|
|
11
|
+
* Derived here (in the SDK) from the schemas package's already-exported
|
|
12
|
+
* `getSchemaForExport`, which returns the *strict* schema — so unknown/misspelled
|
|
13
|
+
* top-level keys are flagged at author time in `defineConfig(...)`, while backend
|
|
14
|
+
* parsing stays lenient. Kept local to `@coderabbitai/config` rather than defined
|
|
15
|
+
* in `@coderabbitai/schemas` so the product-team-owned schema package needs no
|
|
16
|
+
* change. `import type` keeps this purely author-time: nothing from the schema
|
|
17
|
+
* package is pulled into the SDK's runtime bundle.
|
|
18
|
+
*
|
|
19
|
+
* SCHEMA SWITCH (pre-launch): programmatic configs are a new-schema-version-only
|
|
20
|
+
* feature (YAML spans both old and new; `.ts` is new-only). When the new Zod
|
|
21
|
+
* schema lands, repoint this alias at the new schema's strict input type. See the
|
|
22
|
+
* paired marker in `pr-reviewer-saas/src/settings/yaml.ts`
|
|
23
|
+
* (`prepareSettingsFromTypeScriptConfig`), which pins runtime validation of the
|
|
24
|
+
* `.ts` path to the new schema version.
|
|
25
|
+
*/
|
|
26
|
+
export type CodeRabbitConfig = z.input<ReturnType<typeof getSchemaForExport>>;
|
|
27
|
+
/** How CodeRabbit was invoked when evaluating a programmatic config. */
|
|
28
|
+
export type CodeRabbitInvocationSource = "cli" | "review";
|
|
29
|
+
/** Invocation metadata supplied when CodeRabbit evaluates a config factory. */
|
|
30
|
+
export interface CodeRabbitInvocationContext {
|
|
31
|
+
/**
|
|
32
|
+
* `"cli"` for a local `coderabbit review`; `"review"` for reviews initiated
|
|
33
|
+
* through an SCM provider or another review client.
|
|
34
|
+
*/
|
|
35
|
+
readonly source: CodeRabbitInvocationSource;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Runtime context passed to a config factory. It describes the repository,
|
|
39
|
+
* organization, and (for PR/MR events) the pull request being reviewed, so a
|
|
40
|
+
* config can adapt to *where* and *what* it is running against — something a
|
|
41
|
+
* static `.coderabbit.yaml` cannot do.
|
|
42
|
+
*
|
|
43
|
+
* The object is computed by CodeRabbit and injected into the sandbox at
|
|
44
|
+
* evaluation time. It contains only non-sensitive metadata; there are no
|
|
45
|
+
* tokens or secrets here.
|
|
46
|
+
*/
|
|
47
|
+
export interface CodeRabbitContext {
|
|
48
|
+
/**
|
|
49
|
+
* Identifies the product surface evaluating this config. Optional here to
|
|
50
|
+
* preserve source compatibility for consumers that construct this public
|
|
51
|
+
* context type; inferred config factories receive {@link ResolvedCodeRabbitContext}.
|
|
52
|
+
*/
|
|
53
|
+
readonly invocation?: CodeRabbitInvocationContext;
|
|
54
|
+
/**
|
|
55
|
+
* SCM provider the event came from, e.g. `"github"`, `"gitlab"`,
|
|
56
|
+
* `"azure-devops"`, `"bitbucket"`.
|
|
57
|
+
*/
|
|
58
|
+
readonly platform: string;
|
|
59
|
+
readonly repo: {
|
|
60
|
+
readonly owner: string;
|
|
61
|
+
readonly name: string;
|
|
62
|
+
/** Fully-qualified name / path-with-namespace, e.g. `"acme/api"`. */
|
|
63
|
+
readonly fullName: string;
|
|
64
|
+
/** Primary language reported by the provider, or `null` if unknown. */
|
|
65
|
+
readonly language: string | null;
|
|
66
|
+
/** `true` for a private repository. */
|
|
67
|
+
readonly isPrivate: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* `true` when the SCM is a customer-hosted instance (GHES, self-hosted
|
|
70
|
+
* GitLab, Bitbucket Data Center, …) rather than the provider's cloud.
|
|
71
|
+
*/
|
|
72
|
+
readonly isSelfHosted: boolean;
|
|
73
|
+
readonly defaultBranch: string;
|
|
74
|
+
};
|
|
75
|
+
/** The owning organization, or `null` if the provider has no org concept. */
|
|
76
|
+
readonly org: {
|
|
77
|
+
readonly name: string;
|
|
78
|
+
} | null;
|
|
79
|
+
/**
|
|
80
|
+
* Pull/merge request context. Present for PR/MR events; `null` for other
|
|
81
|
+
* events (or when PR details could not be resolved).
|
|
82
|
+
*/
|
|
83
|
+
readonly pr: {
|
|
84
|
+
readonly number: number;
|
|
85
|
+
readonly title: string;
|
|
86
|
+
/** Branch the PR merges into (base/target). */
|
|
87
|
+
readonly baseBranch: string;
|
|
88
|
+
/** Branch the PR is from (head/source). */
|
|
89
|
+
readonly headBranch: string;
|
|
90
|
+
/** Author's username/handle. */
|
|
91
|
+
readonly author: string;
|
|
92
|
+
/**
|
|
93
|
+
* Author's association with the repo, e.g. `"OWNER"`, `"MEMBER"`,
|
|
94
|
+
* `"COLLABORATOR"`, `"CONTRIBUTOR"`, `"FIRST_TIME_CONTRIBUTOR"`, `"NONE"`.
|
|
95
|
+
* `null` when the provider does not report it.
|
|
96
|
+
*/
|
|
97
|
+
readonly authorAssociation: string | null;
|
|
98
|
+
readonly labels: readonly string[];
|
|
99
|
+
readonly isDraft: boolean;
|
|
100
|
+
} | null;
|
|
101
|
+
}
|
|
102
|
+
/** Complete context CodeRabbit passes to an inferred config factory. */
|
|
103
|
+
export interface ResolvedCodeRabbitContext extends CodeRabbitContext {
|
|
104
|
+
readonly invocation: CodeRabbitInvocationContext;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* A config factory: returns the config object (or a promise of it), optionally
|
|
108
|
+
* using the {@link CodeRabbitContext} to compute values. This is the form you
|
|
109
|
+
* use when your config needs to adapt to the invocation source, repo, org, or
|
|
110
|
+
* pull request.
|
|
111
|
+
*/
|
|
112
|
+
export type CodeRabbitConfigFactory = (ctx: ResolvedCodeRabbitContext) => CodeRabbitConfig | Promise<CodeRabbitConfig>;
|
|
113
|
+
/**
|
|
114
|
+
* Define a CodeRabbit configuration with full type-checking and autocomplete.
|
|
115
|
+
*
|
|
116
|
+
* `defineConfig` is the entry point for a programmatic `.coderabbit.config.ts`.
|
|
117
|
+
* It is a typed identity function: it returns exactly what you pass in, but
|
|
118
|
+
* constrains it to the CodeRabbit config schema so typos and invalid values are
|
|
119
|
+
* caught in your editor instead of silently at review time.
|
|
120
|
+
*
|
|
121
|
+
* The value you return (or resolve, if you pass a factory) is evaluated by
|
|
122
|
+
* CodeRabbit in an isolated, network-free sandbox and validated against the
|
|
123
|
+
* schema before it is used — exactly as a `.coderabbit.yaml` would be. A
|
|
124
|
+
* committed `.coderabbit.yaml` always takes precedence over this file.
|
|
125
|
+
*
|
|
126
|
+
* @example Plain object
|
|
127
|
+
* ```ts
|
|
128
|
+
* import { defineConfig } from "@coderabbitai/config"
|
|
129
|
+
*
|
|
130
|
+
* export default defineConfig({
|
|
131
|
+
* language: "en-US",
|
|
132
|
+
* reviews: { profile: "chill" },
|
|
133
|
+
* })
|
|
134
|
+
* ```
|
|
135
|
+
*
|
|
136
|
+
* @example Factory with context
|
|
137
|
+
* ```ts
|
|
138
|
+
* import { defineConfig } from "@coderabbitai/config"
|
|
139
|
+
*
|
|
140
|
+
* export default defineConfig((ctx) => ({
|
|
141
|
+
* reviews: {
|
|
142
|
+
* // Keep local CLI reviews focused; use normal policy in the repository.
|
|
143
|
+
* profile: ctx.invocation.source === "cli" ? "chill" : "assertive",
|
|
144
|
+
* },
|
|
145
|
+
* }))
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
export declare function defineConfig(config: CodeRabbitConfig): CodeRabbitConfig;
|
|
149
|
+
export declare function defineConfig(config: CodeRabbitConfigFactory): CodeRabbitConfigFactory;
|
|
150
|
+
/**
|
|
151
|
+
* Deep-merge CodeRabbit config objects left-to-right and return the combined
|
|
152
|
+
* config. Use it to layer overrides onto a base config — e.g. applying
|
|
153
|
+
* context-driven changes on top of shared defaults.
|
|
154
|
+
*
|
|
155
|
+
* Merge rules:
|
|
156
|
+
* - **Objects** are merged recursively, so setting one nested key does not wipe
|
|
157
|
+
* its siblings (e.g. adding `reviews.tools.osv_scanner` keeps
|
|
158
|
+
* `reviews.tools.gitleaks`).
|
|
159
|
+
* - **Scalars**: the later config wins.
|
|
160
|
+
* - **Arrays** are **concatenated**, so list fields like `path_instructions`
|
|
161
|
+
* and `labeling_instructions` accumulate rather than replacing each other.
|
|
162
|
+
* - An omitted key never clobbers an existing value (pass an empty object to
|
|
163
|
+
* contribute nothing, which makes `cond ? fragment : {}` safe).
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```ts
|
|
167
|
+
* import { defineConfig, mergeConfig } from "@coderabbitai/config"
|
|
168
|
+
*
|
|
169
|
+
* const base = { reviews: { profile: "chill", tools: { gitleaks: { enabled: true } } } }
|
|
170
|
+
*
|
|
171
|
+
* export default defineConfig((ctx) =>
|
|
172
|
+
* mergeConfig(
|
|
173
|
+
* base,
|
|
174
|
+
* ctx.pr?.baseBranch.startsWith("release/")
|
|
175
|
+
* ? { reviews: { profile: "assertive", request_changes_workflow: true } }
|
|
176
|
+
* : {},
|
|
177
|
+
* ),
|
|
178
|
+
* )
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
export declare function mergeConfig(...configs: CodeRabbitConfig[]): CodeRabbitConfig;
|
|
182
|
+
/**
|
|
183
|
+
* Location of a shared config file, for {@link includeRemote}. The file is read
|
|
184
|
+
* from your organization's `coderabbit` configuration repository — the target
|
|
185
|
+
* repository is not (currently) configurable.
|
|
186
|
+
*/
|
|
187
|
+
export interface RemoteInclude {
|
|
188
|
+
/**
|
|
189
|
+
* File path within your org's `coderabbit` repository, e.g. `"base.ts"` or
|
|
190
|
+
* `"configs/base.yaml"`.
|
|
191
|
+
*/
|
|
192
|
+
readonly path: string;
|
|
193
|
+
/**
|
|
194
|
+
* Branch, tag, or commit SHA of the `coderabbit` repo. Optional — omit to
|
|
195
|
+
* track its default branch (so edits propagate automatically); pin it for
|
|
196
|
+
* reproducibility.
|
|
197
|
+
*/
|
|
198
|
+
readonly ref?: string;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Include a shared config from your organization's `coderabbit` repository,
|
|
202
|
+
* returning its config object to compose with {@link mergeConfig}:
|
|
203
|
+
*
|
|
204
|
+
* ```ts
|
|
205
|
+
* import { defineConfig, mergeConfig, includeRemote } from "@coderabbitai/config"
|
|
206
|
+
*
|
|
207
|
+
* const orgBase = includeRemote({ path: "base.ts" })
|
|
208
|
+
* export default defineConfig(mergeConfig(orgBase, { reviews: { profile: "assertive" } }))
|
|
209
|
+
* ```
|
|
210
|
+
*
|
|
211
|
+
* Shared files are always read from the `{owner}/coderabbit` repository (the
|
|
212
|
+
* same repo CodeRabbit uses for org-wide central config); the source repository
|
|
213
|
+
* is not configurable for now. The file is fetched (with your installation's
|
|
214
|
+
* read access) and evaluated in the same sandbox as your config.
|
|
215
|
+
*
|
|
216
|
+
* **This is a bundle-time directive**: the argument must be an inline object
|
|
217
|
+
* literal with string values (it is resolved before your config runs, so it
|
|
218
|
+
* cannot take computed/runtime values). CodeRabbit resolves the call during
|
|
219
|
+
* bundling; the runtime body below only executes if resolution was bypassed.
|
|
220
|
+
*/
|
|
221
|
+
export declare function includeRemote(spec: RemoteInclude): CodeRabbitConfig;
|
|
222
|
+
//# sourceMappingURL=define-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define-config.d.ts","sourceRoot":"","sources":["../src/define-config.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export function defineConfig(config) {
|
|
2
|
+
return config;
|
|
3
|
+
}
|
|
4
|
+
function isPlainObject(value) {
|
|
5
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
6
|
+
}
|
|
7
|
+
function deepMergeValues(a, b) {
|
|
8
|
+
if (b === undefined)
|
|
9
|
+
return a;
|
|
10
|
+
if (isPlainObject(a) && isPlainObject(b)) {
|
|
11
|
+
const result = { ...a };
|
|
12
|
+
for (const key of Object.keys(b)) {
|
|
13
|
+
result[key] = deepMergeValues(a[key], b[key]);
|
|
14
|
+
}
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
17
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
18
|
+
return [...a, ...b];
|
|
19
|
+
}
|
|
20
|
+
return b;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Deep-merge CodeRabbit config objects left-to-right and return the combined
|
|
24
|
+
* config. Use it to layer overrides onto a base config — e.g. applying
|
|
25
|
+
* context-driven changes on top of shared defaults.
|
|
26
|
+
*
|
|
27
|
+
* Merge rules:
|
|
28
|
+
* - **Objects** are merged recursively, so setting one nested key does not wipe
|
|
29
|
+
* its siblings (e.g. adding `reviews.tools.osv_scanner` keeps
|
|
30
|
+
* `reviews.tools.gitleaks`).
|
|
31
|
+
* - **Scalars**: the later config wins.
|
|
32
|
+
* - **Arrays** are **concatenated**, so list fields like `path_instructions`
|
|
33
|
+
* and `labeling_instructions` accumulate rather than replacing each other.
|
|
34
|
+
* - An omitted key never clobbers an existing value (pass an empty object to
|
|
35
|
+
* contribute nothing, which makes `cond ? fragment : {}` safe).
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* import { defineConfig, mergeConfig } from "@coderabbitai/config"
|
|
40
|
+
*
|
|
41
|
+
* const base = { reviews: { profile: "chill", tools: { gitleaks: { enabled: true } } } }
|
|
42
|
+
*
|
|
43
|
+
* export default defineConfig((ctx) =>
|
|
44
|
+
* mergeConfig(
|
|
45
|
+
* base,
|
|
46
|
+
* ctx.pr?.baseBranch.startsWith("release/")
|
|
47
|
+
* ? { reviews: { profile: "assertive", request_changes_workflow: true } }
|
|
48
|
+
* : {},
|
|
49
|
+
* ),
|
|
50
|
+
* )
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export function mergeConfig(...configs) {
|
|
54
|
+
return configs.reduce((acc, config) => deepMergeValues(acc, config), {});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Include a shared config from your organization's `coderabbit` repository,
|
|
58
|
+
* returning its config object to compose with {@link mergeConfig}:
|
|
59
|
+
*
|
|
60
|
+
* ```ts
|
|
61
|
+
* import { defineConfig, mergeConfig, includeRemote } from "@coderabbitai/config"
|
|
62
|
+
*
|
|
63
|
+
* const orgBase = includeRemote({ path: "base.ts" })
|
|
64
|
+
* export default defineConfig(mergeConfig(orgBase, { reviews: { profile: "assertive" } }))
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* Shared files are always read from the `{owner}/coderabbit` repository (the
|
|
68
|
+
* same repo CodeRabbit uses for org-wide central config); the source repository
|
|
69
|
+
* is not configurable for now. The file is fetched (with your installation's
|
|
70
|
+
* read access) and evaluated in the same sandbox as your config.
|
|
71
|
+
*
|
|
72
|
+
* **This is a bundle-time directive**: the argument must be an inline object
|
|
73
|
+
* literal with string values (it is resolved before your config runs, so it
|
|
74
|
+
* cannot take computed/runtime values). CodeRabbit resolves the call during
|
|
75
|
+
* bundling; the runtime body below only executes if resolution was bypassed.
|
|
76
|
+
*/
|
|
77
|
+
export function includeRemote(spec) {
|
|
78
|
+
void spec;
|
|
79
|
+
throw new Error("includeRemote() is resolved at build time by CodeRabbit and cannot be called at runtime.");
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=define-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define-config.js","sourceRoot":"","sources":["../src/define-config.ts"],"names":[],"mappings":"AAgKA,MAAM,UAAU,YAAY,CAC3B,MAAkD;IAElD,OAAO,MAAM,CAAA;AACd,CAAC;AAED,SAAS,aAAa,CAAC,KAAc;IACpC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;AAC5E,CAAC;AAcD,SAAS,eAAe,CAAC,CAAU,EAAE,CAAU;IAC9C,IAAI,CAAC,KAAK,SAAS;QAAE,OAAO,CAAC,CAAA;IAC7B,IAAI,aAAa,CAAC,CAAC,CAAC,IAAI,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC;QAC1C,MAAM,MAAM,GAA4B,EAAE,GAAG,CAAC,EAAE,CAAA;QAChD,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;YAClC,MAAM,CAAC,GAAG,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;QAC9C,CAAC;QACD,OAAO,MAAM,CAAA;IACd,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;QAC1C,OAAO,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,CAAA;IACpB,CAAC;IACD,OAAO,CAAC,CAAA;AACT,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,UAAU,WAAW,CAAC,GAAG,OAA2B;IACzD,OAAO,OAAO,CAAC,MAAM,CACpB,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,CAAC,eAAe,CAAC,GAAG,EAAE,MAAM,CAAC,EAC7C,EAAE,CACF,CAAA;AACF,CAAC;AAqBD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,aAAa,CAAC,IAAmB;IAChD,KAAK,IAAI,CAAA;IACT,MAAM,IAAI,KAAK,CACd,0FAA0F,CAC1F,CAAA;AACF,CAAC"}
|