Skip to content

Commit

Permalink
Merge branch 'main' of github.com:scolladon/sfdx-git-delta into featu…
Browse files Browse the repository at this point in the history
…re/validate_commit_sha

# Conflicts:
#	src/main.js
#	src/utils/cliHelper.js
  • Loading branch information
Abakumov authored and Abakumov committed Feb 28, 2022
2 parents 7d8f07c + 3ba28d5 commit bb59739
Show file tree
Hide file tree
Showing 49 changed files with 1,892 additions and 1,828 deletions.
47 changes: 11 additions & 36 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
name: CI

on:
pull_request_target:
branches: [main]
pull_request:
branches:
- main

jobs:
build-test:
build-check:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
Expand Down Expand Up @@ -48,36 +49,6 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}
continue-on-error: true

plugin-installation-test:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v2

- name: Setup node
uses: actions/setup-node@v1
with:
node-version: '14.x'

- name: Cache prep
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"

- name: Cache yarn
uses: actions/cache@v2
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install dependencies
run: yarn install

- name: Build plugin
run: yarn pack

- name: Install plugin
run: |
npm install -g sfdx-cli
Expand All @@ -88,14 +59,18 @@ jobs:

commit-lint:
runs-on: ubuntu-latest
if: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
steps:
- name: Lint commits
- name: Checkout sources
uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: wagoid/commitlint-github-action@v4

pr-lint:
- name: Lint commits
uses: wagoid/commitlint-github-action@v4
continue-on-error: true

pull-request-lint:
runs-on: ubuntu-latest
steps:
- name: Lint PR
Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Because this plugin is not signed, you will get a warning saying that "This plug

If you run your CI/CD jobs inside a Docker image, you can add the plugin to your image. Here is an example of a Dockerfile including the SGD plugin: https://github.com/mehdisfdc/sfdx-cli-gitlab

⚠️ The Salesforce CLI plugin is now the only supported way to install SGD. There used to be another way to install it directly through yarn or npm. The legacy `sgd` command is now deprecated and will be decommissioned soon.
⚠️ The Salesforce CLI plugin is now the only supported way to install SGD. There used to be another way to install it directly through yarn or npm. The legacy `sgd` command is now deprecated and decommissioned.

### Prerequisites

Expand All @@ -88,7 +88,8 @@ If you encounter this issue while having installed the correct version of node o
## How to use it?

