-
Notifications
You must be signed in to change notification settings - Fork 18
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(onlychanged): allow to lint only changed files in the pull request #4
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution! It looks cool additional feature 👍 but unfortunately, I need some changes before merging. Please check review details 🙇
@@ -0,0 +1 @@ | |||
node_modules |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, Good Catch 👍
@@ -12,6 +12,8 @@ inputs: | |||
default: 'tslint.json' | |||
pattern: | |||
description: 'Glob pattern to match' | |||
only-changed: | |||
description: 'Apply glob patter only to changed files' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice if we add restriction about this option - it only works with pull_event
trigger
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What you suggest?
@@ -41,7 +42,7 @@ const SeverityAnnotationLevelMap = new Map<RuleSeverity, "warning" | "failure">( | |||
owner: ctx.repo.owner, | |||
repo: ctx.repo.repo, | |||
name: CHECK_NAME, | |||
head_sha: ctx.sha, | |||
head_sha: ctx.payload.pull_request ? ctx.payload.pull_request.head.sha : ctx.sha, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you reference head.sha?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because if you use ctx.sha
- it won't appear in the PR: actions/toolkit#133 (comment)
@@ -71,7 +72,27 @@ const SeverityAnnotationLevelMap = new Map<RuleSeverity, "warning" | "failure">( | |||
} else { | |||
const linter = new Linter(options); | |||
|
|||
const files = glob.sync(pattern!); | |||
let files = glob.sync(pattern!); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice if this block can be cleaned.
e.g.
const files = await (async () => {
const matched = glob.sync(pattern!);
if (!onlyChanged) {
return matched;
}
const changedFiles = ctx.action === "pull_request" ?
(await octokit.pulls.listFiles(options)).data :
await getChangedFilesSomeHow();
return matched.filter((f) => changedFiles.includes(f));
})();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this better? We are already in async function.
const changedFiles = response.data.map((f) => f.filename); | ||
files = files.filter((f: string) => changedFiles.includes(f)); | ||
} else { | ||
const response = await octokit.repos.getCommit({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It won't get changed files correctly if user pushed multiple commits
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All you have is ctx.sha
so this should work OK.
@@ -122,6 +145,10 @@ const SeverityAnnotationLevelMap = new Map<RuleSeverity, "warning" | "failure">( | |||
annotations, | |||
}, | |||
}); | |||
|
|||
if (result.errorCount) { | |||
core.setFailed(`${result.errorCount} error(s), ${result.warningCount} warning(s) found`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good Catch tho 👍
@@ -19,6 +19,7 @@ const SeverityAnnotationLevelMap = new Map([ | |||
const projectFileName = core.getInput("project"); | |||
const pattern = core.getInput("pattern"); | |||
const ghToken = core.getInput("token"); | |||
const onlyChanged = core.getInput("only-changed") || false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file will be automatically updated. You don't have to change this file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know - but without compiled file - I cannot test this branch in my project
Any updates on this? |
Hello @aaomidi, As you can see, I left a review of this PR and I will merge this if author updates PR with requested changes. |
Alright, I might make a PR that fixes this - would that be okay? |
Sounds great! It would be nice if you make a new PR 👍 |
@aaomidi Did you make any progress on the new PR? I'm excited to see this feature land. |
Right now I've made my own repo building up on this. I eventually plan to PR back here, just haven't had the time :/ @mooyoul would you mind if the PR changed this from JS to TS too? |
Hello there, I’m looking into this. Stay tuned! |
Hi, I wanted to lint only files which has been changed in the Pull Request, so I added
only-changed
option.