-
Notifications
You must be signed in to change notification settings - Fork 620
API for repository description #7066
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,8 @@ import { APIState, PublishEvent } from '../@types/git'; | |
import { Disposable } from '../common/lifecycle'; | ||
import Logger from '../common/logger'; | ||
import { TernarySearchTree } from '../common/utils'; | ||
import { PullRequestOverviewPanel } from '../github/pullRequestOverview'; | ||
import { RepositoriesManager } from '../github/repositoriesManager'; | ||
import { API, IGit, PostCommitCommandsProvider, Repository, ReviewerCommentsProvider, TitleAndDescriptionProvider } from './api'; | ||
|
||
export const enum RefType { | ||
|
@@ -78,6 +80,11 @@ export class GitApiImpl extends Disposable implements API, IGit { | |
private static _handlePool: number = 0; | ||
private _providers = new Map<number, IGit>(); | ||
|
||
public constructor( | ||
private readonly repositoriesManager: RepositoriesManager) { | ||
super(); | ||
} | ||
|
||
public get repositories(): Repository[] { | ||
const ret: Repository[] = []; | ||
|
||
|
@@ -220,4 +227,41 @@ export class GitApiImpl extends Disposable implements API, IGit { | |
getReviewerCommentsProvider(): { title: string, provider: ReviewerCommentsProvider } | undefined { | ||
return this._reviewerCommentsProviders.size > 0 ? this._reviewerCommentsProviders.values().next().value : undefined; | ||
} | ||
|
||
async getRepositoryDescription() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of just returning info about the first repo, I would suggest passing in a URI and returning info about the repo that the URI belongs to. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case the API will be used in chat to be able to gather and include the context of the repository in which the user is currently at, since there is not a specific file to fetch the PR from. |
||
let repo: Repository | undefined; | ||
const allRepos = this.repositories; | ||
if (vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 0) { | ||
for (const folder of vscode.workspace.workspaceFolders) { | ||
repo = allRepos.find(r => r.rootUri.fsPath === folder.uri.fsPath); | ||
if (repo) { | ||
break; | ||
} | ||
} | ||
} | ||
if (!repo) { | ||
return; | ||
} | ||
const folderManagerForRepo = this.repositoriesManager.folderManagers.find((manager) => manager.gitHubRepositories.some(r => r.rootUri.fsPath === repo!.rootUri.fsPath)); | ||
const folderManagerForPR = this.repositoriesManager.folderManagers.find((manager) => manager.activePullRequest); | ||
|
||
if (folderManagerForRepo && folderManagerForRepo.gitHubRepositories.length > 0) { | ||
const repositoryMetadata = await folderManagerForRepo.gitHubRepositories[0].getMetadata(); | ||
const pullRequest = folderManagerForPR?.activePullRequest ?? PullRequestOverviewPanel.currentPanel?.getCurrentItem(); | ||
if (repositoryMetadata) { | ||
return { | ||
owner: repositoryMetadata.owner.login, | ||
repositoryName: repositoryMetadata.name, | ||
defaultBranch: repositoryMetadata.default_branch, | ||
currentBranch: repo.state.HEAD?.name, | ||
pullRequest: pullRequest ? { | ||
title: pullRequest.title, | ||
url: pullRequest.html_url, | ||
number: pullRequest.number, | ||
id: pullRequest.id | ||
} : undefined | ||
}; | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we include
number
here too? That's usually a useful thing to have.