Skip to content

Commit

Permalink
Merge pull request #141 from forcedotcom/sm/api-v2-check
Browse files Browse the repository at this point in the history
feat!: change-case v2
  • Loading branch information
iowillhoit authored May 24, 2024
2 parents 7e533f9 + 9afc01f commit 736242b
Show file tree
Hide file tree
Showing 31 changed files with 3,663 additions and 4,553 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js → .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
module.exports = {
extends: ['eslint-config-salesforce-typescript', 'eslint-config-salesforce-license', 'plugin:sf-plugin/migration'],
extends: ['eslint-config-salesforce-typescript', 'eslint-config-salesforce-license', 'plugin:sf-plugin/recommended'],
rules: {
camelcase: 'off',
'sf-plugin/get-connection-with-version': 'off',
Expand Down
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ docs
package.json.bak.
.sfdx


npm-shrinkwrap.json
oclif.manifest.json
oclif.lock

# -- CLEAN ALL
*.tsbuildinfo
.eslintcache
Expand All @@ -43,5 +48,3 @@ node_modules
# os specific files
.DS_Store
.idea

oclif.manifest.json
File renamed without changes.
5 changes: 3 additions & 2 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"require": "ts-node/register,source-map-support/register",
"require": ["ts-node/register"],
"watch-extensions": "ts",
"watch-files": ["src/**/*.ts", "test/**/*.ts"],
"recursive": true,
"reporter": "spec",
"timeout": 5000
"timeout": 5000,
"node-option": ["loader=ts-node/esm"]
}
5 changes: 5 additions & 0 deletions .sfdevrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
"command": "echo \"We don't do docs for this command\"",
"files": ["src/**/*.ts", "messages/**"],
"output": ["tmp/root"]
},
"link-check": {
"command": "echo \"We don't do link checks for this command\"",
"files": ["./*.md", "./!(CHANGELOG).md", "messages/**/*.md"],
"output": []
}
}
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"editor.formatOnSave": true
}
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2023, Salesforce.com, Inc.
Copyright (c) 2024, Salesforce.com, Inc.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Expand Down
21 changes: 0 additions & 21 deletions bin/dev

This file was deleted.

2 changes: 1 addition & 1 deletion bin/dev.cmd
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@echo off

node "%~dp0\dev" %*
node --loader ts-node/esm --no-warnings=ExperimentalWarning "%~dp0\dev" %*
8 changes: 8 additions & 0 deletions bin/dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env -S node --loader ts-node/esm --no-warnings=ExperimentalWarning
// eslint-disable-next-line node/shebang
async function main() {
const { execute } = await import('@oclif/core');
await execute({ development: true, dir: import.meta.url });
}

await main();
3 changes: 0 additions & 3 deletions bin/run

This file was deleted.

9 changes: 9 additions & 0 deletions bin/run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env node

// eslint-disable-next-line node/shebang
async function main() {
const { execute } = await import('@oclif/core');
await execute({ dir: import.meta.url });
}

await main();
24 changes: 15 additions & 9 deletions command-snapshot.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
[
{
"alias": [],
"command": "check",
"plugin": "@salesforce/change-case-management",
"flags": ["change-case-id", "json", "location", "release", "target-org"],
"alias": []
"flagAliases": ["changecaseid", "targetusername", "u"],
"flagChars": ["i", "l", "o", "r"],
"flags": ["change-case-id", "flags-dir", "json", "location", "release", "target-org"],
"plugin": "@salesforce/change-case-management"
},
{
"alias": [],
"command": "close",
"plugin": "@salesforce/change-case-management",
"flags": ["change-case-id", "dry-run", "json", "location", "release", "status", "target-org"],
"alias": []
"flagAliases": ["changecaseid", "dryrun", "targetusername", "u"],
"flagChars": ["i", "l", "o", "r", "s"],
"flags": ["change-case-id", "dry-run", "flags-dir", "json", "location", "release", "status", "target-org"],
"plugin": "@salesforce/change-case-management"
},
{
"alias": [],
"command": "create",
"plugin": "@salesforce/change-case-management",
"flags": ["configuration-item", "dry-run", "json", "location", "release", "target-org", "template-id"],
"alias": []
"flagAliases": ["configurationitem", "dryrun", "targetusername", "templateid", "u"],
"flagChars": ["c", "i", "l", "o", "r"],
"flags": ["configuration-item", "dry-run", "flags-dir", "json", "location", "release", "target-org", "template-id"],
"plugin": "@salesforce/change-case-management"
}
]
File renamed without changes.
40 changes: 8 additions & 32 deletions messages/changecase.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,19 @@
# check.description
# flags.changecaseid.summary

