UNPKG

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