-
Notifications
You must be signed in to change notification settings - Fork 0
DO NOT MERGE #599
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: derrick/cod-1379-if-there-is-no-remote-on-a-local
Are you sure you want to change the base?
DO NOT MERGE #599
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 |
|---|---|---|
|
|
@@ -11,6 +11,12 @@ const consoleFormat = winston.format.printf(({ level, message, timestamp, ...met | |
| if (meta) { | ||
| if (meta.error as Error) { | ||
| message += `\n${level}: ${meta.error?.message}\n${meta.error?.stack}`; | ||
| } else { | ||
| try { | ||
| message += `\n${JSON.stringify(meta, undefined, 2)}`; | ||
| } catch (error) { | ||
| // Couldn't parse object ¯\_(ツ)_/¯ | ||
| } | ||
| } | ||
| } | ||
| return message; | ||
|
|
@@ -40,7 +46,7 @@ const options = { | |
| environment: process.env.ENVIRONMENT || "development", | ||
| normalizeDepth: 10, | ||
| }, | ||
| level: "error", | ||
| level: process.env.SENTRY_LOG_LEVEL || "error", | ||
|
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. Ensure that the environment variable |
||
| format: sentryFormat(), | ||
| }; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,8 +49,9 @@ export class GitService implements Singleton { | |
| const repositories: Array<VSCodeRepository> = ( | ||
| await Promise.all( | ||
| this.gitAPI.repositories.map(async (repository) => { | ||
| if (repository?.state?.remotes?.[0]?.fetchUrl) { | ||
| const vscodeRepository: VSCodeRepository = GitService.toVSCodeRepository(repository); | ||
| const remote = GitService.getRemote(repository); | ||
| if (remote?.fetchUrl) { | ||
| const vscodeRepository: VSCodeRepository = GitService.toVSCodeRepository(repository, remote); | ||
|
Comment on lines
+52
to
+54
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. The refactoring to use |
||
| await this.localRepositoryMapManager.set(vscodeRepository.origin, vscodeRepository.directory); | ||
| return vscodeRepository; | ||
| } | ||
|
|
@@ -68,9 +69,9 @@ export class GitService implements Singleton { | |
|
|
||
| async getRepositoryAt(uri: vscode.Uri): Promise<VSCodeRepository | undefined> { | ||
| const repository = this.gitAPI.getRepository(uri); | ||
| const fetchOrigin = GitService.getFetchOrigin(repository); | ||
| if (fetchOrigin) { | ||
| const vscodeRepository: VSCodeRepository = GitService.toVSCodeRepository(repository); | ||
| const remote = GitService.getRemote(repository); | ||
| if (remote) { | ||
| const vscodeRepository: VSCodeRepository = GitService.toVSCodeRepository(repository, remote); | ||
|
Comment on lines
71
to
+74
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. The refactoring from |
||
| return vscodeRepository; | ||
| } else { | ||
| try { | ||
|
|
@@ -110,11 +111,8 @@ export class GitService implements Singleton { | |
| } | ||
| } | ||
|
|
||
| static toVSCodeRepository(repository: Repository): VSCodeRepository | undefined { | ||
| const fetchOrigin = GitService.getFetchOrigin(repository); | ||
| if (!fetchOrigin) return; | ||
|
|
||
| const parsedRemoteGitUrl = gitUrlParse(fetchOrigin.fetchUrl); | ||
| static toVSCodeRepository(repository: Repository, remote: Remote): VSCodeRepository | undefined { | ||
| const parsedRemoteGitUrl = gitUrlParse(remote.fetchUrl); | ||
|
Comment on lines
113
to
+115
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. The refactoring of |
||
| if (parsedRemoteGitUrl) { | ||
| return { | ||
| name: parsedRemoteGitUrl.name, | ||
|
|
@@ -124,7 +122,24 @@ export class GitService implements Singleton { | |
| } | ||
| } | ||
|
|
||
| private static getFetchOrigin(repository: Repository): Remote | undefined { | ||
| return repository?.state?.remotes?.find((remote) => remote.name === "origin" && remote.fetchUrl); | ||
| /** | ||
| * Retrieves a remote repository; ideally returns the Origin, but if not, returns a fallback | ||
| * @param repository | ||
| * @returns Remote | undefined | ||
| */ | ||
| private static getRemote(repository: Repository): Remote | undefined { | ||
| let originRepo = repository?.state?.remotes?.find((remote) => remote.name === "origin" && remote.fetchUrl); | ||
| if (originRepo) { | ||
| return originRepo; | ||
| } | ||
|
|
||
| logger.info(`Could not find repo origin - gitService.getFetchOrigin`, { | ||
|
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. The log message in line 17 references a method |
||
| repositoryRemotes: repository?.state?.remotes, | ||
| }); | ||
| // We couldn't find a repo w/ Origin as it's name, so we'll naively take the first one | ||
| originRepo = repository?.state?.remotes && repository?.state?.remotes[0]; | ||
|
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. Consider adding a null check for |
||
| if (originRepo?.fetchUrl) { | ||
| return originRepo; | ||
| } | ||
| } | ||
| } | ||
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.
The catch block on lines 7-9 should log the error to avoid silent failures during JSON stringification of the
metaobject. Consider usingconsole.erroror the winston logger itself to record the error.