@salesforce/plugin-release-management 3.15.8 → 3.16.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.
@@ -0,0 +1,19 @@
1
+ import { SfCommand } from '@salesforce/sf-plugins-core';
2
+ export default class AutoMerge extends SfCommand<void> {
3
+ static readonly summary: string;
4
+ static readonly description: string;
5
+ static readonly examples: string[];
6
+ static readonly flags: {
7
+ owner: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
8
+ repo: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
9
+ 'pull-number': import("@oclif/core/lib/interfaces").OptionFlag<number, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
10
+ 'dry-run': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
11
+ verbose: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
12
+ };
13
+ private octokit;
14
+ private baseRepoParams;
15
+ private pullRequestParams;
16
+ run(): Promise<void>;
17
+ private isGreen;
18
+ private isMergeable;
19
+ }
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /*
4
+ * Copyright (c) 2020, salesforce.com, inc.
5
+ * All rights reserved.
6
+ * Licensed under the BSD 3-Clause license.
7
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
8
+ */
9
+ /* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, camelcase*/
10
+ const sf_plugins_core_1 = require("@salesforce/sf-plugins-core");
11
+ const core_1 = require("@octokit/core");
12
+ const kit_1 = require("@salesforce/kit");
13
+ const ts_types_1 = require("@salesforce/ts-types");
14
+ const core_2 = require("@salesforce/core");
15
+ core_2.Messages.importMessagesDirectory(__dirname);
16
+ const messages = core_2.Messages.loadMessages('@salesforce/plugin-release-management', 'cli.release.automerge');
17
+ class AutoMerge extends sf_plugins_core_1.SfCommand {
18
+ async run() {
19
+ const { flags } = await this.parse(AutoMerge);
20
+ const { 'dry-run': dryRun, owner, repo, verbose, 'pull-number': pullNumber } = flags;
21
+ const auth = (0, ts_types_1.ensureString)(new kit_1.Env().getString('GH_TOKEN') ?? new kit_1.Env().getString('GITHUB_TOKEN'), 'GH_TOKEN is required to be set in the environment');
22
+ this.octokit = new core_1.Octokit({ auth });
23
+ this.baseRepoParams = { owner, repo };
24
+ this.pullRequestParams = {
25
+ ...this.baseRepoParams,
26
+ pull_number: pullNumber,
27
+ };
28
+ const prData = (await this.octokit.request('GET /repos/{owner}/{repo}/pulls/{pull_number}', { ...this.pullRequestParams })).data;
29
+ // Check if PR is able to be merged.
30
+ const stop = (reason) => {
31
+ if (verbose)
32
+ this.styledJSON(prData);
33
+ throw new core_2.SfError(`CANNOT MERGE: ${reason}`, 'AUTOMERGE_FAILURE', [
34
+ 'Run with --verbose to see PR response object',
35
+ ]);
36
+ };
37
+ if (prData.state !== 'open') {
38
+ stop('PR not open');
39
+ }
40
+ const automergeLabels = ['automerge', 'nightly-automerge'];
41
+ if (!prData.labels.some((label) => automergeLabels.includes(label.name))) {
42
+ stop(`Missing automerge label: [${automergeLabels.join(', ')}]`);
43
+ }
44
+ if (prData.user.login !== 'svc-cli-bot') {
45
+ stop('PR must be created by "svc-cli-bot"');
46
+ }
47
+ if (!(await this.isGreen(prData))) {
48
+ stop('PR checks failed');
49
+ }
50
+ if (!(await this.isMergeable())) {
51
+ stop('PR is not mergable');
52
+ }
53
+ // Continue with merge attempt
54
+ if (dryRun === false) {
55
+ this.log(`Merging ${prData.number} | ${prData.title}`);
56
+ const mergeResult = await this.octokit.request('PUT /repos/{owner}/{repo}/pulls/{pull_number}/merge', {
57
+ ...this.pullRequestParams,
58
+ });
59
+ this.info('Run with --verbose to see PR merge response');
60
+ if (verbose) {
61
+ this.styledJSON(mergeResult);
62
+ }
63
+ }
64
+ else {
65
+ this.logSuccess(`Dry run successful: ${prData.number} | ${prData.title}`);
66
+ }
67
+ }
68
+ async isGreen(pr) {
69
+ const statusResponse = await this.octokit.request('GET /repos/{owner}/{repo}/commits/{ref}/status', {
70
+ ...this.baseRepoParams,
71
+ ref: pr.head.sha,
72
+ });
73
+ // no point looking at check runs if the commit status is not green
74
+ if (statusResponse.data.state !== 'success') {
75
+ return false;
76
+ }
77
+ const checkRunResponse = await this.octokit.request('GET /repos/{owner}/{repo}/commits/{ref}/check-runs', {
78
+ ...this.baseRepoParams,
79
+ ref: pr.head.sha,
80
+ });
81
+ if (checkRunResponse.data.check_runs.every((cr) => cr.status === 'completed' && ['success', 'skipped'].includes(cr.conclusion))) {
82
+ return true;
83
+ }
84
+ }
85
+ async isMergeable() {
86
+ const statusResponse = await this.octokit.request('GET /repos/{owner}/{repo}/pulls/{pull_number}', {
87
+ ...this.pullRequestParams,
88
+ });
89
+ // mergeable_state of 'blocked' is ok because it is either missing an approval or the commit is not signed.
90
+ // We're screening out 'behind' which might be merge conflicts.
91
+ if (statusResponse.data.mergeable === true && statusResponse.data.mergeable_state !== 'behind') {
92
+ return true;
93
+ }
94
+ }
95
+ }
96
+ exports.default = AutoMerge;
97
+ AutoMerge.summary = messages.getMessage('description');
98
+ AutoMerge.description = messages.getMessage('description');
99
+ AutoMerge.examples = messages.getMessages('examples');
100
+ AutoMerge.flags = {
101
+ owner: sf_plugins_core_1.Flags.string({
102
+ summary: messages.getMessage('owner'),
103
+ dependsOn: ['repo'],
104
+ aliases: ['org'],
105
+ required: true,
106
+ }),
107
+ repo: sf_plugins_core_1.Flags.string({
108
+ summary: messages.getMessage('repo'),
109
+ dependsOn: ['owner'],
110
+ required: true,
111
+ }),
112
+ 'pull-number': sf_plugins_core_1.Flags.integer({
113
+ summary: messages.getMessage('pull-number'),
114
+ required: true,
115
+ }),
116
+ 'dry-run': sf_plugins_core_1.Flags.boolean({
117
+ summary: messages.getMessage('dry-run'),
118
+ char: 'd',
119
+ default: false,
120
+ }),
121
+ verbose: sf_plugins_core_1.Flags.boolean({
122
+ summary: messages.getMessage('verbose'),
123
+ default: false,
124
+ }),
125
+ };
126
+ //# sourceMappingURL=automerge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"automerge.js","sourceRoot":"","sources":["../../../../src/commands/cli/release/automerge.ts"],"names":[],"mappings":";;AAAA;;;;;GAKG;AACH,qJAAqJ;AACrJ,iEAA+D;AAC/D,wCAAwC;AACxC,yCAAsC;AACtC,mDAAoD;AACpD,2CAAqD;AAErD,eAAQ,CAAC,uBAAuB,CAAC,SAAS,CAAC,CAAC;AAE5C,MAAM,QAAQ,GAAG,eAAQ,CAAC,YAAY,CAAC,uCAAuC,EAAE,uBAAuB,CAAC,CAAC;AASzG,MAAqB,SAAU,SAAQ,2BAAe;IAoC7C,KAAK,CAAC,GAAG;QACd,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QAE9C,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,GAAG,KAAK,CAAC;QAErF,MAAM,IAAI,GAAG,IAAA,uBAAY,EACvB,IAAI,SAAG,EAAE,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,IAAI,SAAG,EAAE,CAAC,SAAS,CAAC,cAAc,CAAC,EACtE,mDAAmD,CACpD,CAAC;QAEF,IAAI,CAAC,OAAO,GAAG,IAAI,cAAO,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;QAErC,IAAI,CAAC,cAAc,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;QAEtC,IAAI,CAAC,iBAAiB,GAAG;YACvB,GAAG,IAAI,CAAC,cAAc;YACtB,WAAW,EAAE,UAAU;SACxB,CAAC;QAEF,MAAM,MAAM,GAAG,CACb,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,+CAA+C,EAA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AAC;CACH,CAAC"}
@@ -0,0 +1,9 @@
1
+ {
2
+ "description": "Attempt to automerge nightly PR",
3
+ "owner": "Github owner (org), example: salesforcecli",
4
+ "repo": "Github repo, example: sfdx-cli",
5
+ "pull-number": "Github pull request number to merge",
6
+ "dry-run": "Run all checks, but do not merge PR",
7
+ "verbose": "Show additional debug output",
8
+ "examples": ["<%= config.bin %> <%= command.id %> --owner salesforcecli --repo sfdx-cli --pul-number 1049"]
9
+ }
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "3.15.8",
2
+ "version": "3.16.0",
3
3
  "commands": {
4
4
  "channel:promote": {
5
5
  "id": "channel:promote",
@@ -617,6 +617,72 @@
617
617
  },
618
618
  "args": {}
619
619
  },
