├── .gitignore ├── codefactor.png ├── toolbar-sample.png ├── .vscodeignore ├── README.md ├── tsconfig.json ├── package.json └── src └── extension.ts /.gitignore: -------------------------------------------------------------------------------- 1 | out 2 | node_modules -------------------------------------------------------------------------------- /codefactor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codefactor-io/vscode-repo-status/HEAD/codefactor.png -------------------------------------------------------------------------------- /toolbar-sample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codefactor-io/vscode-repo-status/HEAD/toolbar-sample.png -------------------------------------------------------------------------------- /.vscodeignore: -------------------------------------------------------------------------------- 1 | .vscode/** 2 | typings/** 3 | out/test/** 4 | test/** 5 | src/** 6 | **/*.map 7 | .gitignore 8 | tsconfig.json 9 | vsc-extension-quickstart.md 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # VS Code CodeFactor extension 2 | 3 | Shows public repository branch grade and issue count in the status bar. 4 | 5 | # Example 6 | 7 | ![Navigation](toolbar-sample.png) -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "target": "es2019", 5 | "lib": ["ES2019"], 6 | "outDir": "out", 7 | "sourceMap": true, 8 | "strict": true, 9 | "rootDir": "src" 10 | }, 11 | "exclude": [ 12 | "node_modules", 13 | ".vscode-test" 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "repo-status", 3 | "displayName": "Repository status", 4 | "description": "Shows repository branch grade and issue count in the status bar.", 5 | "version": "1.1.0", 6 | "publisher": "codefactor", 7 | "repository": { 8 | "type": "git", 9 | "url": "https://github.com/codefactor-io/vscode-repo-status" 10 | }, 11 | "icon": "codefactor.png", 12 | "bugs": { 13 | "url": "https://github.com/codefactor-io/vscode-repo-status/issues" 14 | }, 15 | "engines": { 16 | "vscode": "^1.25.0" 17 | }, 18 | "categories": [ 19 | "Programming Languages", 20 | "Linters" 21 | ], 22 | "keywords":[ 23 | "code analysis", 24 | "automated code review", 25 | "linters" 26 | ], 27 | "activationEvents": [ 28 | "onStartupFinished" 29 | ], 30 | "main": "./out/extension.js", 31 | "scripts": { 32 | "vscode:prepublish": "npm run compile", 33 | "compile": "tsc -p ./", 34 | "lint": "eslint . --ext .ts,.tsx", 35 | "watch": "tsc -watch -p ./" 36 | }, 37 | "devDependencies": { 38 | "typescript": "^4.0.2", 39 | "@typescript-eslint/eslint-plugin": "^3.0.2", 40 | "@typescript-eslint/parser": "^3.0.2", 41 | "eslint": "^7.1.0", 42 | "@types/vscode": "^1.25.0" 43 | }, 44 | "dependencies": { 45 | "axios": "^0.21.0" 46 | }, 47 | "extensionDependencies": [ 48 | "vscode.git" 49 | ] 50 | } 51 | -------------------------------------------------------------------------------- /src/extension.ts: -------------------------------------------------------------------------------- 1 | import * as vscode from 'vscode'; 2 | import axios from 'axios'; 3 | 4 | let statusBarItem: vscode.StatusBarItem; 5 | enum State { 6 | Found, 7 | NotFound, 8 | NoFetchUrl 9 | } 10 | let itemState: State; 11 | 12 | export function activate({ subscriptions }: vscode.ExtensionContext) { 13 | 14 | const command = 'codefactor.showRepoStats'; 15 | subscriptions.push(vscode.commands.registerCommand(command, () => { 16 | if (itemState == State.Found) 17 | { 18 | vscode.env.openExternal(vscode.Uri.parse('https://www.codefactor.io')); 19 | } 20 | else if (itemState == State.NotFound) 21 | { 22 | vscode.window.showWarningMessage(`Repository was not found on CodeFactor. Please make sure it's public and reviewed.`); 23 | } 24 | else if (itemState == State.NoFetchUrl) 25 | { 26 | vscode.window.showWarningMessage(`Working folder is not a git repository.`); 27 | } 28 | })); 29 | 30 | statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 100); 31 | statusBarItem.command = command; 32 | subscriptions.push(statusBarItem); 33 | subscriptions.push(vscode.workspace.onDidChangeWorkspaceFolders(updateStatusBarItem)); 34 | 35 | updateStatusBarItem(); 36 | } 37 | 38 | function updateStatusBarItem(): void { 39 | const gitExtension = vscode.extensions.getExtension('vscode.git'); 40 | var api = gitExtension?.exports.getAPI(1); 41 | 42 | api.onDidChangeState(() => { 43 | var repo = api.repositories[0]; 44 | if (repo == undefined) 45 | { 46 | statusBarItem.text = `$(megaphone) -`; 47 | statusBarItem.show(); 48 | itemState = State.NoFetchUrl; 49 | return; 50 | } 51 | var fetchUrl = repo.state.remotes[0]?.fetchUrl; 52 | var branchName = repo.state.HEAD.name; 53 | 54 | if (fetchUrl != null) 55 | { 56 | try { 57 | var url = `https://www.codefactor.io/home/repoMeta?cloneUrl=${fetchUrl}&branchName=${branchName}`; 58 | axios.get(url).then((resp) => { 59 | if (resp.status == 200 && resp.data?.issueCount != null) 60 | { 61 | statusBarItem.text = `$(megaphone) ${resp.data.grade}, ${resp.data.issueCount} issues`; 62 | statusBarItem.show(); 63 | itemState = State.Found; 64 | } 65 | else 66 | { 67 | statusBarItem.text = `$(megaphone) -`; 68 | statusBarItem.show(); 69 | itemState = State.NotFound; 70 | } 71 | }).then(undefined, err => { 72 | statusBarItem.text = `$(megaphone) -`; 73 | statusBarItem.show(); 74 | itemState = State.NotFound; 75 | }) 76 | } catch (exception) { 77 | statusBarItem.text = `$(megaphone) -`; 78 | statusBarItem.show(); 79 | itemState = State.NotFound; 80 | } 81 | } 82 | else { 83 | statusBarItem.text = `$(megaphone) -`; 84 | statusBarItem.show(); 85 | itemState = State.NoFetchUrl; 86 | } 87 | }) 88 | } 89 | --------------------------------------------------------------------------------