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

Scale up #29

Merged
merged 50 commits into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
d952169
temp changes on loading repos
rajbos Sep 25, 2023
522a62a
Loading repos now with documentCache
rajbos Sep 25, 2023
02b748f
Moved widget files into grouped folder
rajbos Sep 28, 2023
d842692
Fix build of task
jessehouwing Sep 28, 2023
3b65779
update
rajbos Sep 29, 2023
5f8423a
Merge branch 'scaleUp' into scaleUp
rajbos Sep 29, 2023
d35c4f8
delete generated file
rajbos Sep 29, 2023
0b809b5
Fixing issues with node_module mapping
rajbos Sep 29, 2023
27f9bf9
Loop over all projects and repos in the testing widget
rajbos Sep 29, 2023
992cabc
Adding actual checks for the dependency task
rajbos Oct 2, 2023
3d7a470
Cleanup
rajbos Oct 2, 2023
8541c45
Adding new widgets to the PR and Build windows
rajbos Oct 17, 2023
8326138
trying to fix the loop
rajbos Oct 18, 2023
5a06768
Messing around with showing the headers
rajbos Oct 18, 2023
9bb760a
Added generation of example repos at scale
rajbos Oct 19, 2023
fff114f
Suppress output
rajbos Oct 19, 2023
6b505a1
Add progress indication
rajbos Oct 19, 2023
a4b69aa
finetune the pipeline and setup
rajbos Oct 20, 2023
0d2a8d3
Enable scheduling the provisioning
rajbos Oct 21, 2023
201c64f
Logging cleanup
rajbos Oct 21, 2023
9cc6333
use the new make script in the build workflow
rajbos Oct 21, 2023
9b29229
add trigger for testing
rajbos Oct 21, 2023
6138f1e
configure the correct temp value
rajbos Oct 21, 2023
e828c59
fix script exec call
rajbos Oct 21, 2023
97ddd77
touchups to work with GHA
rajbos Oct 21, 2023
052f8be
fix CI
rajbos Oct 21, 2023
34cfd5e
attempt to fix the location
rajbos Oct 21, 2023
8e9030c
install tfx in the pipeline
rajbos Oct 21, 2023
aa13a64
fix the install
rajbos Oct 21, 2023
4a563a2
log more info
rajbos Oct 21, 2023
ddb0c7e
test path fix
rajbos Oct 21, 2023
7bc675b
testing smore
rajbos Oct 21, 2023
2272961
smore
rajbos Oct 21, 2023
b8e7f3c
convert to param
rajbos Oct 21, 2023
c3665b5
cleaning up
rajbos Oct 21, 2023
9e72269
fix current folder
rajbos Oct 21, 2023
160510f
commit the file itself
rajbos Oct 21, 2023
ff79c09
double check
rajbos Oct 21, 2023
5f69d3f
cleaning up
rajbos Oct 21, 2023
c378141
debugging
rajbos Oct 21, 2023
265e514
Only run on a PR
rajbos Oct 21, 2023
6ebde50
log url to fix the security config
rajbos Oct 21, 2023
2d4f8e8
check CI
rajbos Oct 21, 2023
fad9eb6
set the auth in remote url
rajbos Oct 21, 2023
6025818
change token config
rajbos Oct 21, 2023
8bd00ed
test
rajbos Oct 21, 2023
e79972f
add org name to overwrite
rajbos Oct 21, 2023
27169fa
change pat
rajbos Oct 21, 2023
5768175
Add a schedule instead of a push trigger
rajbos Oct 21, 2023
1c7cf8d
fix schedule
rajbos Oct 21, 2023
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
17 changes: 11 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
name: CI

on:
push:
pull_request:
branches:
- main

jobs:
build:
Expand All @@ -13,10 +15,13 @@ jobs:
with:
node-version: 16

- run: |
npm install
- name: Install tfx extension
run: |
npm install -g tfx-cli

- name: Create extension
run: tfx extension create --manifest-globs vss-extension-dev.json --rev-version
#- run: npm run test
- name: Build the extension
shell: pwsh
env:
AZURE_DEVOPS_PAT: ${{ secrets.AZURE_DEVOPS_PAT }}
run: |
.\make.ps1 -command "build"
25 changes: 25 additions & 0 deletions .github/workflows/createExampleRepos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Create Example Repos
on:
workflow_dispatch:
schedule:
- cron: "5 23 * * 5,6"

jobs:
create:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Configure contributor
run: |
git config --global user.email "github-actions@github.com"
git config --global user.name "GitHub Actions"

