So I was thinking about the problem of how to ensure that all PRs are rustfmt’d for some of my repos. It occurred to me that the simplest thing would be to have some kind of GitHub hook that automatically runs rustfmt. Ideally, this would be something that one can very, very easily integrate into your repo in one of two modes:
Run rustfmt on every PR automatically when it is opened
if any changes occur, push a commit to the user’s branch, and leave a comment
Run rustfmt on PRs when requested (e.g., @rustfmtbot format)
if any changes occur, push a commit to the user’s branch, and leave a comment
This all (hopefully) works because GH now allows you to push to other people’s branches, if you own the repo on which they have opened a PR. I would love to write this but I don’t know much about how GH works and I don’t really have the time. Anybody interested? Any reasons this can’t work?
You could, but that's annoying -- it forces the person opening the PR to fix it (or me), and so forth. Then I have to wait for them to respond etc. I'd prefer to just make it automatic.
Indeed, but I want this to be usable on any project, not just those that use bors. But I guess if we made bors mega easy to install that might be ok too. (In my ideal world, doing cargo new would give you whatever files you need to have everything be setup already (along with a suitable travis configuration).)
This sounds like it would be a fun project - there is no reason why it shouldn’t work - both the GH APIs and Rustfmt have everything you’d need (although the feature for formatting a selection of text in Rustfmt is a bit flakey, so this would probably find a bunch of bugs).
I’m not sure how easy it is to get a set of ranges of modified lines from a PR. At worst you could process the diff which wouldn’t be too bad, I assume there are libs to help with that. (Because Rustfmt can’t format a diff, you’d need to format the selections in the PR’s branch).
For a first implementation it seems like it could just run rustfmt over the whole codebase, if you're using this bot then it's likely that you're keeping the entire codebase formatted correctly, so the only parts that might need reformatting are the files modified in the PR.
RIght now, rustfmtbot could probably be implemented as a regular Github user that just happens to write a lot of reviews with applicable suggestions (and that gives up when there are too many issues)!
That way, we can ask contributors to format whenever it makes sense. Note that the status report shown here does not make a merge with bors fail, so it's just indicative.