11import { EOL } from 'os' ;
2- import { join , relative , sep } from 'path' ;
2+ import { join , relative , resolve , sep } from 'path' ;
33import * as cp from 'child_process' ;
44
55import * as minimatch from 'minimatch' ; // Only needed for githubValiator
66import * as vscode from 'vscode' ;
77
88let statusBarItem : vscode . StatusBarItem ;
99let channel : vscode . OutputChannel ;
10+ let owner : Owner | undefined = undefined ;
1011
1112function updateStatus ( active : vscode . TextEditor | undefined ) {
1213 console . log ( active ) ;
@@ -15,15 +16,16 @@ function updateStatus(active: vscode.TextEditor | undefined) {
1516 statusBarItem . show ( ) ;
1617 setTimeout ( ( ) => {
1718 try {
18- codeownershipValidator ( active . document . uri . fsPath ) . then ( ( owner ) => {
19+ codeownershipValidator ( active . document . uri . fsPath ) . then ( ( result ) => {
20+ owner = result ;
1921 if (
2022 active . document . uri . fsPath ===
2123 vscode . window . activeTextEditor ?. document . uri . fsPath
2224 ) {
23- if ( owner && owner . teamName !== 'Unowned' ) {
24- statusBarItem . text = `$(account) Owner: ${ owner . teamName } ` ;
25+ if ( result ) {
26+ statusBarItem . text = `$(account) Owner: ${ result . teamName } ` ;
2527 } else {
26- statusBarItem . text = `$(warning) Owner: Unowned ` ;
28+ statusBarItem . text = `$(warning) Owner: none ` ;
2729 }
2830 statusBarItem . show ( ) ;
2931 }
@@ -49,6 +51,31 @@ export function activate(context: vscode.ExtensionContext) {
4951 channel = vscode . window . createOutputChannel ( 'Code Ownership' ) ;
5052 context . subscriptions . push ( channel ) ;
5153
54+ context . subscriptions . push (
55+ vscode . commands . registerCommand (
56+ 'code-ownership-vscode.showOwnershipInfo' ,
57+ ( ) => {
58+ if ( owner ) {
59+ const filename = owner . filepath . split ( sep ) . slice ( - 1 ) [ 0 ] ;
60+ const { teamConfig } = owner ;
61+
62+ vscode . window
63+ . showInformationMessage (
64+ `${ filename } is owned by ${ owner . teamName } ` ,
65+ {
66+ title : 'View team config' ,
67+ action ( ) {
68+ const uri = vscode . Uri . parse ( teamConfig ) ;
69+ vscode . commands . executeCommand ( 'vscode.open' , uri ) ;
70+ } ,
71+ } ,
72+ )
73+ . then ( ( x ) => x ?. action ( ) ) ;
74+ }
75+ } ,
76+ ) ,
77+ ) ;
78+
5279 const disposable = vscode . commands . registerCommand (
5380 'code-ownership-vscode.validate' ,
5481 ( ) => {
@@ -62,6 +89,7 @@ export function activate(context: vscode.ExtensionContext) {
6289 statusBarItem = vscode . window . createStatusBarItem (
6390 vscode . StatusBarAlignment . Left ,
6491 ) ;
92+ statusBarItem . command = 'code-ownership-vscode.showOwnershipInfo' ;
6593
6694 vscode . window . onDidChangeActiveTextEditor ( updateStatus ) ;
6795 updateStatus ( vscode . window . activeTextEditor ) ;
@@ -128,12 +156,12 @@ const githubValidator: Validator = async (filepath) => {
128156 const codeowners = doc . getText ( ) . split ( EOL ) ;
129157
130158 for ( const line of codeowners ) {
131- const [ pattern , owner ] = line . split ( ' ' ) ;
159+ const [ pattern , teamName ] = line . split ( ' ' ) ;
132160
133161 if ( minimatch ( rel , pattern ) ) {
134162 return {
135163 filepath,
136- teamName : owner ,
164+ teamName,
137165 teamConfig : config . fsPath ,
138166 } ;
139167 }
@@ -158,11 +186,18 @@ const codeownershipValidator: Validator = async (filepath) => {
158186 log ( 'warning' , 'Missing expected property `team_yml` in command output' ) ;
159187 }
160188
161- if ( typeof obj . team_name === 'string' && typeof obj . team_yml === 'string' ) {
189+ if (
190+ typeof obj . team_name === 'string' &&
191+ typeof obj . team_yml === 'string' &&
192+ obj . team_name !== 'Unowned'
193+ ) {
162194 return {
163195 filepath,
164196 teamName : obj . team_name ,
165- teamConfig : obj . team_yml ,
197+ teamConfig : resolve (
198+ vscode . workspace . workspaceFolders ?. [ 0 ] ?. uri . fsPath || '' ,
199+ obj . team_yml ,
200+ ) ,
166201 } ;
167202 }
168203 } catch {
0 commit comments