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

[Test Owners] Add script to get owners for files #193277

Merged
merged 7 commits into from
Sep 20, 2024

Conversation

wayneseymour
Copy link
Member

@wayneseymour wayneseymour commented Sep 18, 2024

Summary

Node script to report ownership of a given file in our repo.

The script's source of truth is .github/CODEOWNERS, which is generated by @kbn/generate

In order to reach the goal of have zero files without code ownership, this is one small step along the way.

To Test

Happy Path

node scripts/get_owners_for_file.js --file packages/kbn-ace/src/ace/modes/index.ts

 succ elastic/kibana-management

Unknown Path

node scripts/get_owners_for_file.js --file some-file.txt

ERROR Ownership of file [some-file.txt] is UNKNOWN

Error Path

node scripts/get_owners_for_file.js

ERROR Missing --flag argument

  node scripts/get_owners_for_file.js

  Report file ownership from GitHub CODEOWNERS file.

  Options:
    --file             Required, path to the file to report owners for.
    --verbose, -v      Log verbosely
    --debug            Log debug messages (less than verbose)
    --quiet            Only log errors
    --silent           Don't log anything
    --help             Show this message

Notes

Along with this small pr, next will be to ensure owners are assigned to all ES and KBN Archives. See more info in the link below:

Contributes to: #192979

@wayneseymour wayneseymour added release_note:skip Skip the PR/issue when compiling release notes backport:skip This commit does not require backporting FTR labels Sep 18, 2024
@wayneseymour wayneseymour self-assigned this Sep 18, 2024
@wayneseymour wayneseymour requested a review from a team as a code owner September 18, 2024 11:51
@wayneseymour wayneseymour marked this pull request as draft September 18, 2024 11:54
@wayneseymour
Copy link
Member Author

/ci

@wayneseymour
Copy link
Member Author

/ci

"node scripts/build_api_docs --plugin @kbn/code-owners --stats comments"
@wayneseymour wayneseymour marked this pull request as ready for review September 18, 2024 14:43
@wayneseymour
Copy link
Member Author

@elasticmachine merge upstream

Comment on lines +81 to +84
const targetFile = flags.file as string;
if (!targetFile) throw createFlagError(`Missing --flag argument`);
Copy link
Member

Choose a reason for hiding this comment

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

Should we check if provided argument is actually a valid existing path?

Did some testing and I would expect error pointing the path is incorrect for the last 2 calls:

[get-owners-for-files][~/github/kibana]$ node scripts/get_owners_for_file.js --file packages/kbn-ace/src/ace/modes/index.ts
 succ elastic/kibana-management
[get-owners-for-files][~/github/kibana]$ node scripts/get_owners_for_file.js --file packages/kbn-ace/src/ace/modes
 succ elastic/kibana-management
[get-owners-for-files][~/github/kibana]$ node scripts/get_owners_for_file.js --file packages/kbn-ace/src/ace/mode
 succ elastic/kibana-management
[get-owners-for-files][~/github/kibana]$ node scripts/get_owners_for_file.js --file packages/kbn-ace/src/ace/x
 succ elastic/kibana-management

Copy link
Member Author

Choose a reason for hiding this comment

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

Hrmm, as I understand it, the codewoners resolution is essentially looking for files and folders.
Such that, if a file is not found, the result can be a parent dir (depending how the ownership is declared [specific file vs folder]). This is my guess on the algo; that's how I do it manually.

That said, $ node scripts/get_owners_for_file.js --file packages/kbn-ace/src/ace/x:

 succ elastic/kibana-management

...gives me pause.

Lemme see what I can discover.

Good catch mate!

Copy link
Member Author

Choose a reason for hiding this comment

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

FIx?

