@salesforce/plugin-release-management 3.15.9 → 3.16.1

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,129 @@
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
+ 'Also try running this locally with the "--dry-run" flag',
36
+ ]);
37
+ };
38
+ if (prData.state !== 'open') {
39
+ stop('PR not open');
40
+ }
41
+ const automergeLabels = ['automerge', 'nightly-automerge'];
42
+ if (!prData.labels.some((label) => automergeLabels.includes(label.name))) {
43
+ stop(`Missing automerge label: [${automergeLabels.join(', ')}]`);
44
+ }
45
+ if (prData.user.login !== 'svc-cli-bot') {
46
+ stop('PR must be created by "svc-cli-bot"');
47
+ }
48
+ if (!(await this.isGreen(prData, verbose))) {
49
+ stop('PR checks failed');
50
+ }
51
+ if (!(await this.isMergeable())) {
52
+ stop('PR is not mergable');
53
+ }
54
+ // Continue with merge attempt
55
+ if (dryRun === false) {
56
+ this.log(`Merging ${prData.number} | ${prData.title}`);
57
+ const mergeResult = await this.octokit.request('PUT /repos/{owner}/{repo}/pulls/{pull_number}/merge', {
58
+ ...this.pullRequestParams,
59
+ });
60
+ this.info('Run with --verbose to see PR merge response');
61
+ if (verbose) {
62
+ this.styledJSON(mergeResult);
63
+ }
64
+ }
65
+ else {
66
+ this.logSuccess(`Dry run successful: ${prData.number} | ${prData.title}`);
67
+ }
68
+ }
69
+ async isGreen(pr, verbose) {
70
+ const statusResponse = await this.octokit.request('GET /repos/{owner}/{repo}/commits/{ref}/status', {
71
+ ...this.baseRepoParams,
72
+ ref: pr.head.sha,
73
+ });
74
+ // no point looking at check runs if the commit status is not green
75
+ if (statusResponse.data.state !== 'success') {
76
+ return false;
77
+ }
78
+ const checkRunResponse = await this.octokit.request('GET /repos/{owner}/{repo}/commits/{ref}/check-runs', {
79
+ ...this.baseRepoParams,
80
+ ref: pr.head.sha,
81
+ });
82
+ if (verbose)
83
+ this.styledJSON(checkRunResponse);
84
+ if (checkRunResponse.data.check_runs.every((cr) => cr.name === 'automerge' || (cr.status === 'completed' && ['success', 'skipped'].includes(cr.conclusion)))) {
85
+ return true;
86
+ }
87
+ }
88
+ async isMergeable() {
89
+ const statusResponse = await this.octokit.request('GET /repos/{owner}/{repo}/pulls/{pull_number}', {
90
+ ...this.pullRequestParams,
91
+ });
92
+ // mergeable_state of 'blocked' is ok because it is either missing an approval or the commit is not signed.
93
+ // We're screening out 'behind' which might be merge conflicts.
94
+ if (statusResponse.data.mergeable === true && statusResponse.data.mergeable_state !== 'behind') {
95
+ return true;
96
+ }
97
+ }
98
+ }
99
+ exports.default = AutoMerge;
100
+ AutoMerge.summary = messages.getMessage('description');
101
+ AutoMerge.description = messages.getMessage('description');
102
+ AutoMerge.examples = messages.getMessages('examples');
103
+ AutoMerge.flags = {
104
+ owner: sf_plugins_core_1.Flags.string({
105
+ summary: messages.getMessage('owner'),
106
+ dependsOn: ['repo'],
107
+ aliases: ['org'],
108
+ required: true,
109
+ }),
110
+ repo: sf_plugins_core_1.Flags.string({
111
+ summary: messages.getMessage('repo'),
112
+ dependsOn: ['owner'],
113
+ required: true,
114
+ }),
115
+ 'pull-number': sf_plugins_core_1.Flags.integer({
116
+ summary: messages.getMessage('pull-number'),
117
+ required: true,
118
+ }),
119
+ 'dry-run': sf_plugins_core_1.Flags.boolean({
120
+ summary: messages.getMessage('dry-run'),
121
+ char: 'd',
122
+ default: false,
123
+ }),
124
+ verbose: sf_plugins_core_1.Flags.boolean({
125
+ summary: messages.getMessage('verbose'),
126
+ default: false,
127
+ }),
128
+ };
129
+ //# 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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AAC,OAAO,CAAC;QACvB,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC;QACvC,IAAI,EAAE,GAAG;QACT,OAAO,EAAE,KAAK;KACf,CAAC;IACF,OAAO,EAAE,uBAAK,CAAC,OAAO,CAAC;QACrB,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC;QACvC,OAAO,EAAE,KAAK;KACf,CAAC;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.9",
2
+ "version": "3.16.1",
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.9",
4
+ "version": "3.16.1",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/forcedotcom/cli/issues",
7
7
  "bin": {
@@ -290,7 +290,7 @@
290
290
  }
291
291
  },
292
292
  "sfdx": {
293
- "publicKeyUrl": "https://developer.salesforce.com/media/salesforce-cli/security/@salesforce/plugin-release-management/3.15.9.crt",
294
- "signatureUrl": "https://developer.salesforce.com/media/salesforce-cli/security/@salesforce/plugin-release-management/3.15.9.sig"
293
+ "publicKeyUrl": "https://developer.salesforce.com/media/salesforce-cli/security/@salesforce/plugin-release-management/3.16.1.crt",
294
+ "signatureUrl": "https://developer.salesforce.com/media/salesforce-cli/security/@salesforce/plugin-release-management/3.16.1.sig"
295
295
  }
296
296
  }