Skip to content

DO NOT MERGE#599

Open
karlclement wants to merge 2 commits into
derrick/cod-1379-if-there-is-no-remote-on-a-localfrom
derrick/cod-1375-typeerror-cannot-read-properties-of
Open

DO NOT MERGE#599
karlclement wants to merge 2 commits into
derrick/cod-1379-if-there-is-no-remote-on-a-localfrom
derrick/cod-1375-typeerror-cannot-read-properties-of

Conversation

@karlclement
Copy link
Copy Markdown
Contributor

@karlclement karlclement commented Mar 26, 2024

Pull Request Summary by EchoLayer

This pull request introduces a new SENTRY_LOG_LEVEL environment variable to fine-tune Sentry logging, and updates the error logging mechanism in logging.helper.ts to include JSON stringification of metadata, leveraging the new environment variable for setting the log level. Additionally, git.service.ts has been refactored to introduce a getRemote method for more reliable fetching of repository remotes, and the toVSCodeRepository function has been modified to accept a remote parameter, ensuring that the origin remote is always checked before falling back to the first available remote.

File Changes

  • .env.example: Added SENTRY_LOG_LEVEL environment variable with a default value of 'error'.
  • logging.helper.ts: Enhanced error logging with JSON stringification of metadata and set default Sentry log level from environment variable.
  • git.service.ts: Refactored to use a new getRemote method for fetching repository remotes and updated toVSCodeRepository to accept a remote parameter.

@karlclement karlclement added the do not merge Do not merge this branch label Mar 26, 2024
@ghost ghost mentioned this pull request Mar 29, 2024
@squire-dev-app squire-dev-app Bot deleted a comment from saumilptl Apr 3, 2024
@squire-dev-app squire-dev-app Bot deleted a comment Apr 3, 2024
@squire-dev-app squire-dev-app Bot deleted a comment from saumilptl Apr 3, 2024
@squire-dev-app squire-dev-app Bot deleted a comment from saumilptl Apr 3, 2024
@squire-dev-app squire-dev-app Bot deleted a comment Apr 3, 2024
@squire-dev-app squire-dev-app Bot deleted a comment from saumilptl Apr 3, 2024
@SquireAI SquireAI deleted a comment from squire-dev-app Bot Apr 23, 2024
@SquireAI SquireAI deleted a comment from squire-dev-app Bot Apr 23, 2024
@SquireAI SquireAI deleted a comment from squire-dev-app Bot Apr 23, 2024
@SquireAI SquireAI deleted a comment from squire-dev-app Bot Apr 23, 2024
@SquireAI SquireAI deleted a comment from squire-dev-app Bot Apr 23, 2024
@SquireAI SquireAI deleted a comment from squire-dev-app Bot Apr 23, 2024
@SquireAI SquireAI deleted a comment from squire-dev-app Bot Apr 23, 2024
@SquireAI SquireAI deleted a comment from squire-dev-app Bot Apr 23, 2024
Copy link
Copy Markdown

@echolayer-dev-karl echolayer-dev-karl Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Squire has completed its review of this PR!
We left 7 comments.
How did we do? 👍 👎

Comment on lines +17 to +19
} catch (error) {
// Couldn't parse object ¯\_(ツ)_/¯
}
Copy link
Copy Markdown

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 meta object. Consider using console.error or the winston logger itself to record the error.

normalizeDepth: 10,
},
level: "error",
level: process.env.SENTRY_LOG_LEVEL || "error",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure that the environment variable SENTRY_LOG_LEVEL is properly documented and validated to prevent invalid log levels from being used, which could cause runtime issues.

return originRepo;
}

logger.info(`Could not find repo origin - gitService.getFetchOrigin`, {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The log message in line 17 references a method getFetchOrigin that has been renamed to getRemote. Update the log message to reflect the correct method name to avoid confusion during debugging.

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];
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a null check for repository?.state?.remotes before accessing the first element in line 21 to prevent potential runtime errors if remotes is undefined.

Comment on lines 113 to +115

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);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The refactoring of toVSCodeRepository to take a Remote object directly simplifies the method and removes the need for a null check on fetchOrigin. Ensure that all calls to this method are updated to pass the Remote object as the second argument.

Comment on lines 71 to +74
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);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The refactoring from getFetchOrigin to getRemote and the corresponding parameter change in toVSCodeRepository method improves clarity and maintainability by using a more descriptive method name and passing the relevant Remote object directly.

Comment on lines +52 to +54
const remote = GitService.getRemote(repository);
if (remote?.fetchUrl) {
const vscodeRepository: VSCodeRepository = GitService.toVSCodeRepository(repository, remote);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The refactoring to use GitService.getRemote(repository) improves code readability by abstracting the logic for obtaining the remote. However, ensure that the toVSCodeRepository method is updated to accept the new remote parameter as it now requires two arguments.

@SquireAI SquireAI deleted a comment from echolayer-dev-karl Bot Apr 24, 2024
@SquireAI SquireAI deleted a comment from echolayer-dev-karl Bot Apr 24, 2024
@SquireAI SquireAI deleted a comment from echolayer-dev-karl Bot Apr 24, 2024
@SquireAI SquireAI deleted a comment from echolayer-dev-karl Bot Apr 24, 2024
@SquireAI SquireAI deleted a comment from echolayer-dev-karl Bot Apr 24, 2024
@karlclement
Copy link
Copy Markdown
Contributor Author

@echolayer-karl /ship

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not merge Do not merge this branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants