Skip to content

Changes to OAuth service and update undefined state#585

Open
karlclement wants to merge 2 commits into
developmentfrom
echolayer-demo
Open

Changes to OAuth service and update undefined state#585
karlclement wants to merge 2 commits into
developmentfrom
echolayer-demo

Conversation

@karlclement
Copy link
Copy Markdown
Contributor

@karlclement karlclement commented Mar 12, 2024

This pull request introduces a series of code quality improvements across multiple services. In oauth.service.ts, variable names have been refactored for clarity, code formatting enhanced, and a TODO added to address future simplification of timeout rejection logic. The undefinedTextEditor.service.ts has been updated for better readability with new lines, a streamlined if-statement, and a more flexible method parameter type, while user.service.ts now includes a reminder to clean up comments.

File Changes

  • oauth.service.ts: Refactored variable names and improved code formatting. Added a TODO comment regarding simplification of a timeout rejection logic.
  • undefinedTextEditor.service.ts: Inserted new lines for readability, simplified an if-statement, and changed a parameter type to 'any' in a method signature.
  • user.service.ts: Added a TODO comment to remind of cleaning up comments in the future.

import { PromiseAdapter, promiseFromEvent } from "../helpers/eventEmitter.helper";
import { ErrorResponse, IOAuthService, OAuthPath, OAuthPlatform, UserInfo } from "../models/shared/IOAuthService";

import {ErrorResponse, IOAuthService, OAuthPath, OAuthPlatform, UserInfo} from "../models/shared/IOAuthService";
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Break this import into multiple lines, way too long

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@echolayer-stag can you break this import into multiple lines

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sorry, I couldn't find a solution for this task. I'll polish up on the docs for next time.

public async authenticate(oAuthPath: OAuthPath): Promise<UserInfo | ErrorResponse> {
const oAuthPlatform: OAuthPlatform = oAuthPath === OAuthPath.google ? OAuthPlatform.google : OAuthPlatform.github;
const eventEmitter = OAuthUrlHandler.getInstance().getEventEmitter();
const ee = OAuthUrlHandler.getInstance().getEventEmitter();
Copy link
Copy Markdown
Contributor Author

@karlclement karlclement Mar 12, 2024

Choose a reason for hiding this comment

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

Change for a much more descriptive variable name

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@echolayer-stag rename this to be a much more descriptive variable name

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

EchoLayer posted a change for your review: #586

// before completing it.
if (!OAuthService.codeExchangePromise) {
OAuthService.codeExchangePromise = promiseFromEvent(eventEmitter.event, this.postAuthorization());
OAuthService.codeExchangePromise = promiseFromEvent(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not sure why this is multiple lines

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@echolayer-stag can you collapse this all into one line

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

EchoLayer posted a change for your review: #588

OAuthService.codeExchangePromise.promise,
new Promise<ErrorResponse>((_, reject) =>
setTimeout(() => {
// TODO we should make this alot simpler
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We fixed this already, maybe add some comments

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@echolayer-stag remove this TODO and instead add comments to the return Promise.race on how it works

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

EchoLayer posted a change for your review: #589

this.clearCodeExchangePromise();
const parsedQuery = this.parseQuery(uri) as AuthorizeResponse | ErrorResponse;
if ((parsedQuery as AuthorizeResponse).code) {
const parsed_query = this.parseQuery(uri) as AuthorizeResponse | ErrorResponse;
Copy link
Copy Markdown
Contributor Author

@karlclement karlclement Mar 12, 2024

Choose a reason for hiding this comment

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

We don't use snake case in this file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@echolayer-stag change this to camelCasing please

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

EchoLayer posted a change for your review: #587


private parseQuery(uri: vscode.Uri) {
return uri.query.split("&").reduce((prev: any, current) => {
// important to split
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not a helpful comment to explain

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@echolayer-stag can you remove this unhelpful comment and instead actually comment what this code block is doing

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

EchoLayer posted a change for your review: #590

if (force) {
await this.getContexts(force);
}
if (force) await this.getContexts(force);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This shouldn't all be on one line

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@echolayer-stag split this into multiple lines so it's easier to read for my future self

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

EchoLayer posted a change for your review: #595

}

public async getDefaultCodexServiceForRepo(repositoryService: RepositoryService): Promise<CodexService> {
public async getDefaultCodexServiceForRepo(repositoryService: any): Promise<CodexService> {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Add some comments explaining what this is for

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@echolayer-stag add comments explaining what this is for

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

EchoLayer posted a change for your review: #591

return this.ccl.getContextsService();
}

// TODO clean up comments
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Would replace this with a valid comment, in fact this file doesn't have any comments explaining the functions

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@echolayer-stag remove this todo and add comments that explain all functions in this file

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

EchoLayer posted a change for your review: #593

Comment on lines +28 to +31
OAuthService.codeExchangePromise = promiseFromEvent(
ee.event,
this.postAuthorization()
);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@echolayer-stag can you collapse this all into one line

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

EchoLayer posted a change for your review: #594

@@ -16,21 +17,25 @@ export class OAuthService implements IOAuthService {
*/
public async authenticate(oAuthPath: OAuthPath): Promise<UserInfo | ErrorResponse> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@echolayer rename this function to oAuthenticate

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

EchoLayer posted a change for your review: #596

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

EchoLayer posted a change for your review: #597

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

EchoLayer posted a change for your review: #598

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.

3 participants