release-please 17.4.0 → 17.5.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.
Files changed (34) hide show
  1. package/build/src/bin/release-please.js +39 -10
  2. package/build/src/bootstrapper.d.ts +2 -2
  3. package/build/src/changelog-notes/default.js +9 -1
  4. package/build/src/changelog-notes/github.d.ts +2 -2
  5. package/build/src/changelog-notes.d.ts +1 -0
  6. package/build/src/commit.d.ts +6 -0
  7. package/build/src/factories/changelog-notes-factory.d.ts +2 -2
  8. package/build/src/factories/plugin-factory.d.ts +2 -2
  9. package/build/src/factories/versioning-strategy-factory.d.ts +2 -2
  10. package/build/src/factory.d.ts +2 -2
  11. package/build/src/github-api.d.ts +260 -0
  12. package/build/src/github-api.js +701 -0
  13. package/build/src/github.d.ts +21 -171
  14. package/build/src/github.js +154 -687
  15. package/build/src/index.d.ts +2 -2
  16. package/build/src/index.js +1 -1
  17. package/build/src/local-github.d.ts +271 -0
  18. package/build/src/local-github.js +776 -0
  19. package/build/src/manifest.d.ts +7 -5
  20. package/build/src/manifest.js +28 -26
  21. package/build/src/plugin.d.ts +3 -3
  22. package/build/src/plugins/group-priority.d.ts +2 -2
  23. package/build/src/plugins/linked-versions.d.ts +2 -2
  24. package/build/src/plugins/maven-workspace.d.ts +2 -2
  25. package/build/src/plugins/merge.d.ts +2 -2
  26. package/build/src/plugins/node-workspace.d.ts +2 -2
  27. package/build/src/plugins/sentence-case.d.ts +2 -2
  28. package/build/src/plugins/workspace.d.ts +2 -2
  29. package/build/src/scm.d.ts +80 -0
  30. package/build/src/scm.js +16 -0
  31. package/build/src/strategies/base.d.ts +5 -3
  32. package/build/src/strategies/base.js +2 -0
  33. package/build/src/util/pull-request-overflow-handler.d.ts +2 -2
  34. package/package.json +3 -3
@@ -18,12 +18,14 @@ exports.handleError = exports.parser = void 0;
18
18
  const coerce_option_1 = require("../util/coerce-option");
19
19
  const yargs = require("yargs");
20
20
  const github_1 = require("../github");
21
+ const github_api_1 = require("../github-api");
21
22
  const manifest_1 = require("../manifest");
22
23
  const changelog_notes_1 = require("../changelog-notes");
23
24
  const logger_1 = require("../util/logger");
24
25
  const factory_1 = require("../factory");
25
26
  const bootstrapper_1 = require("../bootstrapper");
26
27
  const diff_1 = require("diff");
28
+ const local_github_1 = require("../local-github");
27
29
  // eslint-disable-next-line @typescript-eslint/no-var-requires
28
30
  const parseGithubRepoUrl = require('parse-github-repo-url');
