Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feat/folder-recursive…
Browse files Browse the repository at this point in the history
…-rename-win32
  • Loading branch information
Pragadesh-45 committed Dec 5, 2024
2 parents 99f9123 + 915ebf3 commit 52e0193
Show file tree
Hide file tree
Showing 31 changed files with 2,908 additions and 4,513 deletions.
6,796 changes: 2,329 additions & 4,467 deletions package-lock.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,23 @@ import Modal from 'components/Modal';
const CreateEnvironment = ({ collection, onClose }) => {
const dispatch = useDispatch();
const inputRef = useRef();

// todo: Add this to global env too.
const validateEnvironmentName = (name) => {
return !collection?.environments?.some((env) => env?.name?.toLowerCase().trim() === name?.toLowerCase().trim());
};

const formik = useFormik({
enableReinitialize: true,
initialValues: {
name: ''
},
validationSchema: Yup.object({
name: Yup.string()
.min(1, 'must be at least 1 character')
.max(50, 'must be 50 characters or less')
.required('name is required')
.min(1, 'Must be at least 1 character')
.max(50, 'Must be 50 characters or less')
.required('Name is required')
.test('duplicate-name', 'Environment already exists', validateEnvironmentName)
}),
onSubmit: (values) => {
dispatch(addEnvironment(values.name, collection.uid))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const StyledWrapper = styled.div`
align-items: center;
justify-content: center;
width: 10px;
min-width: 10px;
padding: 0;
cursor: col-resize;
background: transparent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const RenameCollection = ({ collection, onClose }) => {
validationSchema: Yup.object({
name: Yup.string()
.min(1, 'must be at least 1 character')
.max(50, 'must be 50 characters or less')
.required('name is required')
}),
onSubmit: (values) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/bruno-app/src/components/Sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ const Sidebar = () => {
Star
</GitHubButton> */}
</div>
<div className="flex flex-grow items-center justify-end text-xs mr-2">v1.34.2</div>
<div className="flex flex-grow items-center justify-end text-xs mr-2">v1.36.0</div>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion packages/bruno-app/src/providers/App/useTelemetry.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const trackStart = () => {
event: 'start',
properties: {
os: platformLib.os.family,
version: '1.34.2'
version: '1.36.0'
}
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const getReadNotificationIds = () => {
return readNotificationIds;
} catch (err) {
toast.error('An error occurred while fetching read notifications');
return [];
}
};

Expand Down Expand Up @@ -58,14 +59,16 @@ export const notificationSlice = createSlice({
});
},
markNotificationAsRead: (state, action) => {
if (state.readNotificationIds.includes(action.payload.notificationId)) return;
const { notificationId } = action.payload;

if (state.readNotificationIds.includes(notificationId)) return;

const notification = state.notifications.find(
(notification) => notification.id === action.payload.notificationId
(notification) => notification.id === notificationId
);
if (!notification) return;

state.readNotificationIds.push(action.payload.notificationId);
state.readNotificationIds.push(notificationId);
setReadNotificationsIds(state.readNotificationIds);
notification.read = true;
},
Expand Down
3 changes: 2 additions & 1 deletion packages/bruno-app/src/utils/collections/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,8 @@ export const transformCollectionToSaveToExportAsFile = (collection, options = {}
script: si.request.script,
vars: si.request.vars,
assertions: si.request.assertions,
tests: si.request.tests
tests: si.request.tests,
docs: si.request.docs
};

// Handle auth object dynamically
Expand Down
10 changes: 9 additions & 1 deletion packages/bruno-app/src/utils/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,15 @@ export const relativeDate = (dateString) => {
export const humanizeDate = (dateString) => {
// See this discussion for why .split is necessary
// https://stackoverflow.com/questions/7556591/is-the-javascript-date-object-always-one-day-off
const date = new Date(dateString.split('-'));

if (!dateString || typeof dateString !== 'string') {
return 'Invalid Date';
}
const date = new Date(dateString);
if (isNaN(date.getTime())) {
return 'Invalid Date';
}

return date.toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
Expand Down
12 changes: 12 additions & 0 deletions packages/bruno-app/src/utils/common/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ describe('common utils', () => {
it('should return invalid date if the date is invalid', () => {
expect(humanizeDate('9999-99-99')).toBe('Invalid Date');
});

it('should return "Invalid Date" if the date is null', () => {
expect(humanizeDate(null)).toBe('Invalid Date');
});

it('should return a humanized date for a valid date in ISO format', () => {
expect(humanizeDate('2024-11-28T00:00:00Z')).toBe('November 28, 2024');
});

it('should return "Invalid Date" for a non-date string', () => {
expect(humanizeDate('some random text')).toBe('Invalid Date');
});
});

describe('relativeDate', () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/bruno-app/src/utils/curl/curl-to-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ function getDataString(request) {
console.error('Failed to parse JSON data:', error);
return { data: request.data.toString() };
}
} else if (contentType && contentType.includes('application/xml')) {
return { data: request.data };
}

const parsedQueryString = querystring.parse(request.data, { sort: false });
Expand Down
2 changes: 1 addition & 1 deletion packages/bruno-app/src/utils/curl/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const getRequestFromCurlCommand = (curlCommand, requestType = 'http-reque
} else if (contentType.includes('application/json')) {
body.mode = 'json';
body.json = convertToCodeMirrorJson(parsedBody);
} else if (contentType.includes('text/xml')) {
} else if (contentType.includes('xml')) {
body.mode = 'xml';
body.xml = parsedBody;
} else if (contentType.includes('application/x-www-form-urlencoded')) {
Expand Down
69 changes: 68 additions & 1 deletion packages/bruno-cli/src/commands/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,68 @@ const printRunSummary = (results) => {
};
};

const createCollectionFromPath = (collectionPath) => {
const environmentsPath = `${collectionPath}/environments`;
const getFilesInOrder = (collectionPath) => {
let collection = {
pathname: collectionPath
};
const traverse = (currentPath) => {
const filesInCurrentDir = fs.readdirSync(currentPath);

if (currentPath.includes('node_modules')) {
return;
}
const currentDirItems = [];
for (const file of filesInCurrentDir) {
const filePath = path.join(currentPath, file);
const stats = fs.lstatSync(filePath);
if (
stats.isDirectory() &&
filePath !== environmentsPath &&
!filePath.startsWith('.git') &&
!filePath.startsWith('node_modules')
) {
let folderItem = { name: file, pathname: filePath, type: 'folder', items: traverse(filePath) }
const folderBruFilePath = path.join(filePath, 'folder.bru');
const folderBruFileExists = fs.existsSync(folderBruFilePath);
if(folderBruFileExists) {
const folderBruContent = fs.readFileSync(folderBruFilePath, 'utf8');
let folderBruJson = collectionBruToJson(folderBruContent);
folderItem.root = folderBruJson;
}
currentDirItems.push(folderItem);
}
}

for (const file of filesInCurrentDir) {
if (['collection.bru', 'folder.bru'].includes(file)) {
continue;
}
const filePath = path.join(currentPath, file);
const stats = fs.lstatSync(filePath);

if (!stats.isDirectory() && path.extname(filePath) === '.bru') {
const bruContent = fs.readFileSync(filePath, 'utf8');
const bruJson = bruToJson(bruContent);
currentDirItems.push({
name: file,
pathname: filePath,
...bruJson
});
}
}
return currentDirItems
};
collection.items = traverse(collectionPath);
return collection;
};
return getFilesInOrder(collectionPath);
};

const getBruFilesRecursively = (dir, testsOnly) => {
const environmentsPath = 'environments';
const collection = {};

const getFilesInOrder = (dir) => {
let bruJsons = [];
Expand Down Expand Up @@ -359,6 +419,12 @@ const handler = async function (argv) {
const brunoConfigFile = fs.readFileSync(brunoJsonPath, 'utf8');
const brunoConfig = JSON.parse(brunoConfigFile);
const collectionRoot = getCollectionRoot(collectionPath);
let collection = createCollectionFromPath(collectionPath);
collection = {
brunoConfig,
root: collectionRoot,
...collection
}

if (clientCertConfig) {
try {
Expand Down Expand Up @@ -584,7 +650,8 @@ const handler = async function (argv) {
processEnvVars,
brunoConfig,
collectionRoot,
runtime
runtime,
collection
);

results.push({
Expand Down
16 changes: 11 additions & 5 deletions packages/bruno-cli/src/runner/interpolate-vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@ const getContentType = (headers = {}) => {
return contentType;
};

const interpolateVars = (request, envVars = {}, runtimeVariables = {}, processEnvVars = {}) => {
const interpolateVars = (request, envVariables = {}, runtimeVariables = {}, processEnvVars = {}) => {
const collectionVariables = request?.collectionVariables || {};
const folderVariables = request?.folderVariables || {};
const requestVariables = request?.requestVariables || {};
// we clone envVars because we don't want to modify the original object
envVars = cloneDeep(envVars);
envVariables = cloneDeep(envVariables);

// envVars can inturn have values as {{process.env.VAR_NAME}}
// so we need to interpolate envVars first with processEnvVars
forOwn(envVars, (value, key) => {
envVars[key] = interpolate(value, {
forOwn(envVariables, (value, key) => {
envVariables[key] = interpolate(value, {
process: {
env: {
...processEnvVars
Expand All @@ -36,7 +39,10 @@ const interpolateVars = (request, envVars = {}, runtimeVariables = {}, processEn

// runtimeVariables take precedence over envVars
const combinedVars = {
...envVars,
...collectionVariables,
...envVariables,
...folderVariables,
...requestVariables,
...runtimeVariables,
process: {
env: {
Expand Down
Loading

0 comments on commit 52e0193

Please sign in to comment.