Skip to content
This repository was archived by the owner on Apr 27, 2026. It is now read-only.

Commit 83b779c

Browse files
committed
feat: improve formatting of code owners list
Long owners lists make the file header item very long and may cause other items to wrap. Fix this by aggressively truncating the item label and showing the full list in the tooltip.
1 parent 7235918 commit 83b779c

5 files changed

Lines changed: 48 additions & 6 deletions

File tree

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,16 @@
3838
{
3939
"id": "codeOwnership.file",
4040
"actionItem": {
41-
"label": "Owner: ${get(context, `codeOwnership.file.${resource.uri}`)}"
41+
"label": "${get(context, `codeOwnership.file.${resource.uri}.label`)}",
42+
"description": "${get(context, `codeOwnership.file.${resource.uri}.description`)}"
4243
}
4344
}
4445
],
4546
"menus": {
4647
"editor/title": [
4748
{
4849
"action": "codeOwnership.file",
49-
"when": "!config.codeOwnership.hide && get(context, `codeOwnership.file.${resource.uri}`)"
50+
"when": "!config.codeOwnership.hide && get(context, `codeOwnership.file.${resource.uri}.label`)"
5051
}
5152
],
5253
"commandPalette": [

src/codeOwners.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import expect from 'expect'
2+
import { formatCodeOwners } from './codeOwners'
3+
4+
describe('formatCodeOwners', () => {
5+
it('formats null', () => expect(formatCodeOwners(null)).toEqual({ label: null, description: null }))
6+
it('formats empty', () =>
7+
expect(formatCodeOwners([])).toEqual({ label: 'No owner', description: 'File has no code owner' }))
8+
it('formats 1', () =>
9+
expect(formatCodeOwners(['alice'])).toEqual({ label: 'Owner: alice', description: 'Code owner: alice' }))
10+
it('formats 1 with long name', () =>
11+
expect(formatCodeOwners(['alice-long-name'])).toEqual({
12+
label: 'Owner',
13+
description: 'Code owner: alice-long-name',
14+
}))
15+
it('formats 2', () =>
16+
expect(formatCodeOwners(['alice', 'bob'])).toEqual({
17+
label: '2 owners',
18+
description: 'Code owners: alice, bob',
19+
}))
20+
})

src/codeOwners.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const SHOW_SINGLE_OWNER_MAX_LENGTH = 14
2+
3+
export function formatCodeOwners(owners: string[] | null): { label: string | null; description: string | null } {
4+
if (owners === null) {
5+
return { label: null, description: null }
6+
}
7+
if (owners.length === 0) {
8+
return { label: 'No owner', description: 'File has no code owner' }
9+
}
10+
if (owners.length === 1) {
11+
const owner = owners[0]
12+
return {
13+
label: owner.length <= SHOW_SINGLE_OWNER_MAX_LENGTH ? `Owner: ${owners[0]}` : 'Owner',
14+
description: `Code owner: ${owner}`,
15+
}
16+
}
17+
return {
18+
label: `${owners.length} owners`,
19+
description: `Code owners: ${owners.join(', ')}`,
20+
}
21+
}

src/extension.test.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/extension.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { combineLatest, from, Observable } from 'rxjs'
22
import { startWith } from 'rxjs/operators'
33
import * as sourcegraph from 'sourcegraph'
44
import { getCodeOwners } from './codeownersFile'
5+
import { formatCodeOwners } from './codeOwners'
56

67
export function activate(ctx: sourcegraph.ExtensionContext): void {
78
ctx.subscriptions.add(
@@ -27,8 +28,10 @@ export function activate(ctx: sourcegraph.ExtensionContext): void {
2728
console.error(`Error getting code owners for ${doc.uri}:`, err)
2829
}
2930
}
31+
const { label, description } = formatCodeOwners(owners)
3032
sourcegraph.internal.updateContext({
31-
[`codeOwnership.file.${doc.uri}`]: owners && owners.length > 0 ? owners.join(', ') : null,
33+
[`codeOwnership.file.${doc.uri}.label`]: label,
34+
[`codeOwnership.file.${doc.uri}.description`]: description,
3235
})
3336
})
3437
)

0 commit comments

Comments
 (0)