Skip to content

Commit

Permalink
Add support for bitbucket, minor extension cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
noahm committed Sep 19, 2024
1 parent 8b558c5 commit beffe71
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 96 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"out": true // set this to false to include "out" folder in search results
},
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
"typescript.tsc.autoDetect": "off"
"typescript.tsc.autoDetect": "off",
"typescript.tsdk": "node_modules/typescript/lib"
}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to the "codeowners-extended" extension will be documented in this file according to recommendations of [Keep a Changelog](http://keepachangelog.com/).

## [v1.1.0] - 2024-09-19

- Add support for `.bitbucket` folder for CODEOWNERS location.

## [v1.0.1] - 2022-10-06

- Fix a bug handling paths on windows. The extension is now fully cross-platform!
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
],
"activationEvents": [
"workspaceContains:./CODEOWNERS",
"workspaceContains:./.bitbucket/CODEOWNERS",
"workspaceContains:./.github/CODEOWNERS",
"workspaceContains:./.gitlab/CODEOWNERS",
"workspaceContains:./docs/CODEOWNERS"
Expand Down Expand Up @@ -68,6 +69,6 @@
},
"dependencies": {
"clipboardy": "^2.0.0",
"@nmann/codeowners": "^1.0.0"
"@nmann/codeowners": "^2.1.0"
}
}
29 changes: 16 additions & 13 deletions src/owner-display.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import * as vscode from "vscode";
import Codeowners from "@nmann/codeowners";
import Codeowners, { ReadOnlyDict } from "@nmann/codeowners";
import { getNthProperty } from "./utils";

export class OwnerDisplay {
private statusBarItem = vscode.window.createStatusBarItem(
vscode.StatusBarAlignment.Right,
1000
1000,
);
private codeowners: Codeowners | null = null;
public teamInfo: Map<string, Record<string, string>> | null = null;
private pathPrefixLength = 0;
public teamInfo: Map<string, ReadOnlyDict<string>> | null = null;

constructor() {
this.refreshOwnersFile();
Expand All @@ -25,24 +24,25 @@ export class OwnerDisplay {
if (!this.codeowners || !vscode.window.activeTextEditor) {
return [];
}
return this.codeowners.getOwner(
vscode.window.activeTextEditor.document.fileName.slice(
this.pathPrefixLength
)
);
try {
return this.codeowners.getOwner(
vscode.window.activeTextEditor.document.fileName,
);
} catch {
return [];
}
}

public refreshOwnersFile() {
try {
this.codeowners = new Codeowners(
vscode.workspace.workspaceFolders![0].uri.fsPath
vscode.workspace.workspaceFolders![0].uri.fsPath,
);
this.teamInfo = new Map(
this.codeowners.contactInfo
.map((teamInfo) => [getNthProperty(teamInfo, 0)!, teamInfo] as const)
.filter((item) => !!item[0])
.filter((item) => !!item[0]),
);
this.pathPrefixLength = this.codeowners.codeownersDirectory.length + 1;
} catch (e) {
this.codeowners = null;
this.teamInfo = null;
Expand Down Expand Up @@ -81,7 +81,10 @@ export class OwnerDisplayController {
// create a combined disposable from both event subscriptions
this.disposable = vscode.Disposable.from(
vscode.window.onDidChangeActiveTextEditor(this.onEditorChange, this),
vscode.workspace.onDidChangeWorkspaceFolders(this.onWorkspaceChange, this)
vscode.workspace.onDidChangeWorkspaceFolders(
this.onWorkspaceChange,
this,
),
);

// update the counter for the current file
Expand Down
14 changes: 9 additions & 5 deletions src/quick-picks.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { ReadOnlyDict } from "@nmann/codeowners";
import * as clipboardy from "clipboardy";
import * as vscode from "vscode";
import { getNthProperty } from "./utils";

export async function quickPickTeamList(teams: Record<string, string>[]) {
export async function quickPickTeamList(
teams: ReadonlyArray<ReadOnlyDict<string>>,
) {
const items = teams
.map((info) => ({
label: getNthProperty(info, 0) || "",
Expand All @@ -22,20 +25,21 @@ export async function quickPickTeamList(teams: Record<string, string>[]) {
}
}

export async function quickPickTeamFields(teamInfo: Record<string, string>) {
export async function quickPickTeamFields(teamInfo: ReadOnlyDict<string>) {
const keys = Object.keys(teamInfo) as Array<string>;
const itemField = await vscode.window.showQuickPick(
(Object.keys(teamInfo) as Array<keyof typeof teamInfo>).map((key) => ({
keys.map((key) => ({
label: teamInfo[key] || "",
description: key,
})),
{
placeHolder: "Select a field to copy",
}
},
);
if (itemField && itemField.label) {
clipboardy.writeSync(itemField.label);
vscode.window.showInformationMessage(
`Copied "${itemField.label}" to clipboard`
`Copied "${itemField.label}" to clipboard`,
);
}
}
4 changes: 3 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export function getNthProperty(obj: Record<string, string>, n: number) {
import { ReadOnlyDict } from "@nmann/codeowners";

export function getNthProperty(obj: ReadOnlyDict<string>, n: number) {
const keys = Object.keys(obj);
if (keys.length > n) {
return obj[keys[n]];
Expand Down
Loading

0 comments on commit beffe71

Please sign in to comment.