-
Notifications
You must be signed in to change notification settings - Fork 44
Suggest the required form #235
base: master
Are you sure you want to change the base?
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.
Seems reasonable overall, but given that this also does some deeper changes, I'll wait until the new code gets merged (#234 and a following PR to change the stale timelines).
(Sorry that it took so long, and it might take more time yet since it's thanksgiving week, so it's hard to find people to review stuff...)
Also, IIUC, then this supersedes #224, right? It's more extreme in what it does, but I like the approach of having proper feedback rather than rely on the short comment lines in the welcome message. So if it does, then should #224 be closed?
Also, I didn't see any tests for this?
src/pr-info.ts
Outdated
// Suggest the different lines to the author | ||
const suggestionLines = ( | ||
Object.keys(suggestion).length <= 1 | ||
? prettier.format(JSON.stringify(suggestion), { tabWidth: 4, filepath: ".json" }) |
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.
Is prettier
really needed here, if all it does is just suggest a bit of json to use?
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's overkill for JSON but I used it because it's uncomplicated. It minimizes the diffs from the existing JSON that are suggested to the author.
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'm not following this. AFAICT, the above just formats the json value from scratch, so how is it minimizing diffs?
In addition to that, there's the length
condition that makes it use a plain stringify
for short objects, and prettier can't do that then it's even worse to use it for some cases and do its job manually in other cases.
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.
The format is closer to the files that are currently in the DT repo.
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'll ask around whether people mind adding it... But see also the comment below about using it only for some cases, which I still find disturbing, especially if prettier is included.
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 finally talked to @RyanCavanaugh about it, and he doesn't like adding prettier here too...
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.
Okay, thanks for asking around. I've removed it.
f9c7057
to
87a49f7
Compare
All good, thank you for the reviews!
Great! Done ✔️
Done. I added DefinitelyTyped/DefinitelyTyped#49639 |
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.
Many more comments now, since I looked at the code more thoroughly.
Also, it would be good to add another test that shows suggesting adding a line, or even better, both adding and removing.
src/comments.ts
Outdated
|
||
export const Suggestions = (user: string) => ({ | ||
tag: "suggestions", | ||
status: `@${user} I noticed these differences from the required form. If you can revise your changes to avoid them, so much the better! Otherwise please reply with explanations why they're needed (unless it's obvious) and a maintainer will take a look. Thanks!`, |
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.
You probably have a good idea for how often exceptions are needed. If it's not common, then I think that the below is more effective in discouraging arguments.
status: `@${user} I noticed these differences from the required form. If you can revise your changes to avoid them, so much the better! Otherwise please reply with explanations why they're needed (unless it's obvious) and a maintainer will take a look. Thanks!`, | |
status: `@${user} I noticed these differences from the required form. If you can revise your changes to avoid them, so much the better! If they are absolutely needed, please reply with explanations why they're needed and a maintainer will take a look. Thanks!`, |
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 this applies to tsconfig.json
and package.json
, as well as tslint.json
, I'd like to see the current language in action and how people react to it first, then revisit based on the observed shortcomings.
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.
OK, so maybe just drop the (unless it's obvious)
comment? If it's really obvious, people will most likely not bother with it anyway.
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.
Done ✔️
src/execute-pr-actions.ts
Outdated
@@ -106,6 +111,32 @@ function getMutationsForCommentRemovals(actions: Actions, botComments: ParsedCom | |||
}); | |||
} | |||
|
|||
function getMutationsForSuggestions(actions: Actions, pr: PR_repository_pullRequest) { | |||
if (pr.reviews?.nodes?.find(review => review?.author?.login === "typescript-bot")) return []; |
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.
-
sameUser("typescript-bot", review?.author?.login || "-")
-
Even better, make it into a new
isBot
function inutil/util.ts
, and use it also in pr-info.ts.. -
IIUC, this is a once-per-PR thing? Shouldn't it be once-per-head, so it will re-post reviews after people edit stuff? (I'm thinking about someone seeing the suggestion, fixes one thing but leaves another, then dismiss the whole thing, and then a maintainer who is used to seeing these bot-reviews misses the whole thing.)
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.
Done ✔️
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.
Maybe I'm missing something, or maybe you didn't push more commits yet, but the code that I see doesn't do that.
But more than that, the code that I see posts a new review regardless of whether one exists: will the GH api update an existing one? If not, then it will post a new review on every run.
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 excludes existing suggestions' diffs from subsequent suggestions, so suggestions
will be []
if they were already posted. I should've added some comments, adding them now ✔️
src/pr-info.ts
Outdated
// Suggest the different lines to the author | ||
const suggestionLines = ( | ||
Object.keys(suggestion).length <= 1 | ||
? prettier.format(JSON.stringify(suggestion), { tabWidth: 4, filepath: ".json" }) |
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'm not following this. AFAICT, the above just formats the json value from scratch, so how is it minimizing diffs?
In addition to that, there's the length
condition that makes it use a plain stringify
for short objects, and prettier can't do that then it's even worse to use it for some cases and do its job manually in other cases.
src/pr-info.ts
Outdated
const lines = contents.split(/^/m); | ||
let i = 0; | ||
while (suggestionLines[i].trim() === lines[i].trim()) i++; | ||
let j = 1; | ||
while (suggestionLines[suggestionLines.length - j].trim() === lines[lines.length - j].trim()) j++; |
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.
Something's fishy here. In the example that you added, there is one difference of dropping a new await-promise
key, so the resulting suggestion has zero length. It looks like GH will properly take it to show a suggestion to remove the lines but I'm not sure about it. If it will always do that, then there should be a comment saying that this could happen and that's as intended.
Also, I'm worried about this code depending on a difference, otherwise it would find a bogus i
/j
.
Also, this whole code is very verbose for something to include in a small function, so I'd rather see it move out into some makeJsonSuggestion
thing that will do all of the necessary work.
Also, I think that the code itself could be improved. (Something along the lines of popping lines from both while they're equal, then finding the first index where they're different.)
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.
Done ✔️
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.
Looks much more readable -- one slight comment (feel free to ignore and I'll probably do it later: I find it even easier to read if all the variables are defined on one line:
const lines = newText.split(/^/m), startLine = 1, endLine = lines.length;
(because this way I don't need to look into the code and figure out that lines
doesn't change).
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.
No objection but I'm not sure what's best here in particular, because startLine
and endLine
aren't constant?
src/compute-pr-actions.ts
Outdated
context.suggestions = noNulls(flatten(info.pkgInfo.map(pkg => pkg.files.map(({ path, suggestion }) => | ||
suggestion && { path, ...suggestion })))); |
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 uses noNulls
, but the list might have undefined
s. I see that the function uses !=
instead of !==
so it works, but it looks bad to rely on this. (I remember other places where I wanted to remove undefineds, and missed that it's doing it.) So it would be better to:
- Rename it to something that indicates
noNullsOrUndefineds
but with some name that isn't so obnoxiously long. Or maybe just add a comment saying it? - Or make this code
suggestion ? {...} : null
?
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.
Done: #249
Looks closer overall. Two things in addition to the above:
|
#235 (comment) Rename to `noNullish()`. I went with "nullish" like ["nullish coalescing"](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#nullish-coalescing), "nullish checks", etc.
Done: 4183e39 I hand-edited another file in the existing fixture. The bot adds the line that I hand-removed. |
7c8adaf
to
3c981c3
Compare
d823ee3
to
4af0c0e
Compare
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.
Not read the code too deeply other than tests which seems legit, but this is a clever idea 👍🏻
c764954
to
7176fba
Compare
d467d32
to
8a76ccd
Compare
Co-authored-by: Eli Barzilay <[email protected]>
1d39a68
to
9e931d1
Compare
Putting this out there for feedback.
Iterate on #224. Show the differences from the required form as suggestions. Like #224, only shows freshly introduced differences, not preexisting diffs.