Readit News logoReadit News
Posted by u/phendrenad2 4 years ago
Ask HN: Do you rewrite pull requests?
Just wondering how other open-source developers deal with valid by badly-written pull requests.

I usually work closely with the PR author, giving them multiple rounds of suggestions until it's up to our project's coding standards. Sometimes the PR author "drops out" of the process in frustration, as they were just trying to give us a quick fix, and didn't necessarily want to do a lot of work. In those cases, I usually thank them, and rewrite the PR (or heavily modify it). But I'm hesitant to do this in all cases, because often the PR author is excited to see their name as part of the contributors list, and/or to see their own code used in the project.

How so you deal with this kind of thing?

pengaru · 4 years ago
If the PR is technically correct, just violates coding style or smells a bit like of hacky trash, I merge it anyways. As long as it's not breaking the build, functionality, or bisectability, just go with it. You can always chase it with a cleanup commit of your own.

It's up to the PR's author to decide if they care enough to do better next time. By accepting their work and landing the change you've demonstrated an appreciation for their effort with open arms, and I feel this makes it more likely they will contribute in the future and care about doing better.

Maybe make a comment to that effect before merging as-is, creating the opportunity to clean it up themselves first.

If it's coming from a regular contributor I'm far less charitable, this approach I mostly reserve for first-time/infrequent contributors.

tda · 4 years ago
Pieter Hintjens (author of ZeroMQ) wrote and spoke a lot about merging liberally. Great advice IMHO.

> merge pull requests liberally and get new contributors’ “vision of progress on record” so that they immediately become members of the community. Worry about fixing the progress later.

See also https://jeremyfelt.com/2016/03/12/pieter-hintjens-building-o...

otterley · 4 years ago
I've found "importance scoring" to be a useful trick in improving my relationships with teammates and open-source contributors, while preserving my sanity. When I give feedback, I add a score from 1-10 to my comments, where 1 is "trivial nit, take it or leave it," and 10 is "there is no way I will merge this because it's fundamentally broken or would otherwise be a huge mistake." It helps me balance my perfectionist nature against the need for forward progress, and contributors appreciate this guidance because it helps prioritize where further efforts are needed.
bryanrasmussen · 4 years ago
I just go with an important or not important for something I understand, I mean 6/10 I guess is important enough you don't want to merge it unless someone fixes it? And for something I don't understand I of course ask for clarification (by not understand I mean can you clarify why you did this bit?)
LorenzA · 4 years ago
I find this an interesting concept. How do you do this in practice add a number to every comment and explain your system somewhere?
WmyEE0UsWAwC2i · 4 years ago
This seems like the more ethical approach with regards to giving credit to the original author.

I've seen projects (on GitHub, won't call them out) get bad reputation when the maintainer implements code previously submitted as a PR.

svnpenn · 4 years ago
> won't call them out

I will. vim/vim has been doing this for years, with Bram basically ignoring the whole point of GitHub, and putting his name on every commit. I love Vim, but that's not acceptable.

klyrs · 4 years ago
I think it's worth investing some time into people, to teach them about testing and documentation standards. If they can't / won't play along, my first approach is to do a PR into their branch. If that stalls out, I'll make a duplicate* PR from my fork of theirs, maintaining their credit and keeping my source tree up to standards.

Edit: * that almost never happens, it appears that github now supports changing the base of a PR

edem · 4 years ago
I just wrote a comment where I outline almost the same tactics. I think this is the most sensible strategy.
adhesive_wombat · 4 years ago
It's not even about "badly written". Sometimes it's just really hard to get a patch into the shape the maintainer wants (tests, architecture, general feel, how it slots into a longer term vision that may not be clearly defined, but the maintainer knows it when they see it) and takes a lot of back and forth. I don't begrudge that, after all, it's their project.

But it would be nice if there's a way to say "look, it is what it is, and while I'm willing to make an effort, I'm not living and breathing this codebase, and I'm not planning to become a major contributor going forward, much as I like the project. Playing 20 questions is exhausting on both ends and if you'd rather just take it and completely recast it how you want, I honestly don't mind and won't take offense" without sounding like "here's some random code, IDK if it works really, good luck, lol".

