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

Add labels in a more principled way. #90

Merged
merged 4 commits into from
Nov 14, 2024
Merged

Add labels in a more principled way. #90

merged 4 commits into from
Nov 14, 2024

Conversation

csilvers
Copy link
Member

Summary:

Before, I was just munging the label to the name, so I wouldn't have
to change a lot of code. This didn't work because the name was used
in places where the code needs it to actually be a name (e.g. when
telling github what reviewers to add to the PR).

So now I store names and labels separately, and just print the label
explicitly when emitting the comment text. This also gives me more
control over where the label goes; all in all a more maintainable
arrangement.

Issue: https://khanacademy.atlassian.net/browse/FEI-5970

Test plan:

yarn jest

Before, I was just munging the label to the name, so I wouldn't have
to change a lot of code.  This didn't work because the name was used
in places where the code needs it to actually be a name (e.g. when
telling github what reviewers to add to the PR).

So now I store names and labels separately, and just print the label
explicitly when emitting the comment text.  This also gives me more
control over where the label goes; all in all a more maintainable
arrangement.

Issue: https://khanacademy.atlassian.net/browse/FEI-5970

Test plan:
yarn jest
@csilvers csilvers self-assigned this Nov 12, 2024
@khan-actions-bot
Copy link
Contributor

khan-actions-bot commented Nov 12, 2024

Gerald

Required Reviewers
  • @Khan/github-actions for changes to dist/index.js, setup-files/NOTIFIED, setup-files/REVIEWERS, src/runOnPullRequest.js, src/runOnPush.js, src/utils.js, src/__test__/main.test.js, src/__test__/utils.test.js

Don't want to be involved in this pull request? Comment #removeme and we won't notify you of further changes.

@khan-actions-bot khan-actions-bot requested a review from a team November 12, 2024 22:42
@@ -22,6 +22,8 @@ import {
MATCH_COMMENT_HEADER_REGEX,
} from './constants';

type NameToLabelToFiles = {[name: string]: {[label: string]: string[], ...}, ...};
Copy link
Member

@lillialexis lillialexis Nov 12, 2024

Choose a reason for hiding this comment

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

Before, if there were multiple matching rules, I think it would do:

{
  lilli: [fileFromR1, fileFromR2, fileFromR2]
  ...
}

Then in the comment it would do:

lilli because fileFromR1, fileFromR2, fileFromR2

But now if there are multiple matching rules, I think I would want:

lilli (rule1): fileFromR1
lilli (rule2): fileFromR2, fileFromR2

I'm not clear if this structure gets us to that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it does! You can see in some of the test output.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe it does, but the syntax is starting to twist my head...

Copy link
Member Author

Choose a reason for hiding this comment

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

If js allowed non-string map keys, I could do a map from (person, label) to [files], but it doesn't, so this is the best I could do...

