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

Fixed type errors happening frequently. #23

Merged
merged 2 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"parserOptions": {
"ecmaVersion": 2015
"ecmaVersion": 2020
},
"plugins": [
"security",
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/Integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '14.x'
node-version: '16.x'
- run: npm ci
- run: npm run test
78 changes: 78 additions & 0 deletions .github/workflows/draft-new-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Draft new release

on:
workflow_dispatch:
inputs:
version:
description: The version you want to release. Must be a valid semver version.
required: true
type: string

jobs:
draft-new-release:
if: startsWith(github.event.inputs.version, 'v')
name: Draft a new release
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Create release branch
run: git checkout -b release/${{ github.event.inputs.version }}

- name: Update changelog
uses: thomaseizinger/[email protected]
with:
version: ${{ github.event.inputs.version }}

- name: Initialize mandatory git config
run: |
git config user.name "GitHub Actions"
git config user.email [email protected]

- name: Bump version
run: npm version ${{ github.event.inputs.version }} --git-tag-version false

- name: Commit changelog and manifest files
id: make-commit
run: |
git add CHANGELOG.md package.json package-lock.json
git commit --message "Prepare release ${{ github.event.inputs.version }}"
echo "::set-output name=commit::$(git rev-parse HEAD)"

- name: Push new branch
run: git push origin release/${{ github.event.inputs.version }}

- name: Create pull request for main
uses: thomaseizinger/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
head: release/${{ github.event.inputs.version }}
base: main
title: "Release version ${{ github.event.inputs.version }}"
reviewers: ${{ github.actor }}
body: |
Hi @${{ github.actor }}!

This PR was created in response to a manual trigger of the release workflow here: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}.
I've updated the changelog and bumped the versions in the manifest files in this commit: ${{ steps.make-commit.outputs.commit }}.

- name: Create pull request for development
uses: thomaseizinger/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
head: release/${{ github.event.inputs.version }}
base: development
title: "Release version ${{ github.event.inputs.version }}"
reviewers: ${{ github.actor }}
body: |
Hi @${{ github.actor }}!

This PR was created in response to a manual trigger of the release workflow here: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}.
I've updated the changelog and bumped the versions in the manifest files in this commit: ${{ steps.make-commit.outputs.commit }}.
46 changes: 46 additions & 0 deletions .github/workflows/publish-new-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: "Publish new release"

on:
pull_request:
branches:
- main
types:
- closed

jobs:
release:
name: Publish new release
runs-on: ubuntu-latest
# only merged pull requests that begin with 'release/' or 'hotfix/' must trigger this job
if: github.event.pull_request.merged == true &&
(contains(github.event.pull_request.head.ref, 'release/') || contains(github.event.pull_request.head.ref, 'hotfix/'))
permissions:
contents: write

steps:
- name: Extract version from branch name (for release branches)
if: contains(github.event.pull_request.head.ref, 'release/')
run: |
BRANCH_NAME="${{ github.event.pull_request.head.ref }}"
VERSION=${BRANCH_NAME#release/}

echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV

- name: Extract version from branch name (for hotfix branches)
if: contains(github.event.pull_request.head.ref, 'hotfix/')
run: |
BRANCH_NAME="${{ github.event.pull_request.head.ref }}"
VERSION=${BRANCH_NAME#hotfix/}

echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV

- name: Create Release
uses: thomaseizinger/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
target_commitish: ${{ github.event.pull_request.merge_commit_sha }}
tag_name: ${{ env.RELEASE_VERSION }}
name: ${{ env.RELEASE_VERSION }}
draft: false
prerelease: false
22 changes: 11 additions & 11 deletions lib/HARToPostmanCollectionBodyMapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,18 +157,18 @@ function isMimeType(mimeType, expectedMimeType) {
* @returns {array} the list of parameters in the url
*/
function getParamsFromEncoded(harRequest) {
const urlParamsArray = harRequest.postData.params,
urlParamsAsText = harRequest.postData.text;
const urlParamsArray = harRequest?.postData?.params,
urlParamsAsText = harRequest?.postData?.text;
let params = [];
if (urlParamsArray.length > 0) {
if (urlParamsArray?.length > 0) {
params = urlParamsArray.map((param) => {
return {
key: param.name,
value: param.value
};
});
}
else if (urlParamsAsText) {
else if (typeof urlParamsAsText === 'string') {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is urlParamsAsText always expected to be of type string?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@agrwl-harsh Yes, we're directly using .split() function next line from this which should be only done if it's string to avoid typeerrors.

params = urlParamsAsText.split('&')
.map((keyValueAsText) => {
let [key, value] = keyValueAsText.split('=');
Expand All @@ -190,11 +190,11 @@ function getParamsFromEncoded(harRequest) {
* @returns {boolean} true if request privides from a har generated in safari
*/
function isSafariUrlEncoded(harRequest) {
const hasNoParams = harRequest.postData.params !== undefined &&
harRequest.postData.params.length === 0,
hasNoMimeType = harRequest.postData.mimeType === '',
const hasNoParams = harRequest?.postData?.params !== undefined &&
harRequest.postData.params?.length === 0,
hasNoMimeType = harRequest?.postData?.mimeType === '',
paramsInTextPattern = new RegExp('\\w*=[\\w\\s]+', 'g'),
contentText = harRequest.postData.text,
contentText = harRequest?.postData?.text || '',
paramsInTextByPattern = contentText.match(paramsInTextPattern),
paramsInTextBySplit = contentText.split('&'),
textContainsParams = paramsInTextByPattern &&
Expand All @@ -215,7 +215,7 @@ function isSafariUrlEncoded(harRequest) {
function mapBody(harRequest, options) {
let handledBody;
if (harRequest.bodySize > 0) {
const mimeType = harRequest.postData.mimeType;
const mimeType = harRequest?.postData?.mimeType;
if (isMimeType(mimeType, SUPPORTED_BODY_TYPES.applicationJson)) {
handledBody = mapBodyFromJson(harRequest, options);
}
Expand Down Expand Up @@ -251,8 +251,8 @@ function mapBody(harRequest, options) {
*/
function mapBodyResponse(harResponse, options) {
let handledBody;
if (harResponse.content.size > 0) {
const mimeType = harResponse.content.mimeType;
if (harResponse?.content?.size > 0) {
const mimeType = harResponse?.content?.mimeType;

switch (mimeType) {
case SUPPORTED_BODY_TYPES.applicationJson:
Expand Down
8 changes: 7 additions & 1 deletion lib/utils/urlUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ function decodeURL(url) {
if (url === undefined) {
return '';
}
return decodeURIComponent((String(url)).replace(/\+/g, '%20'));

try {
return decodeURIComponent((String(url)).replace(/\+/g, '%20'));
}
catch (e) {
return String(url);
}
}

module.exports = {
Expand Down
Loading
Loading