Skip to content
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

Clean up setup internals #3435

Merged
merged 13 commits into from
Mar 12, 2023
Merged

Clean up setup internals #3435

merged 13 commits into from
Mar 12, 2023

Conversation

mattseddon
Copy link
Member

@mattseddon mattseddon commented Mar 9, 2023

Related to #3434

This PR starts to clean-up the internals of Setup. Comments are inline but the main change is removing instances of DvcReader, DvcExecutor, GitReader & GitExecutor from Setup. All of the required commands should be available through InternalCommands which makes things in the class a bit cleaner.

I also moved command registration out of the class (usual pattern) as then we don't have to worry about commands being "re-registered"/throwing errors when we build Setup for testing purposes.

@mattseddon mattseddon force-pushed the refactor-setup branch 2 times, most recently from 7e38c3e to 6440b70 Compare March 9, 2023 08:55
@@ -131,6 +133,8 @@ export class Extension extends Disposable {
new InternalCommands(outputChannel, ...clis)
)

const status = this.dispose.track(new Status(config, ...clis))
Copy link
Member Author

Choose a reason for hiding this comment

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

[F] There was a bug in the way that we were creating Status it did not contain the dvcViewer.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll add a type in a quick follow-up

export const buildSetup = (
disposer: Disposer,
dependencies?: {
Copy link
Member Author

Choose a reason for hiding this comment

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

[F] This was not used anywhere

dvcReader: DvcReader,
dvcRunner: DvcRunner,
gitExecutor: GitExecutor,
gitReader: GitReader,
Copy link
Member Author

Choose a reason for hiding this comment

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

[F] All of these IClis sit behind the InternalCommands facade. No point to include the functionality twice.

}
}

public async setupWorkspace() {
Copy link
Member Author

@mattseddon mattseddon Mar 9, 2023

Choose a reason for hiding this comment

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

[F] move from private to public only, also done so it can be registered

@@ -257,10 +241,50 @@ export class Setup
})
}

public async selectFocusedProjects() {
Copy link
Member Author

Choose a reason for hiding this comment

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

[F] exposed so it can be registered as a command

@@ -310,13 +337,6 @@ export class Setup
}
}

private async initializeDvc() {
Copy link
Member Author

Choose a reason for hiding this comment

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

[F] Registered externally and used in that way so we get a "free" telemetry event

@@ -36,7 +36,7 @@ export const initializeEmptyRepo = async (): Promise<string> => {
return ''
}

await gitExecutor.init(TEMP_DIR)
await gitExecutor.gitInit(TEMP_DIR)
Copy link
Member Author

Choose a reason for hiding this comment

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

[F] (unfortunate but) you can't register the same command name twice in InternalCommands

mockDvcRoot: string | undefined,
mockGitRoot: string | undefined,
noGitCommits = true
) => {
Copy link
Member Author

Choose a reason for hiding this comment

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

[F] Now that we are using InternalCommands we have to build the dependencies in the normal way.

return await this.internalCommands.executeCommand(
AvailableCommands.VERSION,
cwd
)
Copy link
Member Author

Choose a reason for hiding this comment

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

[F] Move the logic out of the "dumb" reader and into here. Wrote some tests to cover it.

@mattseddon mattseddon marked this pull request as ready for review March 10, 2023 00:55
@mattseddon mattseddon requested a review from sroy3 as a code owner March 10, 2023 00:55
@mattseddon mattseddon requested a review from julieg18 as a code owner March 10, 2023 00:55
Copy link
Contributor

@julieg18 julieg18 left a comment

Choose a reason for hiding this comment

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

Great work!

Copy link
Contributor

@sroy3 sroy3 left a comment

Choose a reason for hiding this comment

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

Works great and good cleanup job!

@mattseddon mattseddon enabled auto-merge (squash) March 12, 2023 08:16
@codeclimate
Copy link

codeclimate bot commented Mar 12, 2023

Code Climate has analyzed commit 5198cae and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 89.4% (85% is the threshold).

This pull request will bring the total coverage in the repository to 95.7% (0.0% change).

View more on Code Climate.

@mattseddon mattseddon merged commit f755edc into main Mar 12, 2023
@mattseddon mattseddon deleted the refactor-setup branch March 12, 2023 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants