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

adding apikey to sast gpt command + fixing codebashing link #792

Merged
merged 1 commit into from
Mar 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
107 changes: 54 additions & 53 deletions media/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@
}
});

function registerCodebashingEventListener(){

function registerCodebashingEventListener() {
let codebashingElement = document.getElementById('cx_codebashing');
if (codebashingElement) {
codebashingElement.addEventListener('click', () => {
Expand Down Expand Up @@ -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("<", "&lt;").replaceAll(">", "&gt");
preCode.appendChild(codeElement);
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/cx/cx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading