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 support for saving comments in global YAML file #895

Merged
merged 7 commits into from
Oct 18, 2024
Merged

Conversation

JerrySentry
Copy link
Contributor

@JerrySentry JerrySentry commented Oct 16, 2024

Add a key to the yaml JSON field to store the comments included YAML str in its original form.
Things considered/validated:

  1. Does not affect DB trigger functions for the yaml column
  2. Does not affect UserYaml object, values are fetched by specific keys
  3. Does not affect CodecovYamlValidator, when JSON is stored into the column it is already validated, however will add a followup PR in shared to future proof to protect the key from being used in the codecov YAML schema.

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. In 2022 this entity acquired Codecov and as result Sentry is going to need some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

@codecov-notifications
Copy link

codecov-notifications bot commented Oct 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

Copy link

codecov bot commented Oct 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.31%. Comparing base (7da1080) to head (1d85bc8).

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #895   +/-   ##
=======================================
  Coverage   96.31%   96.31%           
=======================================
  Files         823      823           
  Lines       19092    19098    +6     
=======================================
+ Hits        18389    18395    +6     
  Misses        703      703           
Flag Coverage Δ
unit 92.66% <100.00%> (+<0.01%) ⬆️
unit-latest-uploader 92.66% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -49,10 +50,12 @@ def convert_yaml_to_dict(self, yaml_input):
raise ValidationError(message)

@sync_to_async
def execute(self, username, yaml_input):
def execute(self, username: str, yaml_input: str) -> Owner:
self.validate()
self.owner = self.get_owner(username)
self.authorize()
self.owner.yaml = self.convert_yaml_to_dict(yaml_input)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

One of two of the actual changes.

if owner.yaml is None:
return
return None
current_owner = info.context["request"].current_owner
if not current_user_part_of_org(current_owner, owner):
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 other change.

@JerrySentry JerrySentry marked this pull request as ready for review October 16, 2024 18:27
@JerrySentry JerrySentry requested a review from a team as a code owner October 16, 2024 18:27
Copy link
Contributor

@suejung-sentry suejung-sentry left a comment

Choose a reason for hiding this comment

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

Nice! I like how simple it is!
Probably worth end to end testing in staging to confirm as much as possible, as I could see some of the parsing ending up weird, or any edge cases around escaping. Also not sure how to test that the other clients than the graphql resolvers are happy with the change than smoke testing user flows in staging

self.validate()
self.owner = self.get_owner(username)
self.authorize()
self.owner.yaml = self.convert_yaml_to_dict(yaml_input)
if self.owner.yaml:
self.owner.yaml["to_string"] = yaml_input
Copy link
Contributor

Choose a reason for hiding this comment

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

We can consider pulling this string key out into a constant so it's more discoverable (not sure all the Python conventions for this)

"codecov": {
"require_ci_to_pass": True,
},
"to_string": "\n" "codecov:\n" " require_ci_to_pass: yes\n",
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add an example after line 36 in this file where the to_string would have comments? Like below I guess

good_yaml_with_comments = """
codecov:
  # this is a yaml comment
  require_ci_to_pass: yes
"""
'\ncodecov:\n  # this is a yaml comment\n  require_ci_to_pass: yes\n'

require_ci_to_pass: no
to_string: hello
"""
config = yaml.final_commit_yaml(self.commit, self.org)
Copy link
Contributor

Choose a reason for hiding this comment

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

In case you didn't see this, I wanted to see what final_commit_yaml does - there is this essay about the logic 😂
https://github.com/codecov/shared/blob/f40874907d3ddbe6993c8016c3f09306cc14a9f8/shared/yaml/user_yaml.py#L128

I think it's not a problem because your change only deals with the "ownerYaml".

I also checked what other clients than the graphql resolver for the owner yaml in this PR may be accessing the revised owner.yaml field. Searching "owner.yaml" shows nothing in shared and a couple spots in worker that all point back to the same final_commit_yaml function above. That function returns a dictionary that doesn't appear to matter if it has the extra to_string on it from what I can tell. So no additional work there needed from what I can tell.

@@ -49,10 +50,12 @@ def convert_yaml_to_dict(self, yaml_input):
raise ValidationError(message)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd guess in a perfect world we would want validate_yaml (in shared) to reject if any reserved keys (like to_string) are in it. It's probably a lot of work for something unlikely, though so can let it be

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh never mind I had missed the note in the PR description! Sounds like that will get covered later - nice!

@JerrySentry JerrySentry added this pull request to the merge queue Oct 18, 2024
Merged via the queue into main with commit 33fc91b Oct 18, 2024
19 checks passed
@JerrySentry JerrySentry deleted the oct_15_comment branch October 18, 2024 18:13
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.

2 participants