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

Migrate repoPolicyCheck to OCLIF #11509

Merged
merged 67 commits into from Sep 1, 2022
Merged

Conversation

RishhiB
Copy link
Contributor

@RishhiB RishhiB commented Aug 11, 2022

@github-actions github-actions bot added the base: main PRs targeted against main branch label Aug 11, 2022
@RishhiB RishhiB marked this pull request as ready for review August 23, 2022 18:20
build-tools/packages/build-tools/tsconfig.json Outdated Show resolved Hide resolved
this.error("ERROR: No exclusions file provided.");
}

const exclusionsFile = await readJsonAsync(this.processedFlags.exclusions);
Copy link
Member

Choose a reason for hiding this comment

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

Does readjson return a string? You might need to parse it into an object first.

Copy link
Contributor Author

@RishhiB RishhiB Aug 31, 2022

Choose a reason for hiding this comment

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

readJsonAsync seems to return a JSON object, this may throw an error. I think I should wrap it in a try catch.
code for function;

export async function readJsonAsync(filename: string) {
    const content = await readFileAsync(filename, "utf-8");
    return JSON.parse(content);
}

…index.ts

Co-authored-by: Tyler Butler <tyler@tylerbutler.com>
Comment on lines 36 to 41
export { handler as assertShortCodeHandler } from "./repoPolicyCheck/handlers/assertShortCode";
export { handlers as copyrightFileHeaderHandlers } from "./repoPolicyCheck/handlers/copyrightFileHeader";
export { handler as dockerfilePackageHandler } from "./repoPolicyCheck/handlers/dockerfilePackages";
export { handler as fluidCaseHandler } from "./repoPolicyCheck/handlers/fluidCase";
export { handlers as lockfilesHandlers } from "./repoPolicyCheck/handlers/lockfiles";
export { handlers as npmPackageContentsHandlers } from "./repoPolicyCheck/handlers/npmPackages";
Copy link
Member

Choose a reason for hiding this comment

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

You shouldn't need these exports anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the catch!

* Licensed under the MIT License.
*/

import { assertShortCodeHandler, copyrightFileHeaderHandlers, dockerfilePackageHandler, fluidCaseHandler, Handler, lockfilesHandlers, npmPackageContentsHandlers } from "../..";
Copy link
Member

Choose a reason for hiding this comment

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

import these individually from the source files. e.g.

import {assertShortCodeHandler} from "./assertShortCode";

What you're doing here is creating a new module, and the API for the module is defined by what's exported from this file (index.ts). The individual handlers are "private" to the module, so you import them here and then export them in the shape that you want for your "external/public" API for the module. When you make this change and remove the exports from the root index.ts, you'll effectively "hide" all the individual handlers from the outside world. Even code within the project but outside the module won't be able to access them directly without a lint error. All access will be through the array exported here.

Copy link
Contributor Author

@RishhiB RishhiB Aug 31, 2022

Choose a reason for hiding this comment

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

Sorry, I was in the process of doing that, please let me know if this is correct; 03ce23a


type policyAction = "handle" | "resolve" | "final";

export class CheckPolicy extends BaseCommand<typeof CheckPolicy.flags> {
Copy link
Member

Choose a reason for hiding this comment

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

Can you add some TSDoc comments to the class and functions? Imagine you have to do this again in 6 months -- what do you wish you'd known?

Copy link
Member

@tylerbutler tylerbutler left a comment

Choose a reason for hiding this comment

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

Some nits and stuff, but looks good.

@RishhiB
Copy link
Contributor Author

RishhiB commented Sep 1, 2022

Thanks for all the help @tylerbutler and @sonalivdeshpande !!

@RishhiB RishhiB merged commit d6ad7f6 into microsoft:main Sep 1, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Sep 1, 2022

This commit is queued for merging with the next branch! Please ignore this PR for now. Contact @microsoft/fluid-cr-infra for help.

@RishhiB RishhiB deleted the migrateRepoPolicyCheck branch February 2, 2024 01:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
base: main PRs targeted against main branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants