Skip to content

Commit

Permalink
Add output channel for debug info.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffersonking committed Aug 31, 2022
1 parent 98492dd commit e43a05e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/extension/index.activateGithubAnalyses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { readFileSync, existsSync } from 'fs';
import { observe } from 'mobx';
import fetch from 'node-fetch';
import { Log } from 'sarif';
import { authentication, extensions, workspace } from 'vscode';
import { authentication, Disposable, extensions, OutputChannel, window, workspace } from 'vscode';
import { augmentLog } from '../shared';
import '../shared/extension';
import { API, GitExtension, Repository } from './git';
Expand Down Expand Up @@ -47,7 +47,12 @@ export async function getInitializedGitApi(): Promise<API | undefined> {
});
}

export function activateGithubAnalyses(store: Store, panel: Panel) {
let outputChannel: OutputChannel;

export function activateGithubAnalyses(disposables: Disposable[], store: Store, panel: Panel) {
outputChannel = window.createOutputChannel('Sarif Viewer');
disposables.push(outputChannel);

const config = {
user: '',
repoName: '',
Expand Down Expand Up @@ -147,13 +152,17 @@ export function activateGithubAnalyses(store: Store, panel: Panel) {
store.banner = 'Refresh to check for more current results.';
store.analysisInfo = undefined;
}
const analysesString = analyses.map(({ created_at, commit_sha, id }) => `${created_at} ${commit_sha} ${id}`).join('\n');
outputChannel.appendLine(`Analyses:\n${analysesString}\n`);

// Find the intersection.
const git = await getInitializedGitApi();
if (!git) return undefined; // No GitExtension or GitExtension API.

const repo = git.repositories[0];
const commits = await repo.log({});
const commitsString = commits.map(({ commitDate, hash }) => `${commitDate?.toISOString().replace('.000', '')} ${hash}`).join('\n');
outputChannel.appendLine(`Commits:\n${commitsString}\n`);
const analysisInfo = analyses.find(analysis => {
return commits.some(commit => analysis.commit_sha === commit.hash);
});
Expand Down
2 changes: 1 addition & 1 deletion src/extension/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export async function activate(context: ExtensionContext) {
activateDecorations(disposables, store);
activateVirtualDocuments(disposables, store);
activateSelectionSync(disposables, panel);
activateGithubAnalyses(store, panel);
activateGithubAnalyses(disposables, store, panel);
activateAntiDriftStatusBarItem(disposables);
activateFixes(disposables, store, baser);

Expand Down

0 comments on commit e43a05e

Please sign in to comment.