29
31
  function gitHubOptions(yargs) {
@@ -31,12 +33,12 @@ function gitHubOptions(yargs) {
31
33
  .option('token', { describe: 'GitHub token with repo write permissions' })
32
34
  .option('api-url', {
33
35
  describe: 'URL to use when making API requests',
34
- default: github_1.GH_API_URL,
36
+ default: github_api_1.GH_API_URL,
35
37
  type: 'string',
36
38
  })
37
39
  .option('graphql-url', {
38
40
  describe: 'URL to use when making GraphQL requests',
39
- default: github_1.GH_GRAPHQL_URL,
41
+ default: github_api_1.GH_GRAPHQL_URL,
40
42
  type: 'string',
41
43
  })
42
44
  .option('default-branch', {
@@ -56,6 +58,19 @@ function gitHubOptions(yargs) {
56
58
  describe: 'Prepare but do not take action',
57
59
  type: 'boolean',
58
60
  default: false,
61
+ })
62
+ .option('local', {
63
+ describe: 'Whether to use local clone',
64
+ type: 'boolean',
65
+ default: false,
66
+ })
67
+ .option('local-path', {
68
+ describe: 'Path to local clone directory. If not set, uses a temporary directory.',
69
+ type: 'string',
70
+ })
71
+ .option('local-clone-depth', {
72
+ describe: 'Depth of local clone. Defaults to the entire repo.',
73
+ type: 'number',
59
74
  })
60
75
  .middleware(_argv => {
61
76
  const argv = _argv;
@@ -565,14 +580,28 @@ const debugConfigCommand = {
565
580
  };
566
581
  async function buildGitHub(argv) {
567
582
  const [owner, repo] = parseGithubRepoUrl(argv.repoUrl);
568
- const github = await github_1.GitHub.create({
569
- owner,
570
- repo,
571
- token: argv.token,
572
- apiUrl: argv.apiUrl,
573
- graphqlUrl: argv.graphqlUrl,
574
- });
575
- return github;
583
+ if (argv.local) {
584
+ const localGitHub = await local_github_1.LocalGitHub.create({
585
+ owner,
586
+ repo,
587
+ token: argv.token,
588
+ apiUrl: argv.apiUrl,
589
+ graphqlUrl: argv.graphqlUrl,
590
+ localRepoPath: argv.localPath,
591
+ cloneDepth: argv.localCloneDepth,
592
+ });
593
+ return localGitHub;
594
+ }
595
+ else {
596
+ const github = await github_1.GitHub.create({
597
+ owner,
598
+ repo,
599
+ token: argv.token,
600
+ apiUrl: argv.apiUrl,
601
+ graphqlUrl: argv.graphqlUrl,
602
+ });
603
+ return github;
604
+ }
576
605
  }
577
606
  exports.parser = yargs
578
607
  .command(createReleasePullRequestCommand)
@@ -1,4 +1,4 @@
1
- import { GitHub } from './github';
1
+ import { Scm } from './scm';
2
2
  import { ReleaserConfig } from './manifest';
3
3
  import { PullRequest } from './pull-request';
4
4
  import { Update } from './update';
@@ -11,7 +11,7 @@ export declare class Bootstrapper {
11
11
  private manifestFile;
12
12
  private configFile;
13
13
  private initialVersion;
14
- constructor(github: GitHub, targetBranch: string, manifestFile?: string, configFile?: string, initialVersionString?: string);
14
+ constructor(github: Scm, targetBranch: string, manifestFile?: string, configFile?: string, initialVersionString?: string);
15
15
  bootstrap(path: string, config: ReleaserConfig): Promise<PullRequest>;
16
16
  buildPullRequest(path: string, config: ReleaserConfig): Promise<BootstrapPullRequest>;
17
17
  }
@@ -50,9 +50,17 @@ class DefaultChangelogNotes {
50
50
  const notes = commit.notes
51
51
  .filter(note => note.title === 'BREAKING CHANGE')
52
52
  .map(note => replaceIssueLink(note, context.host, context.owner, context.repository));
53
+ let subject = htmlEscape(commit.bareMessage);
54
+ // Append author info if enabled and author is available
55
+ if (options.includeCommitAuthors && commit.author) {
56
+ const authorDisplay = commit.author.username
57
+ ? `@${commit.author.username}`
58
+ : commit.author.name;
59
+ subject = `${subject} (${authorDisplay})`;
60
+ }
53
61
  return {
54
62
  body: '',
55
- subject: htmlEscape(commit.bareMessage),
63
+ subject,
56
64
  type: commit.type,
57
65
  scope: commit.scope,
58
66
  notes,
@@ -1,8 +1,8 @@
1
1
  import { ChangelogNotes, BuildNotesOptions } from '../changelog-notes';
2
2
  import { ConventionalCommit } from '../commit';
3
- import { GitHub } from '../github';
3
+ import { Scm } from '../scm';
4
4
  export declare class GitHubChangelogNotes implements ChangelogNotes {
5
5
  private github;
6
- constructor(github: GitHub);
6
+ constructor(github: Scm);
7
7
  buildNotes(_commits: ConventionalCommit[], options: BuildNotesOptions): Promise<string>;
8
8
  }
@@ -9,6 +9,7 @@ export interface BuildNotesOptions {
9
9
  targetBranch: string;
10
10
  changelogSections?: ChangelogSection[];
11
11
  commits?: Commit[];
12
+ includeCommitAuthors?: boolean;
12
13
  }
13
14
  export interface ChangelogNotes {
14
15
  buildNotes(commits: ConventionalCommit[], options: BuildNotesOptions): Promise<string>;
@@ -1,11 +1,17 @@
1
1
  import { PullRequest } from './pull-request';
2
2
  import { Logger } from './util/logger';
3
3
  import * as parser from '@conventional-commits/parser';
4
+ export interface CommitAuthor {
5
+ name: string;
6
+ email?: string;
7
+ username?: string;
8
+ }
4
9
  export interface Commit {
5
10
  sha: string;
6
11
  message: string;
7
12
  files?: string[];
8
13
  pullRequest?: PullRequest;
14
+ author?: CommitAuthor;
9
15
  }
10
16
  export interface ConventionalCommit extends Commit {
11
17
  type: string;
@@ -1,9 +1,9 @@
1
- import { GitHub } from '../github';
1
+ import { Scm } from '../scm';
2
2
  import { ChangelogNotes, ChangelogSection } from '../changelog-notes';
3
3
  export type ChangelogNotesType = string;
4
4
  export interface ChangelogNotesFactoryOptions {
5
5
  type: ChangelogNotesType;
6
- github: GitHub;
6
+ github: Scm;
7
7
  changelogSections?: ChangelogSection[];
8
8
  commitPartial?: string;
9
9
  headerPartial?: string;
@@ -1,11 +1,11 @@
1
1
  import { PluginType, RepositoryConfig } from '../manifest';
2
- import { GitHub } from '../github';
2
+ import { Scm } from '../scm';
3
3
  import { ManifestPlugin } from '../plugin';
4
4
  import { VersioningStrategyType } from './versioning-strategy-factory';
5
5
  import { Logger } from '../util/logger';
6
6
  export interface PluginFactoryOptions {
7
7
  type: PluginType;
8
- github: GitHub;
8
+ github: Scm;
9
9
  targetBranch: string;
10
10
  repositoryConfig: RepositoryConfig;
11
11
  manifestPath: string;
@@ -1,5 +1,5 @@
1
1
  import { VersioningStrategy } from '../versioning-strategy';
2
- import { GitHub } from '../github';
2
+ import { Scm } from '../scm';
3
3
  export type VersioningStrategyType = string;
4
4
  export interface VersioningStrategyFactoryOptions {
5
5
  type?: VersioningStrategyType;
@@ -7,7 +7,7 @@ export interface VersioningStrategyFactoryOptions {
7
7
  bumpPatchForMinorPreMajor?: boolean;
8
8
  prereleaseType?: string;
9
9
  prerelease?: boolean;
10
- github: GitHub;
10
+ github: Scm;
11
11
  }
12
12
  export type VersioningStrategyBuilder = (options: VersioningStrategyFactoryOptions) => VersioningStrategy;
13
13
  export declare function buildVersioningStrategy(options: VersioningStrategyFactoryOptions): VersioningStrategy;
@@ -1,4 +1,4 @@
1
- import { GitHub } from './github';
1
+ import { Scm } from './scm';
2
2
  import { ReleaserConfig } from './manifest';
3
3
  import { BaseStrategyOptions } from './strategies/base';
4
4
  import { Strategy } from './strategy';
@@ -8,7 +8,7 @@ export * from './factories/versioning-strategy-factory';
8
8
  export type ReleaseType = string;
9
9
  export type ReleaseBuilder = (options: BaseStrategyOptions) => Strategy;
10
10
  export interface StrategyFactoryOptions extends ReleaserConfig {
11
- github: GitHub;
11
+ github: Scm;
12
12
  path?: string;
13
13
  targetBranch?: string;
14
14
  }
@@ -0,0 +1,260 @@
1
+ import { Octokit } from '@octokit/rest';
2
+ import { request } from '@octokit/request';
3
+ import { Logger } from 'code-suggester/build/src/types';
4
+ import { PullRequest } from './pull-request';
5
+ import { Repository } from './repository';
6
+ import { Release } from './release';
7
+ import { ScmRelease, ScmReleaseIteratorOptions, ScmReleaseOptions, ScmCommitIteratorOptions } from './scm';
8
+ import { HttpsProxyAgent } from 'https-proxy-agent';
9
+ import { HttpProxyAgent } from 'http-proxy-agent';
10
+ export declare const GH_API_URL = "https://api.github.com";
11
+ export declare const GH_GRAPHQL_URL = "https://api.github.com";
12
+ export type OctokitType = InstanceType<typeof Octokit>;
13
+ type RequestBuilderType = typeof request;
14
+ type DefaultFunctionType = RequestBuilderType['defaults'];
15
+ type RequestFunctionType = ReturnType<DefaultFunctionType>;
16
+ export interface OctokitAPIs {
17
+ graphql: Function;
18
+ request: RequestFunctionType;
19
+ octokit: OctokitType;
20
+ }
21
+ export interface ProxyOption {
22
+ host: string;
23
+ port: number;
24
+ }
25
+ export interface GitHubCreateOptions {
26
+ owner: string;
27
+ repo: string;
28
+ defaultBranch?: string;
29
+ apiUrl?: string;
30
+ graphqlUrl?: string;
31
+ octokitAPIs?: OctokitAPIs;
32
+ token?: string;
33
+ logger?: Logger;
34
+ proxy?: ProxyOption;
35
+ fetch?: any;
36
+ }
37
+ export interface GitHubApiOptions {
38
+ repository: Repository;
39
+ octokitAPIs: OctokitAPIs;
40
+ logger?: Logger;
41
+ }
42
+ export interface GraphQLCommit {
43
+ sha: string;
44
+ message: string;
45
+ associatedPullRequests: {
46
+ nodes: GraphQLPullRequest[];
47
+ };
48
+ }
49
+ export interface GraphQLPullRequest {
50
+ number: number;
51
+ title: string;
52
+ body: string;
53
+ baseRefName: string;
54
+ headRefName: string;
55
+ labels: {
56
+ nodes: {
57
+ name: string;
58
+ }[];
59
+ };
60
+ mergeCommit?: {
61
+ oid: string;
62
+ };
63
+ files: {
64
+ nodes: {
65
+ path: string;
66
+ }[];
67
+ pageInfo: {
68
+ hasNextPage: boolean;
69
+ };
70
+ };
71
+ }
72
+ export interface PullRequestHistory {
73
+ pageInfo: {
74
+ hasNextPage: boolean;
75
+ endCursor: string | undefined;
76
+ };
77
+ data: PullRequest[];
78
+ }
79
+ export interface CommitHistory {
80
+ pageInfo: {
81
+ hasNextPage: boolean;
82
+ endCursor: string | undefined;
83
+ };
84
+ data: ScmRelease[];
85
+ }
86
+ export type CommitIteratorOptions = ScmCommitIteratorOptions;
87
+ export interface GraphQLRelease {
88
+ name: string;
89
+ tag: {
90
+ name: string;
91
+ };
92
+ tagCommit: {
93
+ oid: string;
94
+ };
95
+ url: string;
96
+ description: string;
97
+ isDraft: boolean;
98
+ }
99
+ export interface ReleaseHistory {
100
+ pageInfo: {
101
+ hasNextPage: boolean;
102
+ endCursor: string | undefined;
103
+ };
104
+ data: ScmRelease[];
105
+ }
106
+ export type ReleaseIteratorOptions = ScmReleaseIteratorOptions;
107
+ export declare const MAX_SLEEP_SECONDS = 20;
108
+ export declare const MAX_ISSUE_BODY_SIZE = 65536;
109
+ export declare class GitHubApi {
110
+ readonly repository: Repository;
111
+ readonly octokitAPIs: OctokitAPIs;
112
+ octokit: OctokitType;
113
+ private graphql;
114
+ private logger;
115
+ constructor(options: GitHubApiOptions);
116
+ static createDefaultAgent(baseUrl: string, defaultProxy?: ProxyOption): HttpProxyAgent<`http://${string}:${number}`> | HttpsProxyAgent<`https://${string}:${number}`> | undefined;
117
+ static create(options: GitHubCreateOptions): Promise<GitHubApi>;
118
+ static defaultBranch(owner: string, repo: string, octokit: OctokitType): Promise<string>;
119
+ private graphqlRequest;
120
+ /**
121
+ * Iterate through merged pull requests with a max number of results scanned.
122
+ *
123
+ * @param {string} targetBranch Target branch of commit.
124
+ * @param {string} status The status of the pull request. Defaults to 'MERGED'.
125
+ * @param {number} maxResults Limit the number of results searched. Defaults to
126
+ * unlimited.
127
+ * @param {boolean} includeFiles Whether to fetch the list of files included in
128
+ * the pull request. Defaults to `true`.
129
+ * @yields {PullRequest}
130
+ * @throws {GitHubAPIError} on an API error
131
+ */
132
+ pullRequestIterator(targetBranch: string, status?: 'OPEN' | 'CLOSED' | 'MERGED', maxResults?: number, includeFiles?: boolean): AsyncGenerator<PullRequest, void, void>;
133
+ /**
134
+ * Helper implementation of pullRequestIterator that includes files via
135
+ * the graphQL API.
136
+ *
137
+ * @param {string} targetBranch The base branch of the pull request
138
+ * @param {string} status The status of the pull request
139
+ * @param {number} maxResults Limit the number of results searched
140
+ */
141
+ private pullRequestIteratorWithFiles;
142
+ /**
143
+ * Helper implementation of pullRequestIterator that excludes files
144
+ * via the REST API.
145
+ *
146
+ * @param {string} targetBranch The base branch of the pull request
147
+ * @param {string} status The status of the pull request
148
+ * @param {number} maxResults Limit the number of results searched
149
+ */
150
+ private pullRequestIteratorWithoutFiles;
151
+ /**
152
+ * Return a list of merged pull requests. The list is not guaranteed to be sorted
153
+ * by merged_at, but is generally most recent first.
154
+ *
155
+ * @param {string} targetBranch - Base branch of the pull request. Defaults to
156
+ * the configured default branch.
157
+ * @param {number} page - Page of results. Defaults to 1.
158
+ * @param {number} perPage - Number of results per page. Defaults to 100.
159
+ * @returns {PullRequestHistory | null} - List of merged pull requests
160
+ * @throws {GitHubAPIError} on an API error
161
+ */
162
+ private pullRequestsGraphQL;
163
+ /**
164
+ * Iterate through releases with a max number of results scanned.
165
+ *
166
+ * @param {ReleaseIteratorOptions} options Query options
167
+ * @param {number} options.maxResults Limit the number of results scanned.
168
+ * Defaults to unlimited.
169
+ * @yields {ScmRelease}
170
+ * @throws {GitHubAPIError} on an API error
171
+ */
172
+ releaseIterator(options?: ReleaseIteratorOptions): AsyncGenerator<ScmRelease, void, unknown>;
173
+ private releaseGraphQL;
174
+ createPullRequest: (pullRequest: PullRequest, targetBranch: string, options?: {
175
+ draft?: boolean | undefined;
176
+ } | undefined) => Promise<PullRequest>;
177
+ /**
178
+ * Fetch a pull request given the pull number
179
+ * @param {number} number The pull request number
180
+ * @returns {PullRequest}
181
+ */
182
+ getPullRequest: (number: number) => Promise<PullRequest>;
183
+ updatePullRequest: (number: number, title: string, body: string) => Promise<{
184
+ headBranchName: string;
185
+ baseBranchName: string;
186
+ number: number;
187
+ title: string;
188
+ body: string;
189
+ files: never[];
190
+ labels: string[];
191
+ }>;
192
+ /**
193
+ * Create a GitHub release
194
+ *
195
+ * @param {Release} release Release parameters
196
+ * @param {ScmReleaseOptions} options Release option parameters
197
+ * @throws {DuplicateReleaseError} if the release tag already exists
198
+ * @throws {GitHubAPIError} on other API errors
199
+ */
200
+ createRelease: (release: Release, options?: ScmReleaseOptions | undefined) => Promise<ScmRelease>;
201
+ /**
202
+ * Makes a comment on a issue/pull request.
203
+ *
204
+ * @param {string} comment - The body of the comment to post.
205
+ * @param {number} number - The issue or pull request number.
206
+ * @throws {GitHubAPIError} on an API error
207
+ */
208
+ commentOnIssue: (comment: string, number: number) => Promise<string>;
209
+ /**
210
+ * Removes labels from an issue/pull request.
211
+ *
212
+ * @param {string[]} labels The labels to remove.
213
+ * @param {number} number The issue/pull request number.
214
+ */
215
+ removeIssueLabels: (labels: string[], number: number) => Promise<void>;
216
+ /**
217
+ * Adds label to an issue/pull request.
218
+ *
219
+ * @param {string[]} labels The labels to add.
220
+ * @param {number} number The issue/pull request number.
221
+ */
222
+ addIssueLabels: (labels: string[], number: number) => Promise<void>;
223
+ /**
224
+ * Generate release notes from GitHub at tag
225
+ * @param {string} tagName Name of new release tag
226
+ * @param {string} targetCommitish Target commitish for new tag
227
+ * @param {string} previousTag Optional. Name of previous tag to analyze commits since
228
+ */
229
+ generateReleaseNotes(tagName: string, targetCommitish: string, previousTag?: string): Promise<string>;
230
+ /**
231
+ * Create a single file on a new branch based on an existing
232
+ * branch. This will force-push to that branch.
233
+ * @param {string} filename Filename with path in the repository
234
+ * @param {string} contents Contents of the file
235
+ * @param {string} newBranchName Name of the new branch
236
+ * @param {string} baseBranchName Name of the base branch (where
237
+ * new branch is forked from)
238
+ * @returns {string} HTML URL of the new file
239
+ */
240
+ createFileOnNewBranch(filename: string, contents: string, newBranchName: string, baseBranchName: string): Promise<string>;
241
+ /**
242
+ * Fork a branch from a base branch.
243
+ */
244
+ private forkBranch;
245
+ /**
246
+ * Helper to fetch the SHA of a branch
247
+ */
248
+ private getBranchSha;
249
+ /**
250
+ * Helper to create a new branch from a given SHA.
251
+ */
252
+ private createNewBranch;
253
+ /**
254
+ * Helper to update branch SHA.
255
+ */
256
+ private updateBranchSha;
257
+ }
258
+ export declare const wrapAsync: <T extends any[], V>(fn: (...args: T) => Promise<V>, errorHandler?: ((e: Error) => void) | undefined) => (...args: T) => Promise<V>;
259
+ export declare const sleepInMs: (ms: number) => Promise<unknown>;
260
+ export {};