UNPKG

4.02 kBTypeScriptView Raw
1import { AsyncSeriesBailHook, SyncHook } from 'tapable';
2import { ICreateLabelsOptions } from './auto-args';
3import Changelog from './changelog';
4import Git from './git';
5import LogParse, { IExtendedCommit } from './log-parse';
6import SEMVER from './semver';
7import { ILogger } from './utils/logger';
8export declare type VersionLabel = SEMVER.major | SEMVER.minor | SEMVER.patch | 'skip-release' | 'release' | 'prerelease';
9export declare const defaultLabels: VersionLabel[];
10export declare const isVersionLabel: (label: string) => label is VersionLabel;
11export interface IAutoConfig {
12 githubApi?: string;
13 baseBranch: string;
14 githubGraphqlApi?: string;
15 name?: string;
16 email?: string;
17 owner?: string;
18 repo?: string;
19 skipReleaseLabels: string[];
20 onlyPublishWithReleaseLabel?: boolean;
21 noVersionPrefix?: boolean;
22 plugins?: (string | [string, any])[];
23 labels: ILabelDefinitionMap;
24}
25export interface ILabelDefinition {
26 name: string;
27 title?: string;
28 color?: string;
29 description?: string;
30}
31export interface ILabelDefinitionMap {
32 [label: string]: ILabelDefinition;
33}
34export declare const defaultLabelDefinition: ILabelDefinitionMap;
35export declare const getVersionMap: (labels?: ILabelDefinitionMap) => Map<VersionLabel, string>;
36export interface IReleaseHooks {
37 onCreateChangelog: SyncHook<[Changelog, SEMVER | undefined]>;
38 createChangelogTitle: AsyncSeriesBailHook<[], string | void>;
39 onCreateLogParse: SyncHook<[LogParse]>;
40}
41export declare function buildSearchQuery(owner: string, project: string, commits: IExtendedCommit[]): string | undefined;
42/**
43 * A class for interacting with the git remote
44 */
45export default class Release {
46 readonly options: IAutoConfig;
47 readonly hooks: IReleaseHooks;
48 private readonly git;
49 private readonly logger;
50 private readonly versionLabels;
51 constructor(git: Git, options?: IAutoConfig, logger?: ILogger);
52 /**
53 * Generate a changelog from a range of commits.
54 *
55 * @param from sha or tag to start changelog from
56 * @param to sha or tag to end changelog at (defaults to HEAD)
57 */
58 generateReleaseNotes(from: string, to?: string, version?: SEMVER): Promise<string>;
59 getCommitsInRelease(from: string, to?: string): Promise<IExtendedCommit[]>;
60 /**
61 * Prepend a set of release notes to the changelog.md
62 *
63 * @param releaseNotes Release notes to prepend to the changelog
64 * @param lastRelease Last release version of the code. Could be the first commit SHA
65 * @param currentVersion Current version of the code
66 * @param message Message to commit the changelog with
67 */
68 addToChangelog(releaseNotes: string, lastRelease: string, currentVersion: string, message?: string): Promise<void>;
69 /**
70 * Get a range of commits. The commits will have PR numbers and labels attached
71 *
72 * @param from Tag or SHA to start at
73 * @param to Tag or SHA to end at (defaults to HEAD)
74 */
75 getCommits(from: string, to?: string): Promise<IExtendedCommit[]>;
76 addLabelsToProject(labels: Partial<ILabelDefinitionMap>, options?: ICreateLabelsOptions): Promise<void>;
77 /**
78 * Calculate the SEMVER bump over a range of commits using the PR labels
79 *
80 * @param from Tag or SHA to start at
81 * @param to Tag or SHA to end at (defaults to HEAD)
82 */
83 getSemverBump(from: string, to?: string): Promise<SEMVER>;
84 calcNextVersion(lastTag: string): Promise<string | null>;
85 private createLogParse;
86 private getPRsSinceLastRelease;
87 /**
88 * Add the PR info (labels and body) to the commit
89 *
90 * @param commits Commits to modify
91 */
92 private addPrInfoToCommit;
93 /**
94 * Commits from rebased PRs do not have messages that tie them to a PR
95 * Instead we have to find all PRs since the last release and try to match
96 * their merge commit SHAs.
97 *
98 * @param commits Commits to modify
99 */
100 private getPRForRebasedCommits;
101 private attachAuthor;
102}