Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions .github/workflows/javascript.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v6
- name: Use Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v6
with:
node-version-file: ".nvmrc"
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Run tests
Expand All @@ -22,9 +24,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v6
- name: Use Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v6
with:
node-version-file: ".nvmrc"
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Run tests
Expand Down
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
22.22.0
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## 4.0.0 - 2026-03-16

### Changed

- Extension now calls `git` instead of manually reading `.git/` files. (#75)

## 3.4.0 - 2026-03-07

### Changed
Expand Down
Binary file modified images/logo.sketch
Binary file not shown.
17 changes: 8 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "githubinator",
"displayName": "Githubinator",
"description": "Quickly open files on Github and other providers. View blame information, copy permalinks and more. See the \"commands\" section of the README for more details.",
"version": "3.4.0",
"version": "4.0.0",
"publisher": "chdsbd",
"license": "SEE LICENSE IN LICENSE",
"icon": "images/logo256.png",
Expand Down Expand Up @@ -455,14 +455,14 @@
"@types/lodash": "^4.14.170",
"@types/mocha": "^10.0.6",
"@types/mz": "^2.7.3",
"@types/node": "^15.12.4",
"@types/vscode": "^1.32.0",
"@types/node": "^22.19.15",
"@types/vscode": "^1.110.0",
"@vscode/test-cli": "^0.0.9",
"@vscode/test-electron": "^2.4.0",
"esbuild": "^0.11.12",
"mocha": "^10.4.0",
"prettier": "^3.3.0",
"typescript": "^4.2.2",
"typescript": "^5.9.3",
"vscode-test": "^1.6.1"
},
"dependencies": {
Expand All @@ -472,9 +472,8 @@
"lodash": "^4.17.21",
"mz": "^2.7.0"
},
"packageManager": "yarn@1.22.22",
"volta": {
"node": "18.20.3",
"yarn": "1.22.22"
}
"extensionDependencies": [
"vscode.git"
],
"packageManager": "yarn@1.22.22"
}
79 changes: 45 additions & 34 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,28 +77,35 @@ export interface IGithubinatorConfig {
}
}

export let outputChannel: vscode.LogOutputChannel

export function activate(context: vscode.ExtensionContext) {
console.log("githubinator.active.start")
outputChannel = vscode.window.createOutputChannel("GitHubinator", {
log: true,
})
outputChannel.debug("githubinator.active.start")
context.subscriptions.push(outputChannel)
COMMANDS.forEach(([cmd, args]) => {
const disposable = vscode.commands.registerCommand(cmd, () =>
githubinator(args),
)
context.subscriptions.push(disposable)
})
vscode.commands.registerCommand(
const openFromUrlDisposable = vscode.commands.registerCommand(
"githubinator.githubinatorOpenFromUrl",
openFileFromGitHubUrl,
)
context.subscriptions.push(openFromUrlDisposable)

console.log("githubinator.active.complete")
outputChannel.debug("githubinator.active.complete")
}

export function deactivate() {
console.log("githubinator.deactivate")
outputChannel.debug("githubinator.deactivate")
}

function err(message: string) {
console.error(message)
outputChannel.error(message)
vscode.window.showErrorMessage(message)
}

Expand Down Expand Up @@ -127,11 +134,15 @@ function mainBranches() {
.get<string[]>("mainBranches", ["main"])
}

/**
* Search default main branch names for the first one that exists.
*/
async function findShaForBranches(
gitDir: string,
gitRepository: git.Repo,
fileUri: vscode.Uri,
): Promise<[string, string] | null> {
for (let branch of mainBranches()) {
const sha = await git.getSHAForBranch(gitDir, branch)
const sha = await git.getSHAForBranch(gitRepository, branch)
if (sha == null) {
continue
}
Expand All @@ -151,41 +162,41 @@ interface IGithubinator {
openPR?: boolean
compare?: boolean
}
async function githubinator({
openUrl,
copyToClipboard,
blame,
mainBranch,
openRepo,
permalink,
history,
openPR,
compare,
}: IGithubinator) {
console.log("githubinator.call")
async function githubinator(options: IGithubinator) {
const {
openUrl,
copyToClipboard,
blame,
mainBranch,
openRepo,
permalink,
history,
openPR,
compare,
} = options
outputChannel.info(
"githubinator called with options: " + JSON.stringify(options),
)
const editorConfig = getEditorInfo()
if (!editorConfig.uri) {
return err("could not find file")
return err("Could not find file for current editor.")
}
const fileUri = editorConfig.uri

const gitDirectories = git.dir(editorConfig.uri.fsPath)

if (gitDirectories == null) {
return err("Could not find .git directory.")
const gitRepository = await git.getRepo(fileUri)
if (!gitRepository) {
return err("Could not find git repository for file.")
}

const gitDir = gitDirectories.git
const repoDir = gitDirectories.repository

let headBranch: [string, string | null] | null = null
if (mainBranch) {
const res = await findShaForBranches(gitDir)
const res = await findShaForBranches(gitRepository, fileUri)
if (res == null) {
return err(`Could not find SHA for branch in ${mainBranches()}`)
}
headBranch = res
} else {
headBranch = await git.head(gitDir)
headBranch = await git.head(gitRepository)
}
if (headBranch == null) {
return err("Could not find HEAD.")
Expand All @@ -209,7 +220,7 @@ async function githubinator({
const parsedUrl = await new provider(
providersConfig,
globalDefaultRemote,
(remote) => git.origin(gitDir, remote),
(remote) => git.origin(gitRepository, remote),
).getUrls({
selection,
// priority: permalink > branch > branch from HEAD
Expand All @@ -220,19 +231,19 @@ async function githubinator({
? createSha(head)
: createBranch(branchName),
relativeFilePath: editorConfig.fileName
? getRelativeFilePath(repoDir, editorConfig.fileName)
? getRelativeFilePath(gitRepository.rootUri, editorConfig.fileName)
: null,
})
if (parsedUrl != null) {
console.log("Found provider", provider.name)
outputChannel.debug("Found provider", provider.name)
urls = parsedUrl
break
}
console.log("Skipping provider", provider.name)
outputChannel.debug("Skipping provider", provider.name)
}

if (urls == null) {
return err("Could not find provider for repo.")
return err("Could not find remote for repository.")
}

let url = compare
Expand Down
Loading