Sorry about the force push. I was in a meeting showing someone something and ran a rebase in the wrong dir. Wont happen again (after opening pr's for review)

Copy link
Member

Choose a reason for hiding this comment

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

no worries, checking...

Copy link
Contributor

Choose a reason for hiding this comment

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

The error message seems to be off. It mentions a --flag argument, that's not present in the args.

Copy link
Member

@dmlemeshko dmlemeshko left a comment

Choose a reason for hiding this comment

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

Great to see the new script, left a question about path validation

Copy link
Member

@dmlemeshko dmlemeshko left a comment

Choose a reason for hiding this comment

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

LGTM.

general question:

[get-owners-for-files][~/github/kibana]$ node scripts/get_owners_for_file.js --file x-pack/test/api_integration/deployment_agnostic
ERROR Ownership of file [x-pack/test/api_integration/deployment_agnostic] is UNKNOWN

[get-owners-for-files][~/github/kibana]$ node scripts/get_owners_for_file.js --file x-pack/test/api_integration/deployment_agnostic/default_configs
 succ elastic/appex-qa,#temporarily,to,monitor,tests,migration

It seems to be fine that "root" test directory has no owners as long as all of it child folders (or their child folders, etc...) have owners. Do I see it the right way?

x-pack/test/api_integration/deployment_agnostic may not have explicit owner, but
x-pack/test/api_integration/deployment_agnostic/default_configs
x-pack/test/api_integration/deployment_agnostic/services
...
should either have one, or their files should. wdyt?

@wayneseymour
Copy link
Member Author

LGTM.

It seems to be fine that "root" test directory has no owners as long as all of it child folders (or their child folders, etc...) have owners. Do I see it the right way?

x-pack/test/api_integration/deployment_agnostic may not have explicit owner, but x-pack/test/api_integration/deployment_agnostic/default_configs x-pack/test/api_integration/deployment_agnostic/services ... should either have one, or their files should. wdyt?

Yes I believe that is correct. We will know more once we get closer to having zero files/folders without ownership in test, x-pack/test && x-pack/test_serverless

@wayneseymour
Copy link
Member Author

Force pushed again to see if I can stop the auto-commit which kicked off a ton of extra tests that have nothing to do with my pr

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Unknown metric groups

API count

id before after diff
@kbn/code-owners 8 9 +1

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @wayneseymour

@PhilippeOberti PhilippeOberti removed the request for review from a team September 19, 2024 21:52
{
description: 'Report file ownership from GitHub CODEOWNERS file.',
flags: {
string: ['file'],
Copy link
Member Author

Choose a reason for hiding this comment

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

@delanni is this not it bud?

Copy link
Member Author

Choose a reason for hiding this comment

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

@delanni Haven't heard from ya man. Gonna merge this soon. Please lemme know if you've an objection

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I didn't see the message.
I meant the wording of the error:

throw createFlagError(`Missing --flag argument`);

but there's no --flag argument, it's --file

Copy link
Member Author

Choose a reason for hiding this comment

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

Ahhhhh!!!!

Copy link
Member Author

Choose a reason for hiding this comment

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

@wayneseymour wayneseymour merged commit 8a79173 into elastic:main Sep 20, 2024
21 checks passed
wayneseymour added a commit that referenced this pull request Sep 20, 2024
## Summary

Modify code owner declarations for @elastic/response-ops team in
`.github/CODEOWNERS`

### Update for Reviewers
With the merge of [this](#193277),
you can now do this:
`node scripts/get_owners_for_file.js --file
x-pack/test/functional/es_archives/action_task_params`

```
 succ elastic/response-ops
```
_So, you can use this script to see if the code owners file is reporting
erroneously_

### For Reviewers
Added these lines:
```
/x-pack/test/functional/es_archives/actions @elastic/response-ops
/x-pack/test/functional/es_archives/alerting @elastic/response-ops
/x-pack/test/functional/es_archives/alerts @elastic/response-ops
/x-pack/test/functional/es_archives/alerts_legacy @elastic/response-ops
/x-pack/test/functional/es_archives/observability/alerts @elastic/response-ops
/x-pack/test/functional/es_archives/actions @elastic/response-ops
/x-pack/test/functional/es_archives/rules_scheduled_task_id  @elastic/response-ops
/x-pack/test/functional/es_archives/alerting/8_2_0  @elastic/response-ops
```

Most of these changes come from searching for `esArchiver.load`, within
`x-pack/test/alerting_api_integration`
Obviously this can easily be erroneous, so please keep me honest.

#### Notes

This is a best guess effort, as we march towards having zero files
within `test` && `x-pack/test` && `x-pack/test_serverless` without a
code owner.

In the end, this will contribute to better reporting.

Contribues to: #192979

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
wayneseymour added a commit that referenced this pull request Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting FTR release_note:skip Skip the PR/issue when compiling release notes v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants