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

feat: custom rulesets #129

Merged
merged 14 commits into from
Apr 28, 2020
Merged

feat: custom rulesets #129

merged 14 commits into from
Apr 28, 2020

Conversation

philsturgeon
Copy link
Contributor

Work with custom rulesets in Spectral v5.0.

@rubenfiszel
Copy link

@philsturgeon

We love spectral and the action. It is a bit noisy on our side and we would like to disable some checks. It seems that we could only do that through custom rulesets so we're very eager to see progress on this PR. Is it blocked by something hard? I could help if needed.

@philsturgeon
Copy link
Contributor Author

@rubenfiszel hey, I would love to have this feature too. It's been "coming soon" for a while, but it's the very next task that my team works on. This PR will be picked up by a team mate and should be done... well soon. This whole pandemic is messing with everyones predictions of time so no promises, but it is next.

@rubenfiszel
Copy link

Got it, thanks for the update and the awesome action!

@nulltoken
Copy link
Contributor

@philsturgeon Started to work on this

@nulltoken
Copy link
Contributor

nulltoken commented Apr 25, 2020

@philsturgeon I've got something that starts to work...

image

cf. https://github.com/stoplightio/spectral-action/pull/129/checks

The workflow that runs on every push/pull request now use a custom ruleset with exceptions (which are honored).

@XVincentX @P0lip Would you please take a peek at this proposal?

README.md Show resolved Hide resolved
@nulltoken
Copy link
Contributor

@XVincentX @P0lip The docker build spits an insane amount of warnings:

image

And I'm not sure how to fix them... :-/

Help? 🙏

@nulltoken
Copy link
Contributor

@philsturgeon @XVincentX So I've created a dedicated repo (https://github.com/stoplightio/spectral-action-example/) to test the process out from a consumer standpoint.

https://github.com/stoplightio/spectral-action-example/pull/1/checks?check_run_id=618592904

Looks like I still need to iron out some things...

@nulltoken nulltoken force-pushed the custom-rulesets branch 8 times, most recently from 0655244 to 1faed38 Compare April 26, 2020 20:00
@nulltoken
Copy link
Contributor

@philsturgeon @XVincentX @P0lip I think I'm done.

  • custom rulesets now work
  • annotations are now hooked to the proper commit, whether in push or in pull request context
  • build has been improved (a bit) to avoid some warnings during the docker build phase
  • some logging has been added to help future potential troubleshooting
  • configuration from the user standpoint is slightly easier (explicitly passing the GITHUB_TOKEN is no longer needed)
  • Lint check runs are now suffixed with the event name to avoid having one of them disappear because of name collision:

Some pre-existing issues are still there:

@nulltoken nulltoken marked this pull request as ready for review April 26, 2020 20:13
@nulltoken nulltoken requested review from XVincentX and P0lip April 26, 2020 20:14
@nulltoken
Copy link
Contributor

@philsturgeon https://github.com/stoplightio/spectral-action-example/pull/1/files is now properly decorated.

However, you'll notice that Annotations seem to be hooked to the last line of the offending code block... The annotation is correctly created (from the GH api standpoint), but the resulting UI is causing me violent mixed feelings.

Thoughts?

@nulltoken nulltoken force-pushed the custom-rulesets branch 3 times, most recently from 20721b3 to 8b2b579 Compare April 27, 2020 08:47
@nulltoken
Copy link
Contributor

@rubenfiszel If you'd like to get an early peek and participate in the review from a user standpoint, that would be amazing and your feedback would be very welcome!

https://github.com/stoplightio/spectral-action-example/pull/1/files shows how to reference the action from this very branch.

Would you be willing to give it a try, beware that this branch is going to be short lived. So, don't merge any reference to it. It'd be safer to keep the changes in a opened PR on your side until it's reviewed, fixed, merged and officially released.

@XVincentX
Copy link
Contributor

I'll try to check out this later today!

@rubenfiszel
Copy link

@nulltoken Tried on our repo. It works as expected. Thank you very much!

@@ -0,0 +1,5 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=827846
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need this file in the repository?

Copy link
Contributor

Choose a reason for hiding this comment

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

@XVincentX This will pop up a dialog driving the user to install the editorconfig extension to try and keep the style clean by automatically applying fixups on save (trimming trailing whitespaces, ...). Of course, that will only work with vscode.

cf. https://code.visualstudio.com/docs/editor/extension-gallery#_workspace-recommended-extensions

