UNPKG

10.6 kBTypeScriptView Raw
1import { ReposCreateReleaseResponse, Response } from '@octokit/rest';
2import { AsyncParallelHook, AsyncSeriesBailHook, SyncHook, SyncWaterfallHook, AsyncSeriesHook, AsyncSeriesWaterfallHook } from 'tapable';
3import { ApiOptions, ICanaryOptions, IChangelogOptions, ICommentOptions, ICreateLabelsOptions, IInitOptions, 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, { IAutoConfig, ILabelDefinition } from './release';
8import SEMVER, { IVersionLabels } from './semver';
9import { ILogger } from './utils/logger';
10import { IAuthorOptions, IRepoOptions } from './auto-args';
11interface ChangelogLifecycle {
12 /** The bump being applied to the version */
13 bump: SEMVER;
14 /** The commits included in the changelog */
15 commits: IExtendedCommit[];
16 /** The generated release notes for the commits */
17 releaseNotes: string;
18 /** The current version of the project */
19 currentVersion: string;
20 /** The last version of the project */
21 lastRelease: string;
22}
23interface TestingToken {
24 /** A token used for testing */
25 token?: string;
26}
27export interface IAutoHooks {
28 /** Modify what is in the config. You must return the config in this hook. */
29 modifyConfig: SyncWaterfallHook<[IAutoConfig]>;
30 /** Happens before anything is done. This is a great place to check for platform specific secrets. */
31 beforeRun: SyncHook<[IAutoConfig]>;
32 /** Happens before `shipit` is run. This is a great way to throw an error if a token or key is not present. */
33 beforeShipIt: SyncHook<[]>;
34 /** Ran before the `changelog` command commits the new release notes to `CHANGELOG.md`. */
35 beforeCommitChangelog: AsyncSeriesHook<[ChangelogLifecycle]>;
36 /** Ran after the `changelog` command adds the new release notes to `CHANGELOG.md`. */
37 afterAddToChangelog: AsyncSeriesHook<[ChangelogLifecycle]>;
38 /** Ran after the `shipit` command has run. */
39 afterShipIt: AsyncParallelHook<[string | undefined, IExtendedCommit[]]>;
40 /** Ran after the `release` command has run. */
41 afterRelease: AsyncParallelHook<[{
42 /** The last version released */
43 lastRelease: string;
44 /** The version being released */
45 newVersion?: string;
46 /** The commits included in the release */
47 commits: IExtendedCommit[];
48 /** The generated release notes for the commits */
49 releaseNotes: string;
50 /** The response from creating the new release. */
51 response?: Response<ReposCreateReleaseResponse>;
52 }]>;
53 /** Get git author. Typically from a package distribution description file. */
54 getAuthor: AsyncSeriesBailHook<[], IAuthorOptions | void>;
55 /** Get the previous version. Typically from a package distribution description file. */
56 getPreviousVersion: AsyncSeriesBailHook<[], string>;
57 /** Get owner and repository. Typically from a package distribution description file. */
58 getRepository: AsyncSeriesBailHook<[], (IRepoOptions & TestingToken) | void>;
59 /** 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. */
60 onCreateRelease: SyncHook<[Release]>;
61 /** This is where you hook into the LogParse's hooks. This hook is exposed for convenience on during `this.hooks.onCreateRelease` and at the root `this.hooks` */
62 onCreateLogParse: SyncHook<[LogParse]>;
63 /** This is where you hook into the changelog's hooks. This hook is exposed for convenience on during `this.hooks.onCreateRelease` and at the root `this.hooks` */
64 onCreateChangelog: SyncHook<[Changelog, SEMVER | undefined]>;
65 /** Version the package. This is a good opportunity to `git tag` the release also. */
66 version: AsyncParallelHook<[SEMVER]>;
67 /** Ran after the package has been versioned. */
68 afterVersion: AsyncParallelHook<[]>;
69 /** Publish the package to some package distributor. You must push the tags to github! */
70 publish: AsyncParallelHook<[SEMVER]>;
71 /** Used to publish a canary release. In this hook you get the semver bump and the unique canary postfix ID. */
72 canary: AsyncSeriesBailHook<[SEMVER, string], string | {
73 /** Error when creating the canary release */
74 error: string;
75 }>;
76 /**
77 * Used to publish a next release. In this hook you get the semver bump
78 * and an array of next versions that been released. If you make another
79 * next release be sure to add it the the array.
80 */
81 next: AsyncSeriesWaterfallHook<[string[], SEMVER]>;
82 /** Ran after the package has been published. */
83 afterPublish: AsyncParallelHook<[]>;
84}
85/**
86 * Bump the version but no too much.
87 *
88 * @example
89 * currentVersion = 1.0.0
90 * nextVersion = 2.0.0-next.0
91 * output = 2.0.0-next.1
92 */
93export declare function determineNextVersion(lastVersion: string, currentVersion: string, bump: SEMVER, tag: string): string;
94/**
95 * The "auto" node API. Its public interface matches the
96 * commands you can run from the CLI
97 */
98export default class Auto {
99 /** Plugin entry points */
100 hooks: IAutoHooks;
101 /** A logger that uses log levels */
102 logger: ILogger;
103 /** Options auto was initialized with */
104 options: ApiOptions;
105 /** The branch auto uses as master. */
106 baseBranch: string;
107 /** The user configuration of auto (.autorc) */
108 config?: IAutoConfig;
109 /** A class that handles creating releases */
110 release?: Release;
111 /** A class that handles interacting with git and GitHub */
112 git?: Git;
113 /** The labels configured by the user */
114 labels?: ILabelDefinition[];
115 /** A map of semver bumps to labels that signify those bumps */
116 semVerLabels?: IVersionLabels;
117 /** The version bump being used during "shipit" */
118 private versionBump?;
119 /** Initialize auto and it's environment */
120 constructor(options?: ApiOptions);
121 /**
122 * Load the .autorc from the file system, set up defaults, combine with CLI args
123 * load the extends property, load the plugins and start the git remote interface.
124 */
125 loadConfig(): Promise<void>;
126 /**
127 * Interactive prompt for initializing an .autorc
128 */
129 init(options?: IInitOptions): Promise<void>;
130 /**
131 * Create all of the user's labels on the git remote if the don't already exist
132 *
133 * @param options - Options for the createLabels functionality
134 */
135 createLabels(options?: ICreateLabelsOptions): Promise<void>;
136 /**
137 * Get the labels on a specific PR. Defaults to the labels of the last merged PR
138 *
139 * @param options - Options for the createLabels functionality
140 */
141 label({ pr }?: ILabelOptions): Promise<void>;
142 /**
143 * Create a status on a PR.
144 *
145 * @param options - Options for the pr status functionality
146 */
147 prStatus({ dryRun, pr, url, ...options }: IPRStatusOptions): Promise<void>;
148 /**
149 * Check that a PR has a SEMVER label. Set a success status on the PR.
150 *
151 * @param options - Options for the pr check functionality
152 */
153 prCheck({ dryRun, pr, url, ...options }: IPRCheckOptions): Promise<void>;
154 /**
155 * Comment on a PR. Only one comment will be present on the PR, Older comments are removed.
156 * You can use the "context" option to multiple comments on a PR.
157 *
158 * @param options - Options for the comment functionality
159 */
160 comment(options: ICommentOptions): Promise<void>;
161 /**
162 * Update the body of a PR with a message. Only one message will be present in the PR,
163 * Older messages are removed. You can use the "context" option to multiple message
164 * in a PR body.
165 *
166 * @param options - Options
167 */
168 prBody(options: ICommentOptions): Promise<void>;
169 /**
170 * Calculate the version bump for the current state of the repository.
171 */
172 version(options?: IVersionOptions): Promise<void>;
173 /**
174 * Calculate the the changelog and commit it.
175 */
176 changelog(options?: IChangelogOptions): Promise<void>;
177 /**
178 * Make a release to the git remote with the changes.
179 */
180 runRelease(options?: IReleaseOptions): Promise<void>;
181 /** Create a canary (or test) version of the project */
182 canary(options?: ICanaryOptions): Promise<{
183 newVersion: string;
184 commitsInRelease: IExtendedCommit[];
185 } | undefined>;
186 /**
187 * Create a next (or test) version of the project. If on master will
188 * release to the default "next" branch.
189 */
190 next(options: INextOptions): Promise<{
191 newVersion: string;
192 commitsInRelease: IExtendedCommit[];
193 }>;
194 /**
195 * Run the full workflow.
196 *
197 * 1. Calculate version
198 * 2. Make changelog
199 * 3. Publish code
200 * 4. Create a release
201 */
202 shipit(options?: IShipItOptions): Promise<void>;
203 /** Get the latest version number of the project */
204 getCurrentVersion(lastRelease: string): Promise<string>;
205 /**
206 * A utility function for plugins to check the process for tokens.
207 */
208 checkEnv(pluginName: string, key: string): void;
209 /** On master: publish a new latest version */
210 private publishLatest;
211 /** Get a pr number from user input or the env */
212 private getPrNumber;
213 /** Create a client to interact with git */
214 private startGit;
215 /** Calculate a version from a tag using labels */
216 private getVersion;
217 /** Make a changelog over a range of commits */
218 private makeChangelog;
219 /** Make a release over a range of commits */
220 private makeRelease;
221 /** Check if `git status` is clean. */
222 readonly checkClean: () => Promise<void>;
223 /** Prefix a version with a "v" if needed */
224 readonly prefixRelease: (release: string) => string;
225 /** Create an auto initialization error */
226 private createErrorMessage;
227 /**
228 * Set the git user to make releases and commit with.
229 */
230 private setGitUser;
231 /** Get the repo to interact with */
232 private getRepo;
233 /**
234 * Apply all of the plugins in the config.
235 */
236 private loadPlugins;
237}
238export * from './auto-args';
239export { ILogger } from './utils/logger';
240export { IPlugin } from './utils/load-plugins';
241export { default as Auto } from './auto';
242export { default as SEMVER } from './semver';
243export { default as execPromise } from './utils/exec-promise';
244export { VersionLabel } from './release';
245//# sourceMappingURL=auto.d.ts.map
\No newline at end of file