src/runOnPush.js Outdated
) => {
const names: string[] = Object.keys(peopleToFiles);
if (peopleToFiles && names.length) {
type NameToLabelToFiles = {[name: string]: {[label: string]: string[], ...}, ...};
Copy link
Member

Choose a reason for hiding this comment

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

Can we put this somewhere shared so as to not dupe?

Copy link
Member Author

Choose a reason for hiding this comment

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

If you want. I like having it in each place so it's easier to find when reading the file; flow won't let them get out of sync. But I know some people feel very militant about DRY!

let body = `<details>\n<summary><b>${header}</b></summary>\n\n`;
names.forEach((person: string) => {
const files = peopleToFiles[person];
const names: string[] = Object.keys(peopleToLabelToFiles);
Copy link
Member

Choose a reason for hiding this comment

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

I bet this impacts the #remove-me functionality. Have you checked that? This is big enough that it's fine to do that part in another PR if it's easier.

Copy link
Member Author

Choose a reason for hiding this comment

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

I did check that, at least by reading the code. My changes do not affect #remove-me as far as I can tell. The remove-me logic goes through getFilteredLists(), and that works on the key to peopleToLabelToFiles, which is still the person's name. (My previous way of doing this did break remove-me, but this way should not.)

Why did you think this would impact remove-me?

Copy link
Member

@lillialexis lillialexis Nov 12, 2024

Choose a reason for hiding this comment

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

Why did you think this would impact remove-me?

I guess I thought it might impact the remove-me function because I didn't really know how to remove me function works… I just had a hunch that it might, and I wanted to make sure that it was considered and tested.

Sounds like the way that the functionality works is that it just re-creates the comment minus the removed person? So if the removed person was originally in there twice, and they wanted to be removed, it just leave them out for both rules? Instead of, say, matching the name in the body of the previous comment.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's right.

Copy link
Member

Choose a reason for hiding this comment

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

#removeme

@khan-actions-bot khan-actions-bot requested a review from a team November 12, 2024 23:13
Copy link
Member

@lillialexis lillialexis left a comment

Choose a reason for hiding this comment

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

Tentatively approving but we will want to check the #remove-me functionality.

You can also just test things in the Gerald repo, I think, if you want to avoid the long chain of gerald → actions → webapp.

There's also some local tester utility, but I have no idea what it does or how it works. I just saw it when picking though the code.

@lillialexis
Copy link
Member

Here's Gerald's comment: #90 (comment) for more context on self-testing and #remove-me

@csilvers
Copy link
Member Author

You can also just test things in the Gerald repo, I think, if you want to avoid the long chain of gerald → actions → webapp.

Sadly, I can't, because the gerald repo's github action is Khan/actions@gerald-pr-v3, so it doesn't see the new code until I go through all the rigamarole.

@lillialexis
Copy link
Member

@csilvers I believe you can temporarily point Gerald to the sha that is one behind of the tip of your PR? Because the sha of the commit that points to one behind the tip is the tip...

@csilvers
Copy link
Member Author

csilvers commented Nov 12, 2024

@csilvers I believe you can temporarily point Gerald to the sha that is one behind of the tip of your PR? Because the sha of the commit that points to one behind the tip is the tip...

Oh, I can change the git tag. But that will change things for everyone, not just me, so it's a little scary. I'll try it later in the day.

@lillialexis
Copy link
Member

@csilvers I think on this branch, point this repo's workflow file to a sha on this branch. I think that should work in a way that doesn't affect other people?

@csilvers
Copy link
Member Author

@csilvers I think on this branch, point this repo's workflow file to a sha on this branch. I think that should work in a way that doesn't affect other people?

I don't know how to do that. Right now the repo's gerald-pr.yml file looks like this:

    steps:
      - uses: Khan/actions@gerald-pr-v3
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          admin-token: ${{ secrets.KHAN_ACTIONS_BOT_TOKEN }}

what are you proposing I change it to?

@csilvers
Copy link
Member Author

@MiguelCastillo you're just being added because I needed a name for testing this new functionality.

There's one more test you could help with -- could you add a comment to this PR that just says #removeme? I want to test that this then auto-removes you as a reviewer.

csilvers added a commit to Khan/actions that referenced this pull request Nov 13, 2024
The way I implemented it before didn't work well with REVIEWERS.  Now
it's a bit more complicated but also more principled.

Issue: https://khanacademy.atlassian.net/browse/FEI-5970

Test plan:
The comments and such on Khan/gerald#90
csilvers added a commit to Khan/actions that referenced this pull request Nov 13, 2024
🖍 _This is an audit!_ 🖍

## Summary:
The way I implemented it before didn't work well with REVIEWERS.  Now
it's a bit more complicated but also more principled.

Issue: https://khanacademy.atlassian.net/browse/FEI-5970

## Test plan:
The comments and such on Khan/gerald#90

Author: csilvers

Auditors: #github-actions, jeresig, lillialexis

Required Reviewers:

Approved By:

Checks: ⌛ Lints, ⌛ gerald

Pull Request URL: #96
@MiguelCastillo
Copy link
Member

@MiguelCastillo you're just being added because I needed a name for testing this new functionality.

There's one more test you could help with -- could you add a comment to this PR that just says #removeme? I want to test that this then auto-removes you as a reviewer.

Sure thang!

#removeme

@MiguelCastillo
Copy link
Member

Not sure how important it is, but the tricky thing about using # to start a trigger word is that github thinks you want to reference a PR. Just an annoying observation :D

Screenshot 2024-11-13 at 4 38 30 PM

@csilvers
Copy link
Member Author

@MiguelCastillo : I think you may need to say #removeme here, at the top level.

@MiguelCastillo
Copy link
Member

MiguelCastillo commented Nov 13, 2024

@MiguelCastillo : I think you may need to say #removeme here, at the top level.

I did above. I also did it as an inline comment in case that made a difference. Will do a standalone one too.

#90 (comment)

@MiguelCastillo
Copy link
Member

#removeme

@csilvers
Copy link
Member Author

Oh, it's still processing the PR, maybe it will be a while before it's ready to run the github actions to do the update.

@lillialexis
Copy link
Member

@csilvers I think on this branch, point this repo's workflow file to a sha on this branch. I think that should work in a way that doesn't affect other people?

I don't know how to do that. Right now the repo's gerald-pr.yml file looks like this:

    steps:
      - uses: Khan/actions@gerald-pr-v3
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          admin-token: ${{ secrets.KHAN_ACTIONS_BOT_TOKEN }}

what are you proposing I change it to?

@csilvers I tried and failed :-( #91

@csilvers
Copy link
Member Author

It's still processing the PR. Something is very wrong. Probably the huge index.js file.

@khan-actions-bot khan-actions-bot removed the request for review from MiguelCastillo November 14, 2024 17:49
@csilvers
Copy link
Member Author

OK, I'm landing this. I'm not convinced #removeme works, but I have no experience with it, so I can't say for sure, or if not if it's this PR that broke it or not. If it's being problematic in a way that matters I'm sure we'll hear about it!

@csilvers csilvers merged commit c9b7069 into main Nov 14, 2024
4 checks passed
@csilvers csilvers deleted the fix-reviewers branch November 14, 2024 18:16
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.

4 participants