UNPKG

15.5 kBTypeScriptView Raw
1import { RestEndpointMethodTypes } from "@octokit/rest";
2import { AsyncParallelHook, AsyncSeriesBailHook, SyncHook, SyncWaterfallHook, AsyncSeriesHook, AsyncSeriesWaterfallHook } from "tapable";
3import { ApiOptions, IInfoOptions, ICanaryOptions, IChangelogOptions, ICommentOptions, ICreateLabelsOptions, ILabelOptions, IPRCheckOptions, IPRStatusOptions, IReleaseOptions, IShipItOptions, IVersionOptions, INextOptions } from "./auto-args";
4import Changelog from "./changelog";
5import Git from "./git";
6import LogParse, { IExtendedCommit } from "./log-parse";
7import Release, { ILabelDefinition } from "./release";
8import SEMVER, { IVersionLabels } from "./semver";
9import { ILogger } from "./utils/logger";
10import { RepoInformation, AuthorInformation, LoadedAutoRc } from "./types";
11import { ValidatePluginHook } from "./validate-config";
12interface ChangelogLifecycle {
13 /** The bump being applied to the version */
14 bump: SEMVER;
15 /** The commits included in the changelog */
16 commits: IExtendedCommit[];
17 /** The generated release notes for the commits */
18 releaseNotes: string;
19 /** The current version of the project */
20 currentVersion: string;
21 /** The last version of the project */
22 lastRelease: string;
23}
24interface TestingToken {
25 /** A token used for testing */
26 token?: string;
27}
28declare type ShipitContext = "canary" | "next" | "latest" | "old";
29interface ShipitInfo {
30 /** The Version published when shipit ran */
31 newVersion?: string;
32 /** The commits released during shipit */
33 commitsInRelease: IExtendedCommit[];
34 /** The type of release made */
35 context: ShipitContext;
36}
37declare type ShipitRelease = "latest" | "old" | "next" | "canary";
38interface BeforeShipitContext {
39 /** The type of release that will be made when shipit runs. */
40 releaseType: ShipitRelease;
41}
42interface NextContext {
43 /** The commits in the next release */
44 commits: IExtendedCommit[];
45 /** The release notes for all the commits in the next release */
46 fullReleaseNotes: string;
47 /** The release notes for the last change merged to the next release */
48 releaseNotes: string;
49}
50declare type PublishResponse = RestEndpointMethodTypes["repos"]["createRelease"]["response"];
51export interface IAutoHooks {
52 /** Modify what is in the config. You must return the config in this hook. */
53 modifyConfig: SyncWaterfallHook<[LoadedAutoRc]>;
54 /** Validate what is in the config. You must return the config in this hook. */
55 validateConfig: ValidatePluginHook;
56 /** Happens before anything is done. This is a great place to check for platform specific secrets. */
57 beforeRun: AsyncSeriesHook<[LoadedAutoRc]>;
58 /** Happens before `shipit` is run. This is a great way to throw an error if a token or key is not present. */
59 beforeShipIt: AsyncSeriesHook<[BeforeShipitContext]>;
60 /** Ran before the `changelog` command commits the new release notes to `CHANGELOG.md`. */
61 beforeCommitChangelog: AsyncSeriesHook<[ChangelogLifecycle]>;
62 /** Ran after the `changelog` command adds the new release notes to `CHANGELOG.md`. */
63 afterAddToChangelog: AsyncSeriesHook<[ChangelogLifecycle]>;
64 /** Ran after the `shipit` command has run. */
65 afterShipIt: AsyncParallelHook<[string | undefined, IExtendedCommit[], {
66 /** The type of release made by shipit */
67 context: ShipitContext;
68 }]>;
69 /** Ran after the `release` command has run. */
70 afterRelease: AsyncParallelHook<[{
71 /** The last version released */
72 lastRelease: string;
73 /** The version being released */
74 newVersion?: string;
75 /** The commits included in the release */
76 commits: IExtendedCommit[];
77 /** The generated release notes for the commits */
78 releaseNotes: string;
79 /** The response from creating the new release. */
80 response?: PublishResponse | PublishResponse[];
81 }]>;
82 /** Override what happens when "releasing" code to a Github release */
83 makeRelease: AsyncSeriesBailHook<[{
84 /** Do not actually do anything */
85 dryRun?: boolean;
86 /** Commit to start calculating the version from */
87 from: string;
88 /** The version being released */
89 newVersion: string;
90 /** Whether the release being made is a prerelease */
91 isPrerelease?: boolean;
92 /** The generated release notes for the commits */
93 fullReleaseNotes: string;
94 /** The commits included in the release */
95 commits: IExtendedCommit[];
96 }], PublishResponse | PublishResponse[] | void>;
97 /** Get git author. Typically from a package distribution description file. */
98 getAuthor: AsyncSeriesBailHook<[], Partial<AuthorInformation> | void>;
99 /** Get the previous version. Typically from a package distribution description file. */
100 getPreviousVersion: AsyncSeriesBailHook<[], string>;
101 /** Get owner and repository. Typically from a package distribution description file. */
102 getRepository: AsyncSeriesBailHook<[], (RepoInformation & TestingToken) | void>;
103 /** Tap into the things the Release class makes. This isn't the same as `auto release`, but the main class that does most of the work. */
104 onCreateRelease: SyncHook<[Release]>;
105 /**
106 * This is where you hook into the LogParse's hooks.
107 * This hook is exposed for convenience during `this.hooks.onCreateRelease` and at the root `this.hooks`
108 */
109 onCreateLogParse: SyncHook<[LogParse]>;
110 /**
111 * This is where you hook into the changelog's hooks.
112 * This hook is exposed for convenience during `this.hooks.onCreateRelease` and at the root `this.hooks`
113 */
114 onCreateChangelog: SyncHook<[Changelog, SEMVER | undefined]>;
115 /** Version the package. This is a good opportunity to `git tag` the release also. */
116 version: AsyncParallelHook<[SEMVER]>;
117 /** Ran after the package has been versioned. */
118 afterVersion: AsyncParallelHook<[]>;
119 /** Publish the package to some package distributor. You must push the tags to github! */
120 publish: AsyncParallelHook<[SEMVER]>;
121 /** Used to publish a canary release. In this hook you get the semver bump and the unique canary postfix ID. */
122 canary: AsyncSeriesBailHook<[SEMVER, string], string | {
123 /** A summary to use in a details html element */
124 newVersion: string;
125 /** The details to use in a details html element */
126 details: string;
127 } | {
128 /** Error when creating the canary release */
129 error: string;
130 } | void>;
131 /**
132 * Used to publish a next release. In this hook you get the semver bump
133 * and an array of next versions that been released. If you make another
134 * next release be sure to add it the the array.
135 */
136 next: AsyncSeriesWaterfallHook<[string[], SEMVER, NextContext]>;
137 /** Ran after the package has been published. */
138 afterPublish: AsyncParallelHook<[]>;
139}
140/**
141 * Bump the version but no too much.
142 *
143 * @example
144 * currentVersion = 1.0.0
145 * nextVersion = 2.0.0-next.0
146 * output = 2.0.0-next.1
147 */
148export declare function determineNextVersion(lastVersion: string, currentVersion: string, bump: SEMVER, tag?: string): string;
149/** Print the current version of "auto" */
150export declare function getAutoVersion(): any;
151/**
152 * The "auto" node API. Its public interface matches the
153 * commands you can run from the CLI
154 */
155export default class Auto {
156 /** Plugin entry points */
157 hooks: IAutoHooks;
158 /** A logger that uses log levels */
159 logger: ILogger;
160 /** Options auto was initialized with */
161 options: ApiOptions;
162 /** The branch auto uses as master. */
163 baseBranch: string;
164 /** The remote git to push changes to. This is the full URL with auth */
165 remote: string;
166 /** The user configuration of auto (.autorc) */
167 config?: LoadedAutoRc;
168 /** A class that handles creating releases */
169 release?: Release;
170 /** A class that handles interacting with git and GitHub */
171 git?: Git;
172 /** The labels configured by the user */
173 labels?: ILabelDefinition[];
174 /** A map of semver bumps to labels that signify those bumps */
175 semVerLabels?: IVersionLabels;
176 /** The version bump being used during "shipit" */
177 private versionBump?;
178 /** Initialize auto and it's environment */
179 constructor(options?: ApiOptions);
180 /** List some of the plugins available to auto */
181 private listPlugins;
182 /**
183 * Load the default hook behaviors. Should run after loadPlugins so
184 * plugins take precedence.
185 */
186 private loadDefaultBehavior;
187 /**
188 * Load the .autorc from the file system, set up defaults, combine with CLI args
189 * load the extends property, load the plugins and start the git remote interface.
190 */
191 loadConfig(): Promise<{
192 baseBranch: string;
193 extends?: string | undefined;
194 labels: ({
195 changelogTitle?: string | undefined;
196 color?: string | undefined;
197 description?: string | undefined;
198 releaseType?: "none" | SEMVER.major | SEMVER.minor | SEMVER.patch | "skip" | "release" | undefined;
199 overwrite?: boolean | undefined;
200 } & {
201 name: string;
202 })[];
203 prereleaseBranches: string[];
204 plugins?: (string | [string, any])[] | undefined;
205 noVersionPrefix?: boolean | undefined;
206 versionBranches?: string | boolean | undefined;
207 comment?: {
208 delete?: boolean | undefined;
209 edit?: boolean | undefined;
210 } | undefined;
211 changelog?: {
212 message?: string | undefined;
213 } | undefined;
214 release?: {
215 prerelease?: boolean | undefined;
216 } | undefined;
217 shipit?: {
218 onlyGraduateWithReleaseLabel?: boolean | undefined;
219 } | undefined;
220 canary?: {
221 force?: boolean | undefined;
222 message?: string | false | undefined;
223 } | undefined;
224 next?: {
225 message?: string | undefined;
226 } | undefined;
227 repo?: string | undefined;
228 owner?: string | undefined;
229 githubApi?: string | undefined;
230 githubGraphqlApi?: string | undefined;
231 name?: string | undefined;
232 email?: string | undefined;
233 onlyPublishWithReleaseLabel?: boolean | undefined;
234 verbose?: boolean | [boolean, boolean] | undefined;
235 }>;
236 /** Determine the remote we have auth to push to. */
237 private getRemote;
238 /** Interactive prompt for initializing an .autorc */
239 init(): Promise<void>;
240 /** Check if auto is set up correctly */
241 info(args: IInfoOptions): Promise<{
242 hasError: boolean;
243 }>;
244 /** Determine if the repo is currently in a prerelease branch */
245 inPrereleaseBranch(): boolean;
246 /** Determine if the repo is currently in a old-version branch */
247 inOldVersionBranch(): boolean;
248 /**
249 * Create all of the user's labels on the git remote if the don't already exist
250 */
251 createLabels(options?: ICreateLabelsOptions): Promise<void>;
252 /**
253 * Get the labels on a specific PR. Defaults to the labels of the last merged PR
254 */
255 label({ pr }?: ILabelOptions): Promise<void>;
256 /**
257 * Create a status on a PR.
258 */
259 prStatus({ dryRun, pr, url, ...options }: IPRStatusOptions): Promise<void>;
260 /**
261 * Check that a PR has a SEMVER label. Set a success status on the PR.
262 */
263 prCheck({ dryRun, pr, url, ...options }: IPRCheckOptions): Promise<void>;
264 /**
265 * Comment on a PR. Only one comment will be present on the PR, Older comments are removed.
266 * You can use the "context" option to multiple comments on a PR.
267 */
268 comment(args: ICommentOptions): Promise<void>;
269 /**
270 * Update the body of a PR with a message. Only one message will be present in the PR,
271 * Older messages are removed. You can use the "context" option to multiple message
272 * in a PR body.
273 */
274 prBody(options: ICommentOptions): Promise<void>;
275 /**
276 * Calculate the version bump for the current state of the repository.
277 */
278 version(options?: IVersionOptions): Promise<void>;
279 /**
280 * Calculate the the changelog and commit it.
281 */
282 changelog(options?: IChangelogOptions): Promise<void>;
283 /**
284 * Make a release to the git remote with the changes.
285 */
286 runRelease(options?: IReleaseOptions): Promise<void>;
287 /** Create a canary (or test) version of the project */
288 canary(args?: ICanaryOptions): Promise<ShipitInfo | undefined>;
289 /**
290 * Create a next (or test) version of the project. If on master will
291 * release to the default "next" branch.
292 */
293 next(args: INextOptions): Promise<ShipitInfo | undefined>;
294 /** Force a release to latest and bypass `shipit` safeguards. */
295 latest(args?: IShipItOptions): Promise<ShipitInfo | undefined>;
296 /**
297 * Run the full workflow.
298 *
299 * 1. Calculate version
300 * 2. Make changelog
301 * 3. Publish code
302 * 4. Create a release
303 */
304 shipit(args?: IShipItOptions): Promise<void>;
305 /** Get the latest version number of the project */
306 getCurrentVersion(lastRelease: string): Promise<string>;
307 /**
308 * A utility function for plugins to check the process for tokens.
309 */
310 checkEnv(pluginName: string, key: string): void;
311 /** Make a release to an old version */
312 private oldRelease;
313 /** Publish a new version with changelog, publish, and release */
314 private publishFullRelease;
315 /** Get a pr number from user input or the env */
316 private getPrNumber;
317 /** Create a client to interact with git */
318 private startGit;
319 /** Calculate a version from a tag using labels */
320 getVersion({ from }?: IVersionOptions): Promise<SEMVER>;
321 /** Make a changelog over a range of commits */
322 private makeChangelog;
323 /** Make a release over a range of commits */
324 private makeRelease;
325 /** Check if `git status` is clean. */
326 readonly checkClean: () => Promise<void>;
327 /** Prefix a version with a "v" if needed */
328 readonly prefixRelease: (release: string) => string;
329 /** Create an auto initialization error */
330 private createErrorMessage;
331 /** Get the current git user */
332 private getGitUser;
333 /**
334 * Set the git user to make releases and commit with.
335 */
336 setGitUser(): Promise<void>;
337 /** Get the repo to interact with */
338 private getRepo;
339 /** Find the location of the extended configuration */
340 private getExtendedLocation;
341 /**
342 * Apply all of the plugins in the config.
343 */
344 private loadPlugins;
345 /** Get the branch and build number when in CI environment */
346 private getPrEnvInfo;
347 /** Get the default for a command from the config */
348 private getCommandDefault;
349}
350export * from "./auto-args";
351export { default as InteractiveInit } from "./init";
352export { getCurrentBranch } from "./utils/get-current-branch";
353export { validatePluginConfiguration } from "./validate-config";
354export { ILogger } from "./utils/logger";
355export { IPlugin } from "./utils/load-plugins";
356export { ICommitAuthor, IExtendedCommit } from "./log-parse";
357export { default as Auto } from "./auto";
358export { default as SEMVER } from "./semver";
359export { default as execPromise } from "./utils/exec-promise";
360export { default as getLernaPackages } from "./utils/get-lerna-packages";
361export { default as inFolder } from "./utils/in-folder";
362export { VersionLabel } from "./release";
363//# sourceMappingURL=auto.d.ts.map
\No newline at end of file