check the status of a change case record
change case id

# create.description
# flags.dry-run.summary

create a change case record based on a template ID with one implementation step
run the command without making any API calls - all calls will be 'successful'

# create.flags.templateid.description
# NoOrgError

change case template id
The command needs either a target org specified via flag or an environment variable: %s

# create.flags.release.description
# flags.release.summary

schedule build of the new release

# create.flags.location.description
# flags.location.summary

url of the source control location

# create.flags.configurationitem.description

Full path from the configuration item, ex: Salesforce.SF_Off_Core.DeveloperTools.NPM

# close.description

stops the implementation steps, and closes the change case record

# command.flags.changecaseid.description

change case id

# command.flags.dryrun.description

run the command without making any API calls - all calls will be 'successful'

# close.flags.status.summary

What the status of the implementation steps should be set to

# NoOrgError

The command needs either a target org specified via flag or an environment variable: %s
3 changes: 3 additions & 0 deletions messages/check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# summary

Checks if the change case (for the release and location) is currently blocked by a moratorium (that is, it's pre-approved and scheduled)
7 changes: 7 additions & 0 deletions messages/close.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# summary

Close a change case and stop its implementation steps.

# flags.status.summary

What the status of the implementation steps should be set to.
11 changes: 11 additions & 0 deletions messages/create.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# summary

create a change case record based on a template ID with one implementation step

# flags.template-id.summary

change case template id

# flags.configuration-item.summary

Full path from the configuration item, ex: Salesforce.SF_Off_Core.DeveloperTools.NPM
78 changes: 33 additions & 45 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,28 @@
"version": "2.1.1",
"bugs": "https://github.com/forcedotcom/change-case-management/issues",
"bin": {
"sfchangecase": "./bin/run"
"sfchangecase": "./bin/run.js"
},
"type": "module",
"dependencies": {
"@oclif/core": "^2.8.0",
"@salesforce/core": "^3.34.6",
"@salesforce/kit": "^1.9.2",
"@salesforce/sf-plugins-core": "^2.2.7",
"@salesforce/ts-types": "^1.2.2",
"tslib": "^2"
"@oclif/core": "^3.26.6",
"@salesforce/core": "^7.3.9",
"@salesforce/kit": "^3.1.0",
"@salesforce/sf-plugins-core": "^9.0.0",
"@salesforce/ts-types": "^2.0.9"
},
"devDependencies": {
"@oclif/plugin-command-snapshot": "^3.3.10",
"@salesforce/cli-plugins-testkit": "^3.3.2",
"@salesforce/dev-config": "^3.1.0",
"@salesforce/dev-scripts": "^4.1.3",
"@salesforce/plugin-command-reference": "^2.3.0",
"@salesforce/prettier-config": "^0.0.2",
"@salesforce/ts-sinon": "^1.4.2",
"@swc/core": "^1.3.34",
"@typescript-eslint/eslint-plugin": "^5.57.1",
"@typescript-eslint/parser": "^5.57.1",
"chai": "^4.3.7",
"eslint": "^8.37.0",
"eslint-config-prettier": "^8.5.0",
"eslint-config-salesforce": "^1.1.0",
"eslint-config-salesforce-license": "^0.2.0",
"eslint-config-salesforce-typescript": "^1.1.1",
"eslint-plugin-header": "^3.1.1",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jsdoc": "^40.1.1",
"eslint-plugin-sf-plugin": "^1.14.0",
"globby": "^8",
"husky": "^7.0.4",
"mocha": "^9.2.1",
"nyc": "^15.1.0",
"oclif": "^3.7.3",
"prettier": "^2.8.7",
"pretty-quick": "^3.1.0",
"shx": "^0.3.4",
"sinon": "10.0.0",
"ts-node": "^10.9.1",
"typescript": "^5.0.3",
"wireit": "^0.9.5"
"@oclif/plugin-command-snapshot": "^5.1.9",
"@salesforce/cli-plugins-testkit": "^5.3.5",
"@salesforce/dev-scripts": "^9.1.2",
"@salesforce/plugin-command-reference": "^3.0.86",
"eslint-plugin-sf-plugin": "^1.18.4",
"oclif": "^4.11.0",
"ts-node": "^10.9.2",
"typescript": "^5.4.3"
},
"engines": {
"node": ">=14.0.0"
"node": ">=18.0.0"
},
"files": [
"/lib",
Expand All @@ -64,6 +40,8 @@
"oclif": {
"commands": "./lib/commands",
"bin": "sfchangecase",
"flexibleTaxonomy": true,
"separator": " ",
"devPlugins": [
"@oclif/plugin-help",
"@oclif/plugin-command-snapshot",
Expand All @@ -81,12 +59,12 @@
"build": "wireit",
"clean": "sf-clean",
"clean-all": "sf-clean all",
"clean:lib": "shx rm -rf lib && shx rm -rf coverage && shx rm -rf .nyc_output && shx rm -f oclif.manifest.json",
"compile": "wireit",
"docs": "sf-docs",
"format": "wireit",
"link-check": "wireit",
"lint": "wireit",
"postpack": "shx rm -f oclif.manifest.json",
"postpack": "sf-clean --ignore-signing-artifacts",
"prepack": "sf-prepack",
"prepare": "sf-install",
"test": "wireit",
Expand Down Expand Up @@ -159,7 +137,8 @@
"test:command-reference",
"test:deprecation-policy",
"lint",
"test:json-schema"
"test:json-schema",
"link-check"
]
},
"test:only": {
Expand Down Expand Up @@ -188,7 +167,7 @@
]
},
"test:deprecation-policy": {
"command": "\"./bin/dev\" snapshot:compare",
"command": "node --loader ts-node/esm --no-warnings=ExperimentalWarning \"./bin/dev.js\" snapshot:compare",
"files": [
"src/**/*.ts"
],
Expand All @@ -208,12 +187,21 @@
"output": []
},
"test:json-schema": {
"command": "\"./bin/dev\" schema:compare",
"command": "node --loader ts-node/esm --no-warnings=ExperimentalWarning \"./bin/dev.js\" schema:compare",
"files": [
"src/**/*.ts",
"schemas"
],
"output": []
},
"link-check": {
"command": "echo \"We don't do link checks for this command\"",
"files": [
"./*.md",
"./!(CHANGELOG).md",
"messages/**/*.md"
],
"output": []
}
}
}
13 changes: 1 addition & 12 deletions src/changeCaseApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
import { Connection, SfError } from '@salesforce/core';
import { Ux } from '@salesforce/sf-plugins-core';
import { Case, ChangeCaseApiResponse, CreateCaseResponse, Implementation } from './types';
import { Case, Implementation } from './types.js';

const retrieveOrCreateBuildId = async (conn: Connection, ux: Ux, release: string): Promise<string> => {
const buildResults = await conn.query<{ Id: string }>(`SELECT Id FROM ADM_Build__c WHERE Name = '${release}'`);
Expand Down Expand Up @@ -109,14 +109,3 @@ export const retrieveCaseFromIdOrRelease = async ({
return cases[0];
}
};

export const parseErrors = (body: ChangeCaseApiResponse | CreateCaseResponse): string => {
if (body.errors) {
return body.errors.map((error) => error.message).join(',');
}
if (body.results?.length && typeof body.results[0].message === 'string') {
return body.results[0].message;
} else {
throw new SfError('Unexpected error response from change case API');
}
};
Loading

0 comments on commit 736242b

Please sign in to comment.