@@ -264,79 +264,98 @@ class Worker implements vscode.Disposable {
264264 async run ( file : vscode . Uri ) : Promise < void > {
265265 if ( this . workspaceHas ( file ) ) {
266266 this . statusProvider . status = 'working' ;
267-
268267 await new Promise ( ( r ) => setTimeout ( r , 50 ) ) ;
269268
270- // bin/codeownership currenlty wants relative paths
271269 const cwd = this . workspace . uri . fsPath ;
272270 const relativePath = relative ( cwd , file . fsPath ) ;
273271
274272 logSpace ( ) ;
273+ log ( 'info' , `Checking ownership for ${ relativePath } ` ) ;
275274 log ( 'debug' , `cwd: ${ cwd } ` ) ;
276275 log ( 'debug' , `workspace: ${ this . workspace . uri . fsPath } ` ) ;
277276 log ( 'debug' , `file path: ${ file . fsPath } ` ) ;
278- log ( 'debug' , `relative path: ${ relativePath } ` ) ;
279277
280- try {
281- const output = await runCommand (
282- cwd ,
283- `bin/codeownership for_file "${ relativePath } " --json` ,
284- this . statusProvider ,
285- ) ;
278+ // Check if binary exists
279+ const checkBinary = await runCommand (
280+ cwd ,
281+ 'test -f bin/codeownership && echo "exists"' ,
282+ this . statusProvider
283+ ) ;
284+
285+ if ( ! checkBinary ) {
286+ log ( 'info' , 'No code ownership binary found in project' ) ;
287+ this . statusProvider . owner = undefined ;
288+ this . statusProvider . status = 'idle' ;
289+ return ;
290+ }
286291
292+ // Run ownership check
293+ const output = await runCommand (
294+ cwd ,
295+ `bin/codeownership for_file "${ relativePath } " --json` ,
296+ this . statusProvider ,
297+ ) ;
298+
299+ if ( ! output ) {
300+ log ( 'info' , 'Code ownership check returned no output' ) ;
301+ this . statusProvider . owner = undefined ;
302+ this . statusProvider . status = 'idle' ;
303+ return ;
304+ }
305+
306+ try {
287307 const obj = JSON . parse ( output ) ;
288308
289- if ( typeof obj . team_name !== 'string' ) {
290- log (
291- 'warning' ,
292- 'Missing expected property `team_name` in command output' ,
293- ) ;
294- }
295- if ( typeof obj . team_yml !== 'string' ) {
296- log (
297- 'warning' ,
298- 'Missing expected property `team_yml` in command output' ,
299- ) ;
309+ if ( ! obj . team_name ) {
310+ log ( 'info' , 'No team name found in ownership data' ) ;
311+ this . statusProvider . owner = undefined ;
312+ this . statusProvider . status = 'idle' ;
313+ return ;
300314 }
301315
302- if (
303- typeof obj . team_name === 'string' &&
304- typeof obj . team_yml === 'string' &&
305- obj . team_name !== 'Unowned'
306- ) {
307- const teamConfig = resolve ( this . workspace . uri . fsPath , obj . team_yml ) ;
308-
309- const actions : UserAction [ ] = [ ] ;
316+ if ( ! obj . team_yml ) {
317+ log ( 'info' , 'No team config file found in ownership data' ) ;
318+ this . statusProvider . owner = undefined ;
319+ this . statusProvider . status = 'idle' ;
320+ return ;
321+ }
310322
311- const slackChannel = await getSlackChannel ( teamConfig ) ;
323+ if ( obj . team_name === 'Unowned' ) {
324+ log ( 'info' , 'File is explicitly unowned' ) ;
325+ this . statusProvider . owner = undefined ;
326+ this . statusProvider . status = 'idle' ;
327+ return ;
328+ }
312329
313- if ( slackChannel ) {
314- actions . push ( {
315- title : `Slack: #${ slackChannel } ` ,
316- uri : vscode . Uri . parse (
317- `https://slack.com/app_redirect?channel=${ slackChannel } ` ,
318- ) ,
319- } ) ;
320- }
330+ const teamConfig = resolve ( this . workspace . uri . fsPath , obj . team_yml ) ;
331+ const actions : UserAction [ ] = [ ] ;
321332
333+ const slackChannel = await getSlackChannel ( teamConfig ) ;
334+ if ( slackChannel ) {
322335 actions . push ( {
323- title : 'View team config' ,
324- uri : vscode . Uri . parse ( teamConfig ) ,
336+ title : `Slack: #${ slackChannel } ` ,
337+ uri : vscode . Uri . parse (
338+ `https://slack.com/app_redirect?channel=${ slackChannel } ` ,
339+ ) ,
325340 } ) ;
326-
327- this . statusProvider . owner = {
328- filepath : file . fsPath ,
329- teamName : obj . team_name ,
330- teamConfig,
331- actions,
332- } ;
333- } else {
334- this . statusProvider . owner = undefined ;
335341 }
342+
343+ actions . push ( {
344+ title : 'View team config' ,
345+ uri : vscode . Uri . parse ( teamConfig ) ,
346+ } ) ;
347+
348+ this . statusProvider . owner = {
349+ filepath : file . fsPath ,
350+ teamName : obj . team_name ,
351+ teamConfig,
352+ actions,
353+ } ;
354+ this . statusProvider . status = 'idle' ;
355+ } catch ( error ) {
356+ log ( 'info' , `Invalid ownership data format: ${ error . message } ` ) ;
357+ this . statusProvider . owner = undefined ;
336358 this . statusProvider . status = 'idle' ;
337- } catch {
338- this . statusProvider . status = 'error' ;
339- log ( 'error' , 'Error parsing command output' ) ;
340359 }
341360 }
342361 }
0 commit comments