- name: Run script
shell: pwsh
env:
AZURE_DEVOPS_CREATE_PAT: ${{ secrets.AZURE_DEVOPS_CREATE_PAT }}
TEMP: ${{ runner.temp }}
PROVISIONCOUNT: ${{ vars.PROVISIONCOUNT }}
run: |
.\make.ps1 -command "provision" -provisionCount $env:PROVISIONCOUNT
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
node_modules/
*.vsix
dependencyReviewTask/*.js
dependencyReviewTask/*.js.map
1 change: 1 addition & 0 deletions dependencyReviewTask/.taskkey
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cdb7315b-109e-4717-bc9a-58e8128d1cce
135 changes: 135 additions & 0 deletions dependencyReviewTask/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import * as tl from "azure-pipelines-task-lib/task";
import { getHandlerFromToken, WebApi } from "azure-devops-node-api";

function getSystemAccessToken() : string {
tl.debug('Getting credentials for local feeds');
const auth = tl.getEndpointAuthorization('SYSTEMVSSCONNECTION', false);
if (auth.scheme === 'OAuth') {
tl.debug('Got an OAuth authentication token');
return auth.parameters['AccessToken'];
}
else {
tl.warning('Could not determine credentials to use');
}
}

interface IValue {
alertId: number;
title: string;
}
interface IResult {
count: number;
value: IValue[];
}

interface IResponse {
result: IResult;
}

async function getAlerts(connection: WebApi, orgSlug: string, project: string, repository: string, branchName: string) {
const branchUrl = `https://advsec.dev.azure.com/${orgSlug}/${project}/_apis/AdvancedSecurity/repositories/${repository}/alerts?criteria.alertType=1&criteria.ref=${branchName}&criteria.onlyDefaultBranchAlerts=true&useDatabaseProvider=true`;
let branchResponse: IResponse

try {
branchResponse = await connection.rest.get<IResult>(branchUrl);
}
catch (err: unknown) {
if (err instanceof Error) {
if (err.message.includes('Branch does not exist')) {
console.log(`Branch [${branchName}] does not exist in GHAzDo yet. Make sure to run the Dependency Scan task first on this branch (easiest to do in the same pipeline).`);
}
else {
console.log(`An error occurred: ${err.message}`);
}
}
}
return branchResponse
}

async function run() {
try {
// test to see if this build was triggered with a PR context
const buildReason = tl.getVariable('Build.Reason');
if (buildReason != 'PullRequest') {
tl.setResult(tl.TaskResult.Skipped, `This extension only works when triggered by a Pull Request and not by a [${buildReason}]`);
return
}

// todo: convert to some actual setting
const inputString: string | undefined = tl.getInput('samplestring', true);
if (inputString == 'bad') {
tl.setResult(tl.TaskResult.Failed, 'Bad input was given');

// stop the task execution
return;
}
console.log('Hello', inputString);

const token = getSystemAccessToken();
const authHandler = getHandlerFromToken(token);
const uri = tl.getVariable("System.CollectionUri");
const connection = new WebApi(uri, authHandler);

const organization = tl.getVariable('System.TeamFoundationCollectionUri');
const orgSlug = organization.split('/')[3];
const project = tl.getVariable('System.TeamProject');
const repository = tl.getVariable('Build.Repository.ID');
const sourceBranch = tl.getVariable('System.PullRequest.SourceBranch');
const sourceBranchName = sourceBranch?.split('/')[2];
const targetBranchName = tl.getVariable('System.PullRequest.targetBranchName');

console.log(`Retrieving alerts with token: [${token}], organization: [${organization}], orgSlug: [${orgSlug}], project: [${project}], sourceBranchName: [${sourceBranchName}], targetBranchName: [${targetBranchName}]`);

const sourceBranchResponse = await getAlerts(connection, orgSlug, project, repository, sourceBranchName);
const targetBranchResponse = await getAlerts(connection, orgSlug, project, repository, targetBranchName);

tl.debug(`source response: ${JSON.stringify(sourceBranchResponse)}`);
tl.debug(`target response: ${JSON.stringify(targetBranchResponse)}`);

if (sourceBranchResponse.result.count == 0) {
console.log('No alerts found for this branch');

tl.setResult(tl.TaskResult.Succeeded, `Found no alerts for the source branch`);
return;
}
else {
// check by result.alertId if there is a new alert or not (so alert not in targetBranch)

// first get the only the alertid's from the source branch
const sourceAlertIds = sourceBranchResponse.result.value.map((alert) => {return alert.alertId;});
// do the same for the target branch
const targetAlertIds = targetBranchResponse.result.value.map((alert) => {return alert.alertId;});
// now find the delta
const newAlertIds = sourceAlertIds.filter((alertId) => {
return !targetAlertIds.includes(alertId);
});

if (newAlertIds.length > 0) {

console.log(`Found [${sourceBranchResponse.result.count}] alerts for the source branch [${sourceBranchName}] of which [${newAlertIds.length}] are new:`);
for (const alertId of newAlertIds) {
// get the alert details:
const alertUrl = `https://dev.azure.com/${orgSlug}/${project}/_git/${repository}/alerts/${alertId}?branch=refs/heads/${sourceBranchName}`;
const alertTitle = sourceBranchResponse.result.value.find((alert) => {return alert.alertId == alertId;})?.title;
// and show them:
console.log(`- ${alertId}: ${alertTitle}, url: ${alertUrl}`);
}

tl.setResult(tl.TaskResult.Failed, `Found [${sourceBranchResponse.result.count}] alerts for the source branch [${sourceBranchName}] of which [${newAlertIds.length}] are new`);
}
else {
console.log(`Found no new alerts for the source branch [${sourceBranchName}]`);
tl.setResult(tl.TaskResult.Succeeded, `Found no new alerts for the source branch [${sourceBranchName}], only [${targetBranchResponse.result.count}] existing ones`);
}
}
}
catch (err: unknown) {
if (err instanceof Error) {
tl.setResult(tl.TaskResult.Failed, err.message);
} else {
tl.setResult(tl.TaskResult.Failed, 'An unknown error occurred');
}
}
}

run();
Loading