Skip to content

Commit

Permalink
Messing around with showing the headers
Browse files Browse the repository at this point in the history
  • Loading branch information
rajbos committed Oct 18, 2023
1 parent 8326138 commit 5a06768
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 35 deletions.
2 changes: 1 addition & 1 deletion vss-extension-dev.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifestVersion": 1,
"id": "GHAzDoWidget-DEV",
"version": "0.2.152",
"version": "0.2.171",
"public": false,
"name": "Advanced Security dashboard Widgets [DEV]",
"description": "[DEV] GitHub Advanced Security for Azure DevOps dashboard widgets",
Expand Down
11 changes: 8 additions & 3 deletions widgets/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@ function authenticatedGet(url) {
.then(authHeader =>
fetch(url, {
headers: {
"Content-Type": "application/json",
Authorization: authHeader
"Content-Type": "application/json",
Authorization: authHeader
}
})
)
.then(x => x.json());
.then(response => {
console.log(`Headers for [${url}]:`)
response.headers.forEach((value, name) => console.log(`${name}: ${value}`));

return response.json()
});
}
class AlertType {
constructor(name, value, display, displayPlural) {
Expand Down
142 changes: 111 additions & 31 deletions widgets/widgets/testing_widget/testing.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,61 +16,101 @@
["VSS/Service", "TFS/Dashboards/WidgetHelpers", "VSS/Context", "TFS/VersionControl/GitRestClient", "TFS/Core/RestClient"],
async function (Service, WidgetHelpers, context, GitWebApi, RestClient)
{
function setAlertValues(alerts, organization, projectName) {
const linkBase = `https://dev.azure.com/${organization}/${projectName}/_security`;
// set the alert counts
var dependencyAlertCount = $('p.dependencyAlertCount');
var currentValue = parseInt(dependencyAlertCount.text());
dependencyAlertCount.text(currentValue + alerts.dependencyAlerts);
const dependencyLinkValue = `${linkBase}?_t=dependencies`;
const dependencyLink = $('a.dependency-link');
//dependencyLink.attr('href', dependencyLinkValue);

var secretAlertCount = $('p.secretAlertCount');
var currentValue = parseInt(secretAlertCount.text());
secretAlertCount.text(currentValue + alerts.secretAlerts);
const secretLinkValue = `${linkBase}?_t=secrets`;
const secretLink = $('a.secret-link');
//secretLink.attr('href', secretLinkValue);

var codeAlertCount = $('p.codeAlertCount');
var currentValue = parseInt(codeAlertCount.text());
codeAlertCount.text(currentValue + alerts.codeAlerts);
const codeLinkValue = `${linkBase}?_t=codescanning`;
const codeLink = $('a.code-link');
//codeLink.attr('href', codeLinkValue);

var endDateTime = $('p.endDateTime');
endDateTime.text('end: ' + (new Date()).toISOString());
}

function testingLog(message) {
var $title = $('h2.ghazdo-title');
$title.text(message);
$title.text += message + '</br>';
}

function extraLogs(message) {
var $logs = $('#logs');
$logs.append(message + '</br>');
}

function showAlertInfo(organization, project, repo, repoAlerts, $queryinfocontainer) {
const $projectli = $queryinfocontainer.find(`#${project.id}`);
const $projectul = $projectli.find('ul');
consoleLog(`Found [${JSON.stringify(repoAlerts)}] dependency alerts for repo [${repo.name}]`)
$projectul.append(`<li>${repo.name} (${repoAlerts.dependencyAlerts}/${repoAlerts.secretAlerts}/${repoAlerts.codeAlerts})</li>\n`);

setAlertValues(repoAlerts, organization, project.name);
}

function showRepoInfo(repos, project, organization) {
consoleLog(`Found [${repos?.length}] repos for project [${project.name}]`);

var repoCounter = $('p.repoCount');
var currentValue = parseInt(repoCounter.text());
repoCounter.text(currentValue + repos.length);

if (repos.length > 0) {
const $projectli = $queryinfocontainer.find(`#${project.id}`);
$projectli.append(`<ul>\n`);
}

for (let repoIndex in repos) {
const repo = repos[repoIndex];
getAlerts(organization, project.name, repo.id).then(
repoAlerts => showAlertInfo(organization, project, repo, repoAlerts, $queryinfocontainer)
);
}

if (repos.length > 0) {
$queryinfocontainer.append(`</ul>\n`);
}
}

async function showProjectInfo(VSS, Service, GitWebApi, organization, projects) {
// show the project names:
$queryinfocontainer = $('#query-info-container');
$queryinfocontainer.append(`<ul>`);

var procjectCounter = $('p.projectCount');
procjectCounter.text(projects.length);

for (let index in projects) {
const project = projects[index];
consoleLog(`Checking project: [${JSON.stringify(project)}]`);
$queryinfocontainer.append(`<li id="${project.id}">${project.name}</li>\n`);
// load the repos for this project:
try {
//const repos = getRepos(VSS, Service, GitWebApi, project.name);
getRepos(VSS, Service, GitWebApi, project.name).then(function (repos, project) {
consoleLog(`Got this repos info ${dumpObject(repos)}`);
consoleLog(`Got this project info ${dumpObject(project)}`);
consoleLog(`Found [${repos?.length}] repos for project [${project.name}]`);

if (repos.length > 0) {
const $projectli = $queryinfocontainer.find(`#${project.id}`);
$projectli.append(`<ul>\n`);
}

for (let repoIndex in repos) {
const repo = repos[repoIndex];
//const repoAlerts = getAlerts(organization, project.name, repo.id)
getAlerts(organization, project.name, repo.id).then((repoAlerts, project) => {
const $projectli = $queryinfocontainer.find(`#${project.id}`);
const $projectul = $projectli.find('ul');
consoleLog(`Found [${JSON.stringify(repoAlerts)}] dependency alerts for repo [${repo.name}]`)
$projectul.append(`<li>${repo.name} (${repoAlerts.dependencyAlerts}/${repoAlerts.secretAlerts}/${repoAlerts.codeAlerts})</li>\n`);
});
}

if (repos.length > 0) {
$queryinfocontainer.append(`</ul>\n`);
}
});
getRepos(VSS, Service, GitWebApi, project.name).then(
repos => showRepoInfo(repos, project, organization)
);
}
catch (err) {
consoleLog(`error loading repos for project ${project.name}` + JSON.stringify(err));
}
};
$queryinfocontainer.append(`</ul>`);

// log the current time
extraLogs('done: ' + (new Date()).toISOString());
}

WidgetHelpers.IncludeWidgetStyles();
Expand Down Expand Up @@ -117,7 +157,8 @@

try {
// log the current time
extraLogs('start: ' + (new Date()).toISOString());
var startDateTime = $('p.startDateTime');
startDateTime.text('start: ' + (new Date()).toISOString());

const projects = await getProjects(VSS, Service, RestClient);
consoleLog(`Found [${projects?.length}] projects`);
Expand All @@ -142,7 +183,46 @@
<body>
<div class="widget GHAzDo-widget" style="overflow-y: scroll;">
<h2 class="ghazdo-title" title="" style="font-size: 15px;text-align: left;">Testing info</h2>
<p id="logs" style="font-size: 15px; text-align: left;"></p>
<p id="startDateTime" style="font-size: 15px; text-align: left;"></p>
<p id="endDateTime" style="font-size: 15px; text-align: left;"></p>

<div id="query-values-container" class="column-container">

<a class="link bolt-link project-link" target="_parent" href="">
<div class="column">
<h3>Projects</h3>
<p class="alertValue projectCount">0</p>
</div>
</a>

<a class="link bolt-link repo-link" target="_parent" href="">
<div class="column">
<h3>Repos</h3>
<p class="alertValue repoCount">0</p>
</div>
</a>

<a class="link bolt-link dependency-link" target="_parent" href="">
<div class="column">
<h3>Dependencies</h3>
<p class="alertValue dependencyAlertCount">0</p>
</div>
</a>

<a class="link bolt-link secret-link" target="_parent" href="">
<div class="column">
<h3>Secrets</h3>
<p class="alertValue secretAlertCount">0</p>
</div>
</a>

<a class="link bolt-link code-link" target="_parent" href="">
<div class="column">
<h3>Code</h3>
<p class="alertValue codeAlertCount">0</p>
</div>
</a>
</div>
<div id="query-info-container" class="column-container" style="font-size: 15px;text-align: left;display: block;">
Projects: </br>
</div>
Expand Down

0 comments on commit 5a06768

Please sign in to comment.