620
+ "cli:release:automerge": {
621
+ "id": "cli:release:automerge",
622
+ "summary": "Attempt to automerge nightly PR",
623
+ "description": "Attempt to automerge nightly PR",
624
+ "strict": true,
625
+ "pluginName": "@salesforce/plugin-release-management",
626
+ "pluginAlias": "@salesforce/plugin-release-management",
627
+ "pluginType": "core",
628
+ "aliases": [],
629
+ "examples": [
630
+ "<%= config.bin %> <%= command.id %> --owner salesforcecli --repo sfdx-cli --pul-number 1049"
631
+ ],
632
+ "flags": {
633
+ "json": {
634
+ "name": "json",
635
+ "type": "boolean",
636
+ "description": "Format output as json.",
637
+ "helpGroup": "GLOBAL",
638
+ "allowNo": false
639
+ },
640
+ "owner": {
641
+ "name": "owner",
642
+ "type": "option",
643
+ "summary": "Github owner (org), example: salesforcecli",
644
+ "required": true,
645
+ "multiple": false,
646
+ "dependsOn": [
647
+ "repo"
648
+ ],
649
+ "aliases": [
650
+ "org"
651
+ ]
652
+ },
653
+ "repo": {
654
+ "name": "repo",
655
+ "type": "option",
656
+ "summary": "Github repo, example: sfdx-cli",
657
+ "required": true,
658
+ "multiple": false,
659
+ "dependsOn": [
660
+ "owner"
661
+ ]
662
+ },
663
+ "pull-number": {
664
+ "name": "pull-number",
665
+ "type": "option",
666
+ "summary": "Github pull request number to merge",
667
+ "required": true,
668
+ "multiple": false
669
+ },
670
+ "dry-run": {
671
+ "name": "dry-run",
672
+ "type": "boolean",
673
+ "char": "d",
674
+ "summary": "Run all checks, but do not merge PR",
675
+ "allowNo": false
676
+ },
677
+ "verbose": {
678
+ "name": "verbose",
679
+ "type": "boolean",
680
+ "summary": "Show additional debug output",
681
+ "allowNo": false
682
+ }
683
+ },
684
+ "args": {}
685
+ },
620
686
  "cli:release:build": {
621
687
  "id": "cli:release:build",
622
688
  "summary": "builds a new release from a designated starting point and optionally creates PR in Github",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@salesforce/plugin-release-management",
3
3
  "description": "A plugin for preparing and publishing npm packages",
4
- "version": "3.15.8",
4
+ "version": "3.16.0",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/forcedotcom/cli/issues",
7
7
  "bin": {
@@ -14,7 +14,7 @@
14
14
  "@octokit/plugin-throttling": "^5.0.1",
15
15
  "@salesforce/core": "^3.33.5",
16
16
  "@salesforce/kit": "^1.9.2",
17
- "@salesforce/plugin-command-reference": "^2.3.1",
17
+ "@salesforce/plugin-command-reference": "^2.4.1",
18
18
  "@salesforce/plugin-trust": "^2.4.2",
19
19
  "@salesforce/sf-plugins-core": "^2.2.4",
20
20
  "@salesforce/ts-types": "^1.7.3",
@@ -36,9 +36,9 @@
36
36
  "yarn-deduplicate": "^3.1.0"
37
37
  },
38
38
  "devDependencies": {
39
- "@oclif/plugin-command-snapshot": "^3.3.8",
39
+ "@oclif/plugin-command-snapshot": "^3.3.9",
40
40
  "@salesforce/dev-config": "^3.0.0",
41
- "@salesforce/dev-scripts": "^4.1.2",
41
+ "@salesforce/dev-scripts": "^4.1.3",
42
42
  "@salesforce/prettier-config": "^0.0.2",
43
43
  "@salesforce/ts-sinon": "1.4.6",
44
44
  "@swc/core": "^1.3.37",
@@ -195,7 +195,7 @@
195
195
  "command": "tsc -p . --pretty --incremental",
196
196
  "files": [
197
197
  "src/**/*.ts",
198
- "tsconfig.json",
198
+ "**/tsconfig.json",
199
199
  "messages/**"
200
200
  ],
201
201
  "output": [
@@ -221,7 +221,8 @@
221
221
  "src/**/*.ts",
222
222
  "test/**/*.ts",
223
223
  "messages/**",
224
- ".eslint*"
224
+ "**/.eslint*",
225
+ "**/tsconfig.json"
225
226
  ],
226
227
  "output": []
227
228
  },
@@ -229,8 +230,7 @@
229
230
  "command": "tsc -p \"./test\" --pretty",
230
231
  "files": [
231
232
  "test/**/*.ts",
232
- "tsconfig.json",
233
- "test/tsconfig.json"
233
+ "**/tsconfig.json"
234
234
  ],
235
235
  "output": []
236
236
  },
@@ -252,9 +252,8 @@
252
252
  "files": [
253
253
  "test/**/*.ts",
254
254
  "src/**/*.ts",
255
- "tsconfig.json",
255
+ "**/tsconfig.json",
256
256
  ".mocha*",
257
- "test/tsconfig.json",
258
257
  "!*.nut.ts",
259
258
  ".nycrc"
260
259
  ],
@@ -291,7 +290,7 @@
291
290
  }
292
291
  },
293
292
  "sfdx": {
294
- "publicKeyUrl": "https://developer.salesforce.com/media/salesforce-cli/security/@salesforce/plugin-release-management/3.15.8.crt",
295
- "signatureUrl": "https://developer.salesforce.com/media/salesforce-cli/security/@salesforce/plugin-release-management/3.15.8.sig"
293
+ "publicKeyUrl": "https://developer.salesforce.com/media/salesforce-cli/security/@salesforce/plugin-release-management/3.16.0.crt",
294
+ "signatureUrl": "https://developer.salesforce.com/media/salesforce-cli/security/@salesforce/plugin-release-management/3.16.0.sig"
296
295
  }
297
296
  }