Skip to content

Commit

Permalink
move count outside
Browse files Browse the repository at this point in the history
  • Loading branch information
julz0815 committed Mar 28, 2024
1 parent 93b6cd6 commit d19f69d
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 94 deletions.
91 changes: 44 additions & 47 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19218,60 +19218,57 @@ async function createSandboxBuild(vid, vkey, jarName, appId, version, deleteinco
return buildId;
}

let count = 0;
async function uploadFile(vid, vkey, jarName, appId, filepath, sandboxID) {
let command;
let count = 0;


const stat = util.promisify(fs.stat);
const stats = await stat(filepath);

// fs.stat(filepath, async (err, stats) => {
// if (err) {
// console.error(`Error reading path: ${err}`);
// } else {
if (stats.isFile()) {
console.log(`${filepath} is a file.`);
if ( sandboxID > 1){
core.info(`Uploading artifact (${filepath}) to Sandbox: ${sandboxID}`);
command = `java -jar ${jarName} -vid ${vid} -vkey ${vkey} -action UploadFile -appid ${appId} -filepath ${filepath} -sandboxid ${sandboxID}`
const output = await runCommand(command);
const outputXML = output.toString();
console.log(outputXML.indexOf('Uploaded'))
count++
}
else{
core.info(`Uploading artifact (${filepath}) to Policy Scan`);
command = `java -jar ${jarName} -vid ${vid} -vkey ${vkey} -action UploadFile -appid ${appId} -filepath ${filepath}`
const output = await runCommand(command);
const outputXML = output.toString();
console.log(outputXML.indexOf('Uploaded'))
count++
}
}
else if (stats.isDirectory()) {
console.log(`${filepath} is a directory.`);

const filesPromis = util.promisify(fs.readdir);
const files = await filesPromis(filepath);
files.forEach(async file => {
if ( sandboxID > 1){
core.info(`Uploading artifact ${file} to Sandbox: ${sandboxID}`);
command = `java -jar ${jarName} -vid ${vid} -vkey ${vkey} -action UploadFile -appid ${appId} -filepath ${filepath}${file} -sandboxid ${sandboxID}`
let output = await runCommand(command);
let outputXML = output.toString();
console.log(outputXML.indexOf('Uploaded'))
count++
}
else{
core.info(`Uploading artifact ${file} to Policy Scan`);
command = `java -jar ${jarName} -vid ${vid} -vkey ${vkey} -action UploadFile -appid ${appId} -filepath ${filepath}${file}`
let output = await runCommand(command);
let outputXML = output.toString();
console.log(outputXML.indexOf('Uploaded'))
count++
}
});
if (stats.isFile()) {
console.log(`${filepath} is a file.`);
if ( sandboxID > 1){
core.info(`Uploading artifact (${filepath}) to Sandbox: ${sandboxID}`);
command = `java -jar ${jarName} -vid ${vid} -vkey ${vkey} -action UploadFile -appid ${appId} -filepath ${filepath} -sandboxid ${sandboxID}`
const output = await runCommand(command);
const outputXML = output.toString();
console.log(outputXML.indexOf('Uploaded'))
count++
}
else{
core.info(`Uploading artifact (${filepath}) to Policy Scan`);
command = `java -jar ${jarName} -vid ${vid} -vkey ${vkey} -action UploadFile -appid ${appId} -filepath ${filepath}`
const output = await runCommand(command);
const outputXML = output.toString();
console.log(outputXML.indexOf('Uploaded'))
count++
}
}
else if (stats.isDirectory()) {
console.log(`${filepath} is a directory.`);

const filesPromis = util.promisify(fs.readdir);
const files = await filesPromis(filepath);
files.forEach(async file => {
if ( sandboxID > 1){
core.info(`Uploading artifact ${file} to Sandbox: ${sandboxID}`);
command = `java -jar ${jarName} -vid ${vid} -vkey ${vkey} -action UploadFile -appid ${appId} -filepath ${filepath}${file} -sandboxid ${sandboxID}`
let output = await runCommand(command);
let outputXML = output.toString();
console.log(outputXML.indexOf('Uploaded'))
count++
}
else{
core.info(`Uploading artifact ${file} to Policy Scan`);
command = `java -jar ${jarName} -vid ${vid} -vkey ${vkey} -action UploadFile -appid ${appId} -filepath ${filepath}${file}`
let output = await runCommand(command);
let outputXML = output.toString();
console.log(outputXML.indexOf('Uploaded'))
count++
}
});
}

return count;
}
Expand Down
91 changes: 44 additions & 47 deletions src/services/scan-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,60 +67,57 @@ async function createSandboxBuild(vid, vkey, jarName, appId, version, deleteinco
return buildId;
}

let count = 0;
async function uploadFile(vid, vkey, jarName, appId, filepath, sandboxID) {
let command;
let count = 0;


const stat = util.promisify(fs.stat);
const stats = await stat(filepath);

// fs.stat(filepath, async (err, stats) => {
// if (err) {
// console.error(`Error reading path: ${err}`);
// } else {
if (stats.isFile()) {
console.log(`${filepath} is a file.`);
if ( sandboxID > 1){
core.info(`Uploading artifact (${filepath}) to Sandbox: ${sandboxID}`);
command = `java -jar ${jarName} -vid ${vid} -vkey ${vkey} -action UploadFile -appid ${appId} -filepath ${filepath} -sandboxid ${sandboxID}`
const output = await runCommand(command);
const outputXML = output.toString();
console.log(outputXML.indexOf('Uploaded'))
count++
}
else{
core.info(`Uploading artifact (${filepath}) to Policy Scan`);
command = `java -jar ${jarName} -vid ${vid} -vkey ${vkey} -action UploadFile -appid ${appId} -filepath ${filepath}`
const output = await runCommand(command);
const outputXML = output.toString();
console.log(outputXML.indexOf('Uploaded'))
count++
}
}
else if (stats.isDirectory()) {
console.log(`${filepath} is a directory.`);

const filesPromis = util.promisify(fs.readdir);
const files = await filesPromis(filepath);
files.forEach(async file => {
if ( sandboxID > 1){
core.info(`Uploading artifact ${file} to Sandbox: ${sandboxID}`);
command = `java -jar ${jarName} -vid ${vid} -vkey ${vkey} -action UploadFile -appid ${appId} -filepath ${filepath}${file} -sandboxid ${sandboxID}`
let output = await runCommand(command);
let outputXML = output.toString();
console.log(outputXML.indexOf('Uploaded'))
count++
}
else{
core.info(`Uploading artifact ${file} to Policy Scan`);
command = `java -jar ${jarName} -vid ${vid} -vkey ${vkey} -action UploadFile -appid ${appId} -filepath ${filepath}${file}`
let output = await runCommand(command);
let outputXML = output.toString();
console.log(outputXML.indexOf('Uploaded'))
count++
}
});
if (stats.isFile()) {
console.log(`${filepath} is a file.`);
if ( sandboxID > 1){
core.info(`Uploading artifact (${filepath}) to Sandbox: ${sandboxID}`);
command = `java -jar ${jarName} -vid ${vid} -vkey ${vkey} -action UploadFile -appid ${appId} -filepath ${filepath} -sandboxid ${sandboxID}`
const output = await runCommand(command);
const outputXML = output.toString();
console.log(outputXML.indexOf('Uploaded'))
count++
}
else{
core.info(`Uploading artifact (${filepath}) to Policy Scan`);
command = `java -jar ${jarName} -vid ${vid} -vkey ${vkey} -action UploadFile -appid ${appId} -filepath ${filepath}`
const output = await runCommand(command);
const outputXML = output.toString();
console.log(outputXML.indexOf('Uploaded'))
count++
}
}
else if (stats.isDirectory()) {
console.log(`${filepath} is a directory.`);

const filesPromis = util.promisify(fs.readdir);
const files = await filesPromis(filepath);
files.forEach(async file => {
if ( sandboxID > 1){
core.info(`Uploading artifact ${file} to Sandbox: ${sandboxID}`);
command = `java -jar ${jarName} -vid ${vid} -vkey ${vkey} -action UploadFile -appid ${appId} -filepath ${filepath}${file} -sandboxid ${sandboxID}`
let output = await runCommand(command);
let outputXML = output.toString();
console.log(outputXML.indexOf('Uploaded'))
count++
}
else{
core.info(`Uploading artifact ${file} to Policy Scan`);
command = `java -jar ${jarName} -vid ${vid} -vkey ${vkey} -action UploadFile -appid ${appId} -filepath ${filepath}${file}`
let output = await runCommand(command);
let outputXML = output.toString();
console.log(outputXML.indexOf('Uploaded'))
count++
}
});
}

return count;
}
Expand Down

0 comments on commit d19f69d

Please sign in to comment.