Automated Prettier formatting on pull requests #428
-
Hi all, I had promised to open a discussion about this topic, but I have only gotten around to it today, so my apologies for the delay. After significant efforts to get all of our content Prettified (thanks to all who helped), we had some trouble with pull request checks, diagnosing and solving issues, particularly those opened by contributors via the GitHub UI. It's clear we need some additional tooling that will help us with those cases. In the meantime, we merged a pull request to disable Prettier checks in pull requests: This is temporary while we get something in place to enforce the formatting requirements on incoming content without causing too much work for reviewers and authors. In the current state it's easier to automatically fix issues in content rather than troubleshoot broken CI. This is already handled in: https://github.com/mdn/content/blob/3e2369d97e2d6fbfe33a3c496a8edd90e0b539e2/package.json#L17 We have a great suggestion from @queengooborg to try out a GitHub action. This looks promising, but we will have to try it out. Another option is a GitHub bot that reacts to |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 12 replies
-
Another way is provide code suggestions, I just found a project named reviewdog. It has provided a tool that just used for Github Action. An example here: - name: Format changed content
if: ${{ env.GIT_DIFF_CONTENT }}
run: |
yarn prettier --write ${{ env.GIT_DIFF_CONTENT }}
- name: Submit suggestion
uses: reviewdog/action-suggester@v1
with:
tool_name: prettier But this tool only handle |
Beta Was this translation helpful? Give feedback.
-
Part of my problem previously was that the precommit hook is buggy - at least on Windows. It was running but not fixing errors. FYI the output below.
|
Beta Was this translation helpful? Give feedback.
-
I think we should do this, and fix the precommit hook.
This fixes the main problem we had previously, which was leaving github only users in a state where they had a problem that they could not fix. It does it in a way that doesn't add any extra workflow for reviewers. What's the down side? |
Beta Was this translation helpful? Give feedback.
-
The command |
Beta Was this translation helpful? Give feedback.
-
We have now introduced a review bot that will suggest changes to help the contributor match Prettier's formatting desires. This should eliminate issues with Prettier formatting for changes made by contributors using the GitHub Web UI. If you have feedback on the bot, please feel free to reply to this thread, we'd love to hear what you think! |
Beta Was this translation helpful? Give feedback.
-
Hey all, @bsmth pointed me in the direction of this discussion after asking about the feasibility of hosting some kind of auto-linter bot outside of GitHub, and being me I couldn't just answer simply, I had to probe a bit into the motivations :) Whatever the solution is here unfortunately isn't simple, as GitHub's security model really locks down permissions in PRs coming from forks, for good reason: untrusted code run with the same permissions as code in a repo could do bad things, and if we work around it in any way, we need to ensure that whatever we're doing doesn't compromise that security model. Indeed, reviewdog doesn't appear to work in the way we'd like in those cases: https://github.com/reviewdog/reviewdog#graceful-degradation-for-pull-requests-from-forked-repositories But, ultimately, what's the motivation here? To fix linting errors for users who submit PRs exclusively from the GitHub UI? What proportion of content PRs come in like that? And since they all need to be reviewed anyway, why can't the reviewer just quickly run |
Beta Was this translation helpful? Give feedback.
We have now introduced a review bot that will suggest changes to help the contributor match Prettier's formatting desires. This should eliminate issues with Prettier formatting for changes made by contributors using the GitHub Web UI. If you have feedback on the bot, please feel free to reply to this thread, we'd love to hear what you think!