If you don't think that adds any value, I'll drop it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I am aware of the feature. I have always been against IDE specific files in the repository, but I do not mind if you want to keep it here.

I would personally remove it.

Dockerfile Show resolved Hide resolved
Comment on lines +36 to +37
info(`Done linting '${v.path}'`);

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it really worth to add logging here? It's a side effect and it should be encapsulated in an IO .

It would better to use a Writer or simply hold off on logging here

src/index.ts Show resolved Hide resolved
src/spectral.ts Outdated
@@ -11,11 +13,28 @@ import {
isOpenApiv3,
} from '@stoplight/spectral';

import * as SpectralPackage from '../node_modules/@stoplight/spectral/package.json';
Copy link
Contributor

Choose a reason for hiding this comment

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

This cannot be statically imported, because this might not exist. You need to replace this with an IOEither with a require call

Copy link
Contributor

@nulltoken nulltoken Apr 28, 2020

Choose a reason for hiding this comment

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

@XVincentX I've tried to apply your hints (Not that they were unclear, but rather because I'm not really used to fp-ts. Hence "tried").

Could you please check that I've correctly understood the requirements?

src/spectral.ts Outdated Show resolved Hide resolved
src/spectral.ts Outdated Show resolved Hide resolved
src/spectral.ts Outdated
Comment on lines 50 to 56
if (rulesetPath.length !== 0) {
info(`Loading ruleset '${rulesetPath}'...`);
normRuleSet = [rulesetPath];
} else {
info(`Loading built-in rulesets...`);
normRuleSet = undefined;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Replace this with an expression so that normRuleSet is constant

Copy link
Contributor

Choose a reason for hiding this comment

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

@XVincentX Fixed. Do you like it better?

src/spectral.ts Outdated Show resolved Hide resolved
@nulltoken
Copy link
Contributor

@XVincentX I believe I've fixed all your comments. Could you please take another peek?

@nulltoken nulltoken requested a review from XVincentX April 28, 2020 09:54
src/spectral.ts Outdated Show resolved Hide resolved
@XVincentX
Copy link
Contributor

@nulltoken

image

Please do not do this, it makes reviewing the follow up commits almost impossible and it's forcing the to re-review the whole PR.

Copy link
Contributor Author

@philsturgeon philsturgeon left a comment

Choose a reason for hiding this comment

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

I can't approve this, but it would be good to get @XVincentX to take one last look anyway. I'll leave it with you two!

@philsturgeon
Copy link
Contributor Author

@nulltoken btw can you push a v2 tag when this is done? We don't have semantic release set up or anything like that.

Comment on lines +50 to +54
const retrieveSpectralPackageVersion = (): IOEither.IOEither<Error, string> =>
IOEither.tryCatch<Error, string>(() => {
const x = require('../node_modules/@stoplight/spectral/package.json');
return String(x.version);
}, E.toError);
Copy link
Contributor

Choose a reason for hiding this comment

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

You do not need to make a function of this

Suggested change
const retrieveSpectralPackageVersion = (): IOEither.IOEither<Error, string> =>
IOEither.tryCatch<Error, string>(() => {
const x = require('../node_modules/@stoplight/spectral/package.json');
return String(x.version);
}, E.toError);
const retrieveSpectralPackageVersion =
IOEither.tryCatch<Error, string>(() => {
const x = require('../node_modules/@stoplight/spectral/package.json');
return String(x.version);
}, E.toError);

Copy link
Contributor

Choose a reason for hiding this comment

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

@XVincentX Duh. I now realize I didn't take this into account. Sorry :-(

Copy link
Contributor

@XVincentX XVincentX left a comment

Choose a reason for hiding this comment

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

I will probably jump on this integration and clean up some stuff, but for now this is good to go.

@nulltoken nulltoken merged commit 5c59284 into master Apr 28, 2020
@nulltoken
Copy link
Contributor

@XVincentX It's in. Thanks a lot for your patience and your feedback! I definitely need to feel more at easy with fp-ts.

@nulltoken
Copy link
Contributor

I will probably jump on this integration and clean up some stuff, but for now this is good to go.

@XVincentX Thanks. I'll read your changes to learn from them.

Once you're done, could you please take care of the tagging (as requested by @philsturgeon above)?

@nulltoken
Copy link
Contributor

@nulltoken

image

Please do not do this, it makes reviewing the follow up commits almost impossible and it's forcing the to re-review the whole PR.

re PR-rewrite. Sorry, bad habit. Will keep the fixups! commits from now on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants