Skip to content
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

Suggest the required form #235

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open

Conversation

jablko
Copy link
Contributor

@jablko jablko commented Nov 24, 2020

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.

Copy link
Contributor

@elibarzilay elibarzilay left a 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" })
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

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...

Copy link
Contributor Author

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.

src/comments.ts Outdated Show resolved Hide resolved
@jablko
Copy link
Contributor Author

jablko commented Nov 26, 2020

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...)

All good, thank you for the reviews!

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?

Great! Done ✔️

Also, I didn't see any tests for this?

Done. I added DefinitelyTyped/DefinitelyTyped#49639

Copy link
Contributor

@elibarzilay elibarzilay left a 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!`,
Copy link
Contributor

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.

Suggested change
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!`,

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done ✔️

src/compute-pr-actions.ts Outdated Show resolved Hide resolved
src/execute-pr-actions.ts Outdated Show resolved Hide resolved
@@ -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 [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. sameUser("typescript-bot", review?.author?.login || "-")

  2. Even better, make it into a new isBot function in util/util.ts, and use it also in pr-info.ts..

  3. 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.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done ✔️

Copy link
Contributor

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.

Copy link
Contributor Author

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 Show resolved Hide resolved
src/execute-pr-actions.ts Show resolved Hide resolved
src/pr-info.ts Outdated Show resolved Hide resolved
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" })
Copy link
Contributor

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
Comment on lines 442 to 446
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++;
Copy link
Contributor

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.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done ✔️

Copy link
Contributor

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).

Copy link
Contributor Author

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/pr-info.ts Outdated Show resolved Hide resolved
Comment on lines 312 to 307
context.suggestions = noNulls(flatten(info.pkgInfo.map(pkg => pkg.files.map(({ path, suggestion }) =>
suggestion && { path, ...suggestion }))));
Copy link
Contributor

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 undefineds. 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done: #249

@elibarzilay
Copy link
Contributor

Looks closer overall. Two things in addition to the above:

  • Can you add a test that adds (hopefully also removes) lines? It's fine to just make a copy of the test you added and hand-edit it.

  • There's a complaint now about PR's ending up in the "Other" column when the PRs don't have the expected header -- instead of making it go to "Needs Author Action" with a comment saying what's wrong. It's not really related to this PR, but if you see a quick way to add it, it would be better than me making a separate PR which will probably have some bad conflicts with this one. If you don't get to it, I might do so as commits on top of this PR.

elibarzilay pushed a commit that referenced this pull request Dec 2, 2020
#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.
@jablko
Copy link
Contributor Author

jablko commented Dec 3, 2020

Can you add a test that adds (hopefully also removes) lines? It's fine to just make a copy of the test you added and hand-edit it.

Done: 4183e39

I hand-edited another file in the existing fixture. The bot adds the line that I hand-removed.

Copy link
Contributor

@orta orta left a 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 👍🏻

@jablko jablko force-pushed the patch-15 branch 5 times, most recently from d467d32 to 8a76ccd Compare January 20, 2021 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants