|
1 | | -import { window, commands, Uri, ExtensionContext, QuickPickItem } from 'vscode'; |
| 1 | +import * as path from 'path'; |
| 2 | +import * as fs from 'fs-extra'; |
| 3 | + |
| 4 | +import { window, commands, Uri, ExtensionContext, QuickPickItem, workspace, ViewColumn } from 'vscode'; |
2 | 5 | import { Credentials } from '../authentication'; |
3 | 6 | import { UserCancellationException } from '../commandRunner'; |
4 | | -import { showInformationMessageWithAction, showAndLogInformationMessage } from '../helpers'; |
| 7 | +import { showInformationMessageWithAction } from '../helpers'; |
5 | 8 | import { logger } from '../logging'; |
6 | 9 | import { QueryHistoryManager } from '../query-history'; |
7 | 10 | import { createGist } from './gh-actions-api-client'; |
@@ -41,9 +44,10 @@ export async function exportRemoteQueryResults( |
41 | 44 | if (exportFormat === gistOption) { |
42 | 45 | await exportResultsToGist(ctx, query, analysesResults); |
43 | 46 | } else if (exportFormat === localMarkdownOption) { |
44 | | - // TODO: Write function that creates local markdown files |
45 | | - // const markdownFiles = generateMarkdown(query, analysesResults, 'local'); |
46 | | - void showAndLogInformationMessage('Local markdown export not yet available'); |
| 47 | + const queryDirectoryPath = await queryHistoryManager.getQueryHistoryItemDirectory( |
| 48 | + queryHistoryItem |
| 49 | + ); |
| 50 | + await exportResultsToLocalMarkdown(queryDirectoryPath, query, analysesResults); |
47 | 51 | } |
48 | 52 | } |
49 | 53 |
|
@@ -95,3 +99,31 @@ async function exportResultsToGist( |
95 | 99 | } |
96 | 100 | } |
97 | 101 | } |
| 102 | + |
| 103 | +/** |
| 104 | + * Converts the results of a remote query to markdown and saves the files locally |
| 105 | + * in the query directory (where query results and metadata are also saved). |
| 106 | + */ |
| 107 | +async function exportResultsToLocalMarkdown( |
| 108 | + queryDirectoryPath: string, |
| 109 | + query: RemoteQuery, |
| 110 | + analysesResults: AnalysisResults[] |
| 111 | +) { |
| 112 | + const markdownFiles = generateMarkdown(query, analysesResults, 'local'); |
| 113 | + const exportedResultsPath = path.join(queryDirectoryPath, 'exported-results'); |
| 114 | + await fs.ensureDir(exportedResultsPath); |
| 115 | + for (const markdownFile of markdownFiles) { |
| 116 | + const filePath = path.join(exportedResultsPath, `${markdownFile.fileName}.md`); |
| 117 | + await fs.writeFile(filePath, markdownFile.content.join('\n'), 'utf8'); |
| 118 | + } |
| 119 | + const shouldOpenExportedResults = await showInformationMessageWithAction( |
| 120 | + `Variant analysis results exported to \"${exportedResultsPath}\".`, |
| 121 | + 'Open exported results' |
| 122 | + ); |
| 123 | + if (shouldOpenExportedResults) { |
| 124 | + const summaryFilePath = path.join(exportedResultsPath, '_summary.md'); |
| 125 | + const summaryFile = await workspace.openTextDocument(summaryFilePath); |
| 126 | + await window.showTextDocument(summaryFile, ViewColumn.One); |
| 127 | + await commands.executeCommand('revealFileInOS', Uri.file(summaryFilePath)); |
| 128 | + } |
| 129 | +} |
0 commit comments