I don't even care about the authorship, I'd rather have the fix than get credit for a moribund PR. Half the time I contribute pseudonymously anyway.

Aeolun · 4 years ago
Yeah, this is how I feel. When I make a PR, I do not do it for the credit, it’s because I really need/want a specific fix/change in the codebase without the overhead of having to maintain a fork myself.

Deleted Comment

puffoflogic · 4 years ago
I think that way to say that is open a PR, and just let it sit open. Eventually the repo owner will either merge it, close it, or sometimes ask you to do something to it. In the last case, I often just politely decline. It's the flip side of the idea that publishing an open source project doesn't obligate you to support it — likewise, submitting a PR to a project doesn't obligate you to do any more work on it.
adhesive_wombat · 4 years ago
Right, but the point is I don't want the maintainer to avoid or delay handling it because they would like to change something, but either don't want to offend or don't want to go through the tedious rigamarole of editing the file as they want by using the ensemble of GitHub, the Internet, me and my text editor as a very slow and inefficient text editor (especially as I probably don't understand all their comments at first because they know the system inside out, and I don't).

It's not that I will refuse to make changes, I will, within reason, it's that I'm also fine with the maintainer just taking over at any point and finishing it however they want, without any further back-and-forth. And I don't even care whose name is on it.

freedomben · 4 years ago
Unless the PR is really broken, I merge it so they get "credit" for it and then rewrite/refactor/add tests as needed. I do this for a few reasons:

1. I've been on the other side of spending time trying to figure out the arcane organizational details, existing utils functions, etc only to have there be things I missed. This is deeply frustrating.

2. I'm deeply appreciative that somebody took the effort to do something on project of mine! I recognize they did that for free out of good will and don't want to make it harder for them.

3. I know the codebase much better. I can fix up/trim/format/etc properly 10x faster than the contributor can. I'd rather spend 15 mins of my own time than try to suck away an hour or two of their time. I value my time very highly but I also try to be generous and loving, and that requires some giving of my most valuable asset: my time.

Super low effort/spammy PRs do not count. I don't merge those because I don't want to incentivize more of them.

kirke · 4 years ago
My typical workflow - in private business repos, but for the same reasons specified in OP - is as follows:

1. Fork the PR branch. 2. Make the changes I want to see upstream. 3. Create a PR into the author's branch. 4. Ask the author to review my changes. 5. When my PR is complete, finally review and merge The original PR.

This gives me the opportunity to explain my changes in commit messages, and gives the author an opportunity to push back or argue actual functionality changes I made if it's not all coding style. Now the author has license in accepting my changes. It avoids the cumbersome comment/resolve feedback loop, shows the author that their contribution is important and I'm willing to put time into making it right, and ultimately gives them credit when their PR is merged.

travisjungroth · 4 years ago
The PR into their branch sounds nice, but not always necessary. If you forked the PR branch, threw a commit on top, opened and accepted a PR from your-branch to main and declined theirs, would that work? They get their commit in the history, you make the changes you want without back-and-forth. You could link from their-declined PR to your-accepted PR.

I guess that's messy if it's linked to issues and the connotation of "declined PR" isn't as nice.

tomstuart · 4 years ago
The `Co-authored-by` trailer is your friend here. Even if you completely rewrite their code, give them coauthor credit in the commits and they’ll get the satisfaction of seeing their face in the commit history without the hassle of actually addressing all your feedback. https://docs.github.com/en/pull-requests/committing-changes-...
mook · 4 years ago
Wouldn't making commits on top of their (untouched) commits fine too? When creating PRs, there is a checkbox to allow repository committers to push into the PR branch.

That preserves the original author credit (and any GPG signatures), but moves things along. If that's not enabled, making a new PR based on the same commits works too.