<!-- commands -->
* [`sfdx sgd:source:delta -f <string> [-t <string>] [-r <filepath>] [-i <filepath>] [-D <filepath>] [-s <filepath>] [-W] [-o <filepath>] [-a <number>] [-d] [-n <filepath>] [-N <filepath>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`](#sfdx-sgdsourcedelta--f-string--t-string--r-filepath--i-filepath--d-filepath--s-filepath--w--o-filepath--a-number--d--n-filepath--n-filepath---json---loglevel-tracedebuginfowarnerrorfataltracedebuginfowarnerrorfatal)

- [`sfdx sgd:source:delta -f <string> [-t <string>] [-r <filepath>] [-i <filepath>] [-D <filepath>] [-s <filepath>] [-W] [-o <filepath>] [-a <number>] [-d] [-n <filepath>] [-N <filepath>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`](#sfdx-sgdsourcedelta--f-string--t-string--r-filepath--i-filepath--d-filepath--s-filepath--w--o-filepath--a-number--d--n-filepath--n-filepath---json---loglevel-tracedebuginfowarnerrorfataltracedebuginfowarnerrorfatal)

## `sfdx sgd:source:delta -f <string> [-t <string>] [-r <filepath>] [-i <filepath>] [-D <filepath>] [-s <filepath>] [-W] [-o <filepath>] [-a <number>] [-d] [-n <filepath>] [-N <filepath>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`

Expand All @@ -97,7 +98,7 @@ Generate the sfdx content in source format and destructive change from two git c
```
USAGE
$ sfdx sgd:source:delta -f <string> [-t <string>] [-r <filepath>] [-i <filepath>] [-D <filepath>] [-s <filepath>] [-W]
[-o <filepath>] [-a <number>] [-d] [-n <filepath>] [-N <filepath>] [--json] [--loglevel
[-o <filepath>] [-a <number>] [-d] [-n <filepath>] [-N <filepath>] [--json] [--loglevel
trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]
OPTIONS
Expand Down Expand Up @@ -143,6 +144,7 @@ OPTIONS
```

_See code: [src/commands/sgd/source/delta.ts](https://github.com/scolladon/sfdx-git-delta/blob/v4.12.1/src/commands/sgd/source/delta.ts)_

<!-- commandsstop -->

### Important note for Windows users:
Expand Down Expand Up @@ -372,7 +374,7 @@ Then use the JavaScript module
// sample/app.js
const sgd = require('sfdx-git-delta')

const work = sgd({
const work = await sgd({
to: '', // commit sha to where the diff is done. [default : "HEAD"]
from: '', // (required) commit sha from where the diff is done. [default : git rev-list --max-parents=0 HEAD]
output: '', // source package specific output. [default : "./output"]
Expand All @@ -391,7 +393,6 @@ console.log(JSON.stringify(work))

## Built With

- [commander](https://github.com/tj/commander.js/) - The complete solution for node.js command-line interfaces, inspired by Ruby's commander.
- [fast-xml-parser](https://github.com/NaturalIntelligence/fast-xml-parser) - Validate XML, Parse XML to JS/JSON and vise versa, or parse XML to Nimn rapidly without C/C++ based libraries and no callback
- [fs-extra](https://github.com/jprichardson/node-fs-extra) - Node.js: extra methods for the fs object like copy(), remove(), mkdirs().
- [ignore](https://github.com/kaelzhang/node-ignore#readme) - is a manager, filter and parser which implemented in pure JavaScript according to the .gitignore spec 2.22.1.
Expand Down
22 changes: 21 additions & 1 deletion __mocks__/child_process.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
'use strict'
const { EventEmitter, Readable } = require('stream')
const { EOL } = require('os')
const childProcess = jest.genMockFromModule('child_process')

childProcess.spawnSync = () => ({ stdout: '1stsha' })
let output = []
let error = false

childProcess.__setOutput = value => (output = value)
childProcess.__setError = value => (error = value)

childProcess.spawn.mockImplementation(() => {
const mock = new EventEmitter()
mock.stdout = new Readable({
read() {
if (!error && output.length) {
this.push(output.pop().join(EOL))
}
this.push(null)
mock.emit(error ? 'error' : 'close')
},
})
return mock
})

module.exports = childProcess
11 changes: 6 additions & 5 deletions __mocks__/fast-xml-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ fxp.__setMockContent = contents => {
}
}

fxp.parse = content => {
return JSON.parse(xml2json[content])
}

fxp.j2xParser = class j2xParser {
fxp.XMLParser = class XMLParser {
parse(content) {
return JSON.parse(xml2json[content])
}
}
fxp.XMLBuilder = class XMLBuilder {
build(content) {
return json2xml[content]
}
}
Expand Down
13 changes: 6 additions & 7 deletions __mocks__/fs-extra.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
const fse = jest.genMockFromModule('fs-extra')

fse.errorMode = false
fse.outputFileSyncError = false

fse.pathExistsSync = () => true
fse.outputFileError = false
fse.pathShouldExist = true

fse.pathExists = () => Promise.resolve(fse.pathShouldExist)
fse.copy = () => (fse.errorMode ? Promise.reject() : Promise.resolve())
fse.copySync = () => {
if (fse.errorMode) throw new Error()
}

fse.outputFileSync = () => {
if (fse.outputFileSyncError) throw new Error()
}
fse.outputFile = () =>
fse.outputFileError ? Promise.reject() : Promise.resolve()

module.exports = fse
46 changes: 26 additions & 20 deletions __mocks__/fs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'
const path = require('path')
const fs = jest.genMockFromModule('fs')
const { MASTER_DETAIL_TAG } = require('../src/utils/metadataConstants')

fs.errorMode = false
let mockFiles = {}
Expand All @@ -19,28 +20,33 @@ fs.__setMockFiles = newMockFiles => {
}
}

fs.readdirSync = directoryPath => mockFiles[path.basename(directoryPath)] ?? []
fs.promises = {}

fs.existsSync = filePath => filePathList.has(path.basename(filePath))
fs.promises.stat = elem =>
Promise.resolve({
isDirectory() {
return elem !== 'file'
},
isFile() {
return filePathList.has(elem)
},
})

fs.statSync = elem => ({
isDirectory() {
return elem !== 'file'
},
isFile() {
return filePathList.has(elem)
},
})
fs.promises.readFile = path =>
new Promise((res, rej) => {
if (fs.errorMode) rej(new Error())
else {
const result = Object.prototype.hasOwnProperty.call(mockContent, path)
? mockContent[path]
: MASTER_DETAIL_TAG
res(result)
}
})

fs.readFileSync = path => {
if (fs.errorMode) throw new Error()
return Object.prototype.hasOwnProperty.call(mockContent, path)
? mockContent[path]
: '<type>MasterDetail</type>'
}

fs.writeFileSync = () => {
if (fs.errorMode) throw new Error()
}
fs.promises.readdir = directoryPath =>
new Promise(res => {
const result = mockFiles[path.basename(directoryPath)] ?? []
res(result)
})

module.exports = fs
6 changes: 0 additions & 6 deletions __mocks__/git-state.js

This file was deleted.

20 changes: 10 additions & 10 deletions __tests__/__utils__/testHandlerHelper.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
'use strict'
const metadataManager = require('../../src/metadata/metadataManager')

global.globalMetadata = metadataManager.getDefinition('directoryName', 50)
global.testHandlerHelper = testContext => {
describe(`test if ${testContext.handler.name}`, () => {
let globalMetadata
beforeAll(async () => {
globalMetadata = await metadataManager.getDefinition('directoryName', 50)
})
describe.each(testContext.testData)(
'handles',
(type, changePath, expected, expectedType) => {
beforeEach(
() =>
(testContext.work.diffs = { package: {}, destructiveChanges: {} })
)
test('addition', () => {
test('addition', async () => {
const handler = new testContext.handler(
`A ${changePath}`,
type,
testContext.work,
// eslint-disable-next-line no-undef
globalMetadata
)
handler.handle()
await handler.handle()
expect(testContext.work.diffs.package).toHaveProperty(
expectedType ?? type,
expected
)
})
test('deletion', () => {
test('deletion', async () => {
const handler = new testContext.handler(
`D ${changePath}`,
type,
testContext.work,
// eslint-disable-next-line no-undef
globalMetadata
)
handler.handle()
await handler.handle()
expect(testContext.work.diffs.destructiveChanges).toHaveProperty(
expectedType ?? type,
expected
)
})
test('modification', () => {
test('modification', async () => {
const handler = new testContext.handler(
`M ${changePath}`,
type,
testContext.work,
// eslint-disable-next-line no-undef
globalMetadata
)
handler.handle()
await handler.handle()
expect(testContext.work.diffs.package).toHaveProperty(
expectedType ?? type,
expected
Expand Down
Loading

0 comments on commit bb59739

Please sign in to comment.