Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync main and release branches #837

Merged
merged 17 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
48e3cef
chore(release): v0.4.0-beta.0 ✨
narekhovhannisyan Jun 11, 2024
6d0be43
Merge pull request #806 from Green-Software-Foundation/release-v0.4.0…
narekhovhannisyan Jun 11, 2024
9e0e9e5
Merge pull request #827 from Green-Software-Foundation/main
narekhovhannisyan Jun 12, 2024
2fd2d62
chore(release): v0.4.0-beta.1 ✨
narekhovhannisyan Jun 12, 2024
0c4de59
fix(src): call `overrideConsoleMethods(false)` to prevent show debug …
manushak Jun 13, 2024
7e6772d
feat(src): read all piped data before checking params
narekhovhannisyan Jun 13, 2024
d4a492b
test(lib): fix load if diff cases
narekhovhannisyan Jun 13, 2024
8cd4266
test(util): fix parseManifestFromStdin case
narekhovhannisyan Jun 13, 2024
17948b6
fix(lib): move piped data reader
narekhovhannisyan Jun 13, 2024
dd97317
feat(types): add piped source manifest to load diff params
narekhovhannisyan Jun 13, 2024
f14790b
fix(util): return empty string if no manifest found
narekhovhannisyan Jun 13, 2024
640b0ca
fix(util): add newlines which improve readability
narekhovhannisyan Jun 13, 2024
3e3ec07
Merge pull request #834 from Green-Software-Foundation/fix-diff-log
narekhovhannisyan Jun 13, 2024
9aa1302
Merge pull request #835 from Green-Software-Foundation/fix-piping-issue
narekhovhannisyan Jun 13, 2024
c4f15c9
chore(release): v0.4.0 ✨
narekhovhannisyan Jun 13, 2024
6333b56
Merge branch 'release' into release-v0.4.0
narekhovhannisyan Jun 13, 2024
1342df8
Merge pull request #836 from Green-Software-Foundation/release-v0.4.0
narekhovhannisyan Jun 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@grnsft/if",
"description": "Impact Framework",
"version": "0.3.4",
"version": "0.4.0",
"author": {
"name": "Green Software Foundation",
"email": "info@gsf.com"
Expand Down
6 changes: 5 additions & 1 deletion src/__tests__/unit/lib/load.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ import {PARAMETERS} from '../../../config';
import {PluginParams} from '../../../types/interface';

import {STRINGS} from '../../../config';
import {parseManifestFromStdin} from '../../../util/helpers';
import {LoadDiffParams} from '../../../types/util/args';

const {INVALID_SOURCE} = STRINGS;

Expand Down Expand Up @@ -109,8 +111,10 @@ describe('lib/load: ', () => {

it('successfully loads target, and source from stdin.', async () => {
process.env.readline = 'valid-source';
const params = {
const piped = await parseManifestFromStdin();
const params: LoadDiffParams = {
targetPath: 'target-path.yml',
pipedSourceManifest: piped,
};

const response = await loadIfDiffFiles(params);
Expand Down
11 changes: 3 additions & 8 deletions src/__tests__/unit/util/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,16 +364,11 @@ describe('util/helpers: ', () => {

it('throws error if there is no manifest in stdin.', async () => {
process.env.readline = 'no_manifest';
const expectedMessage = 'Manifest not found in STDIN.';
expect.assertions(1);

try {
await parseManifestFromStdin();
} catch (error) {
if (error instanceof Error) {
expect(error.message).toEqual(expectedMessage);
}
}
const response = await parseManifestFromStdin();

expect(response).toEqual('');
});

it('returns empty string if there is no data in stdin.', async () => {
Expand Down
8 changes: 7 additions & 1 deletion src/diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,27 @@ import {loadIfDiffFiles} from './lib/load';
import {compare} from './lib/compare';

import {parseIfDiffArgs} from './util/args';
import {formatNotMatchingLog} from './util/helpers';
import {formatNotMatchingLog, parseManifestFromStdin} from './util/helpers';
import {validateManifest} from './util/validations';

import {CONFIG} from './config';
import {logger} from './util/logger';
import {debugLogger} from './util/debug-logger';

const {IF_DIFF} = CONFIG;
const {SUCCESS_MESSAGE, FAILURE_MESSAGE} = IF_DIFF;

const IfDiff = async () => {
const pipedSourceManifest = await parseManifestFromStdin();
const {sourcePath, targetPath} = parseIfDiffArgs();

// Call this function with false parameter to prevent log debug messages.
debugLogger.overrideConsoleMethods(false);

const {rawSourceManifest, rawTargetManifest} = await loadIfDiffFiles({
targetPath,
sourcePath,
pipedSourceManifest,
});
const [sourceManifest, targetManifest] = [
rawSourceManifest,
Expand Down
4 changes: 1 addition & 3 deletions src/lib/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as YAML from 'js-yaml';
import {ERRORS} from '../util/errors';
import {openYamlFileAsObject} from '../util/yaml';
import {readAndParseJson} from '../util/json';
import {parseManifestFromStdin} from '../util/helpers';

import {PARAMETERS} from '../config';
import {STRINGS} from '../config';
Expand Down Expand Up @@ -41,8 +40,7 @@ export const load = async (inputPath: string, paramPath?: string) => {
* Loads files to compare. As a source file checks if data is piped and then decides which one to take.
*/
export const loadIfDiffFiles = async (params: LoadDiffParams) => {
const {sourcePath, targetPath} = params;
const pipedSourceManifest = await parseManifestFromStdin();
const {sourcePath, targetPath, pipedSourceManifest} = params;

if (!sourcePath && !pipedSourceManifest) {
throw new CliInputError(INVALID_SOURCE);
Expand Down
1 change: 1 addition & 0 deletions src/types/util/args.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export type LoadDiffParams = {
sourcePath?: string;
targetPath: string;
pipedSourceManifest?: string;
};
4 changes: 2 additions & 2 deletions src/util/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ const collectPipedData = async () => {

/**
* Checks if there is piped data, tries to parse yaml from it.
* Throws error if there is piped info, but there is no valid manifest.
* Returns empty string if haven't found anything.
*/
export const parseManifestFromStdin = async () => {
const pipedSourceManifest = await collectPipedData();
Expand All @@ -177,7 +177,7 @@ export const parseManifestFromStdin = async () => {
const match = regex.exec(pipedSourceManifest);

if (!match) {
throw new Error('Manifest not found in STDIN.');
return '';
}

return match![1];
Expand Down
2 changes: 2 additions & 0 deletions src/util/validations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {STRINGS} from '../config/strings';

const {ManifestValidationError, InputValidationError} = ERRORS;
const {VALIDATING_MANIFEST} = STRINGS;

/**
* At least one property defined handler.
*/
Expand Down Expand Up @@ -148,5 +149,6 @@ const flattenPath = (path: (string | number)[]): string => {
const flattenPath = path.map(part =>
typeof part === 'number' ? `[${part}]` : part
);

return flattenPath.join('.');
};