masklinn · 4 years ago
If only two people are involved in the PR you don't even need "Co-Authored-By": unless you --reset-author, it's not going to get blown up by updating the commits, only "committer" is.
captn3m0 · 4 years ago
For squash merges, GitHub will autofill the Co-Authored-By in the merge commit, but it is up to you to keep it there.
rurban · 4 years ago
Not for a GNU project, where the PR author didn't file a copyright assignment via snail mail yet. Such PR's could need months.
gsliepen · 4 years ago
I try to help contributors to make it so their commits can be merged without any changes. For some this can be annoying in the beginning, but the goal is that they learn to write quality patches and that I will have less work getting their work merged. I hope that this is a win-win. There are times where I do some changes (rebasing, small fixes, rewording of commit messages), but I will try to ensure their name is in the Author: field in the commit messages.

As mentioned by sph: some projects have maintainers that have much stricter standards for outside contributors that for themselves. Speaking as a maintainer of a project that accepts contributions through PR requests, I am afraid I do indeed have such a double standard, although I try to avoid it as much as possible. I had to set some rules for myself:

- Contributors must fix outright bugs in their commits.

- Style issues are avoided by having a coding style enforced by a code formatting tool. This saves everyones time.

- If the commit is bug free (passes test suite and code review) and is a net improvement, accept it, regardless of my own plans for the project.

- If there is more that can be done to make it ideal, this can be done in a future pull request, or perhaps I will add those changes later myself.

I also try to hold myself to the same standards as I hold contributors to, and now often create a development branch myself for features so they get the same CI testing as pull requests, although I still sometimes bypass this for quick fixes.

caffeine · 4 years ago
Just wanted to say thanks for sharing these rules, I think they’re super helpful.

Do you have any particular rules about performance? I worry that accepting net improvements on functionality alone could result in “death-by-a-thousand-cuts” performance issues down the line (assume it’s a project where performance is one of the deliverables).

Would you ask a contributor to perform benchmarks or some other performance validation, for example?

gsliepen · 4 years ago
It would depend on the project. If performance is important, it should indeed by validated, but then it would greatly help if the project also has a performance test suite that contributors could run locally, and compare their change against the baseline, and a reviewer could then also verify it themselves.

What you do with the performance results really depends on the kind of patch they want to commit. Is it an important bug fix? Then I would get that merged first and worry about fixing performance afterwards. And then you have those patches that improve performance in one area at the cost of decreasing it in another. In that case you might have to use your experience in what is more important to decide whether to accept or reject it.

beebmam · 4 years ago
Here's a relevant quote from Google's code review guidelines on speed https://google.github.io/eng-practices/review/reviewer/speed...

>When code reviews are slow, several things happen: ...

>Developers start to protest the code review process. If a reviewer only responds every few days, but requests major changes to the CL each time, that can be frustrating and difficult for developers. Often, this is expressed as complaints about how “strict” the reviewer is being. If the reviewer requests the same substantial changes (changes which really do improve code health), but responds quickly every time the developer makes an update, the complaints tend to disappear. Most complaints about the code review process are actually resolved by making the process faster.

mhitza · 4 years ago
That guideline definitely must applies only internally. All the Google public repos I've interacted with stall in the PR department like crazy.
pm215 · 4 years ago
For contributions by new authors I usually don't make them do a respin for something minor, for instance if I think a more explanatory comment would be helpful -- I just fix those up when I commit. It saves the author doing multiple rounds dealing with a process they may be unfamiliar with, and it's usually less work on my end. For an established submitter the balance is more to ask them to respin, because they ought to be learning the project rules and process; even there I often fix up nits like typos in comment when committing rather than requesting a respin.

I generally err on the side of retaining the authorship when I do this kind of thing (our project follows the kernel's de-facto standard of retaining the original git author but adding a note of extra changes made in square brackets after the author's signed-off-by and before mine as the committer, which is how we record who's responsible for what parts of a change like this). If you've literally completely written a fresh change to solve the same problem a different way then that should be your authorship with some kind of reported-by or other acknowledgement to the PR author, though.