From 842c6b7c429173304052329d72002af83c90ef72 Mon Sep 17 00:00:00 2001 From: tiagobcx Date: Fri, 15 Mar 2024 11:10:29 +0000 Subject: [PATCH] adding apikey to sast gpt command + fixing codebashing link --- media/view.js | 107 +++++++++++++++++++++++++------------------------- src/cx/cx.ts | 2 +- 2 files changed, 55 insertions(+), 54 deletions(-) diff --git a/media/view.js b/media/view.js index cfcea21f..64202d30 100644 --- a/media/view.js +++ b/media/view.js @@ -288,8 +288,8 @@ } }); - - function registerCodebashingEventListener(){ + + function registerCodebashingEventListener() { let codebashingElement = document.getElementById('cx_codebashing'); if (codebashingElement) { codebashingElement.addEventListener('click', () => { @@ -329,11 +329,11 @@ for (let learn of learnArray) { for (let code of learn.samples) { let learnSectionDiv = document.createElement('div'); - learnSectionDiv.setAttribute('class','learn-section'); + learnSectionDiv.setAttribute('class', 'learn-section'); let codeTitlePara = document.createElement('p'); - codeTitlePara.textContent = ''+code.title+' using '+code.progLanguage; + codeTitlePara.textContent = '' + code.title + ' using ' + code.progLanguage; let preCode = document.createElement('pre'); - preCode.setAttribute('class','pre-code'); + preCode.setAttribute('class', 'pre-code'); let codeElement = document.createElement('code'); codeElement.textContent = code.code.replaceAll("<", "<").replaceAll(">", ">"); preCode.appendChild(codeElement); @@ -379,36 +379,37 @@ return html; } - function codeBashingSection(result){ - let codeBashingSection = ""; - if(result.sastNodes.length > 0){ - let headerItemCodebashingDiv = document.createElement('div'); - headerItemCodebashingDiv.setAttribute('id','cx_header_codebashing'); - headerItemCodebashingDiv.style.marginBottom = '20px'; - let codebashingLinkSpan = document.createElement('span'); - codebashingLinkSpan.setAttribute('class','codebashing-link'); - codebashingLinkSpan.textContent='Learn more at '; - let orangeColorSpan = document.createElement('span'); - orangeColorSpan.setAttribute('class','orange-color'); - orangeColorSpan.textContent='>_'; - let codeBashingSpan = document.createElement('span'); - codeBashingSpan.setAttribute('class','codebashing-link-value'); - codeBashingSpan.setAttribute('title',"Learn more about "+result.queryName +" using Checkmarx's eLearning platform"); - codeBashingSpan.textContent = 'codebashing'; - codebashingLinkSpan.appendChild(orangeColorSpan); - codebashingLinkSpan.appendChild(codeBashingSpan); - headerItemCodebashingDiv.appendChild(codebashingLinkSpan); - return headerItemCodebashingDiv.outerHTML; - } - return codeBashingSection; + function codeBashingSection(result) { + let codeBashingSection = ""; + if (result.sastNodes.length > 0) { + let headerItemCodebashingDiv = document.createElement('div'); + headerItemCodebashingDiv.setAttribute('id', 'cx_header_codebashing'); + headerItemCodebashingDiv.style.marginBottom = '20px'; + let codebashingLinkSpan = document.createElement('span'); + codebashingLinkSpan.setAttribute('class', 'codebashing-link'); + codebashingLinkSpan.textContent = 'Learn more at '; + let orangeColorSpan = document.createElement('span'); + orangeColorSpan.setAttribute('class', 'orange-color'); + orangeColorSpan.textContent = '>_'; + let codeBashingSpan = document.createElement('span'); + codeBashingSpan.setAttribute('class', 'codebashing-link-value'); + codeBashingSpan.setAttribute('id', 'cx_codebashing'); + codeBashingSpan.setAttribute('title', "Learn more about " + result.queryName + " using Checkmarx's eLearning platform"); + codeBashingSpan.textContent = 'codebashing'; + codebashingLinkSpan.appendChild(orangeColorSpan); + codebashingLinkSpan.appendChild(codeBashingSpan); + headerItemCodebashingDiv.appendChild(codebashingLinkSpan); + return headerItemCodebashingDiv.outerHTML; + } + return codeBashingSection; } - + function riskSection(risk) { let learnSectionDiv = document.createElement('div'); - learnSectionDiv.setAttribute('class','learn-section'); + learnSectionDiv.setAttribute('class', 'learn-section'); let learnHeaderPara = document.createElement('p'); - learnHeaderPara.setAttribute('class','learn-header'); + learnHeaderPara.setAttribute('class', 'learn-header'); learnHeaderPara.textContent = 'Risk'; let riskPara = document.createElement('p'); riskPara.innerHTML = risk; @@ -420,9 +421,9 @@ function causeSection(cause) { let learnSectionDiv = document.createElement('div'); - learnSectionDiv.setAttribute('class','learn-section'); + learnSectionDiv.setAttribute('class', 'learn-section'); let learnHeaderPara = document.createElement('p'); - learnHeaderPara.setAttribute('class','learn-header'); + learnHeaderPara.setAttribute('class', 'learn-header'); learnHeaderPara.textContent = 'Cause'; let causePara = document.createElement('p'); causePara.innerHTML = cause; @@ -433,12 +434,12 @@ function recommendationSection(recommendations) { let learnSectionDiv = document.createElement('div'); - learnSectionDiv.setAttribute('class','learn-section'); + learnSectionDiv.setAttribute('class', 'learn-section'); let learnHeaderPara = document.createElement('p'); - learnHeaderPara.setAttribute('class','learn-header'); + learnHeaderPara.setAttribute('class', 'learn-header'); learnHeaderPara.textContent = 'General Recommendations'; let recommendationsSpan = document.createElement('span'); - recommendationsSpan.setAttribute('class','code-sample'); + recommendationsSpan.setAttribute('class', 'code-sample'); recommendationsSpan.innerHTML = recommendations; learnSectionDiv.appendChild(learnHeaderPara); learnSectionDiv.appendChild(recommendationsSpan); @@ -447,42 +448,42 @@ // Individual changes - function infoChanges(change) { + function infoChanges(change) { let infoDiv = document.createElement("div"); let severityPara = document.createElement("p"); let severityClass = change.Severity.length > 0 ? ("select-" + change.Severity.toLowerCase()) : ""; - severityPara.setAttribute('class',severityClass); + severityPara.setAttribute('class', severityClass); var severity = change.Severity.length > 0 ? change.Severity : "No changes in severity."; severityPara.textContent = severity; let statePara = document.createElement("p"); - statePara.setAttribute('class','state'); + statePara.setAttribute('class', 'state'); var state = change.State.length > 0 ? change.State.replaceAll("_", " ") : "No changes in state."; statePara.textContent = state; infoDiv.appendChild(severityPara); infoDiv.appendChild(statePara); - if(change.Comment.length > 0){ - let commentPara = document.createElement("p"); - commentPara.setAttribute('class','comment'); - commentPara.textContent = change.Comment; - infoDiv.appendChild(commentPara); + if (change.Comment.length > 0) { + let commentPara = document.createElement("p"); + commentPara.setAttribute('class', 'comment'); + commentPara.textContent = change.Comment; + infoDiv.appendChild(commentPara); } return infoDiv.outerHTML; } // Generic card for changes - function userCardInfo(username, date, info) { + function userCardInfo(username, date, info) { let historyContainerDiv = document.createElement('div'); - historyContainerDiv.setAttribute('class','history-container'); + historyContainerDiv.setAttribute('class', 'history-container'); let historyHeaderDiv = document.createElement('div'); - historyHeaderDiv.setAttribute('class','history-header'); + historyHeaderDiv.setAttribute('class', 'history-header'); let userNameDiv = document.createElement('div'); - userNameDiv.setAttribute('class','username'); + userNameDiv.setAttribute('class', 'username'); userNameDiv.textContent = username; let dateDiv = document.createElement('div'); - dateDiv.setAttribute('class','date'); + dateDiv.setAttribute('class', 'date'); dateDiv.textContent = date; let textContentDiv = document.createElement('div'); - textContentDiv.setAttribute('class','text-content'); + textContentDiv.setAttribute('class', 'text-content'); textContentDiv.innerHTML = info; historyHeaderDiv.appendChild(userNameDiv); historyHeaderDiv.appendChild(dateDiv); @@ -493,13 +494,13 @@ function loader() { let historyContainerLoaderDiv = document.createElement('div'); - historyContainerLoaderDiv.setAttribute('id','history-container-loader'); - historyContainerLoaderDiv.setAttribute('class','center'); + historyContainerLoaderDiv.setAttribute('id', 'history-container-loader'); + historyContainerLoaderDiv.setAttribute('class', 'center'); let historyContainerLoaderPara = document.createElement('p'); - historyContainerLoaderPara.setAttribute('class','history-container-loader'); + historyContainerLoaderPara.setAttribute('class', 'history-container-loader'); historyContainerLoaderPara.textContent = 'Loading changes'; let loaderDiv = document.createElement('div'); - loaderDiv.setAttribute('class','loader'); + loaderDiv.setAttribute('class', 'loader'); historyContainerLoaderDiv.appendChild(historyContainerLoaderPara); historyContainerLoaderDiv.appendChild(loaderDiv); return historyContainerLoaderDiv.outerHTML; diff --git a/src/cx/cx.ts b/src/cx/cx.ts index 70fdee55..86baf689 100644 --- a/src/cx/cx.ts +++ b/src/cx/cx.ts @@ -35,7 +35,7 @@ export class Cx implements CxPlatform { async runSastGpt(message: string, filePath: string, resultId: string, conversationId?: string) { const resultsFilePath = getResultsFilePath(); - const cx = new CxWrapper(this.getBaseAstConfiguration()); + const cx = new CxWrapper(this.getAstConfiguration()); const gptToken = vscode.workspace .getConfiguration(constants.gptCommandName) .get(constants.gptSettingsKey) as string;