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

fix: Create GitHub comment as table #3948

Merged
merged 5 commits into from
May 15, 2024

Conversation

novakzaballa
Copy link
Contributor

@novakzaballa novakzaballa commented May 14, 2024

Thanks for submitting a PR! Please check the boxes below:

  • I have run pre-commit to check linting
  • I have added information to docs/ if required so people know about the feature!
  • I have filled in the "Changes" section below?
  • I have filled in the "How did you test this code" section below?
  • I have used a Conventional Commit title for this Pull Request

Changes

  • Improve GitHub comment to look like a table

image

How did you test this code?

  • Some unit tests updated.
  • Link an external resource manually.

Copy link

vercel bot commented May 14, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 14, 2024 10:39pm
flagsmith-frontend-preview ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 14, 2024 10:39pm
flagsmith-frontend-staging ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 14, 2024 10:39pm

Copy link
Contributor

github-actions bot commented May 14, 2024

Uffizzi Preview deployment-51714 was deleted.

Copy link

codecov bot commented May 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.99%. Comparing base (132ef77) to head (0e9d821).
Report is 14 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3948   +/-   ##
=======================================
  Coverage   95.98%   95.99%           
=======================================
  Files        1135     1135           
  Lines       36182    36220   +38     
=======================================
+ Hits        34731    34771   +40     
+ Misses       1451     1449    -2     

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

LINK_FEATURE_TEXT = "### This pull request is linked to a Flagsmith Feature (`%s`):\n"
LINK_FEATURE_TITLE = """**Flagsmith feature linked:** `%s`
Default Values:\n"""
FEATURE_TABLE_HEADER = """| Environment | Enabled | Value | Type | Updated (UTC) |
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
FEATURE_TABLE_HEADER = """| Environment | Enabled | Value | Type | Updated (UTC) |
FEATURE_TABLE_HEADER = """| Environment | Enabled | Value | Type | Last Updated (UTC) |

This way, we won't have to prepend "Last Updated" to every timestamp in this column.

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.

Comment on lines 89 to 91
last_updated_string = LAST_UPDATED_FEATURE_TEXT % (
datetime.datetime.now().strftime("%dth %b %Y %I:%M%p")
)
Copy link
Member

Choose a reason for hiding this comment

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

I'm not a fan of the custom datetime format.

Let's consider either sticking to ISO8601 or using Django locale, i.e.:

from django.utils.formats import get_format

datetime_format = get_format('DATETIME_INPUT_FORMATS')[0]

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.

@khvn26
Copy link
Member

khvn26 commented May 14, 2024

Please cover the code reported as uncovered with tests, or add a # pragma: no cover annotation, preferably with an explanation why.

@novakzaballa
Copy link
Contributor Author

Please cover the code reported as uncovered with tests, or add a # pragma: no cover annotation, preferably with an explanation why.

I ended up adding the coverage. Let's keep this coverage while it is possible and is worth it.

Comment on lines 59 to 67
expected_comment_body = (
"**Flagsmith feature linked:** `feature_with_value`\n"
+ "Default Values:\n"
+ "| Environment | Enabled | Value | Last Updated (UTC) |\n"
+ "| :--- | :----- | :------ | :------ |\n"
+ f"| [Test Environment](https://example.com/project/{project.id}/"
+ f"environment/{environment.api_key}/features?feature={feature_with_value.id}&tab=value) "
+ "| ❌ Disabled | `value` | 2024-01-01 00:00:00 |\n"
)
Copy link
Member

Choose a reason for hiding this comment

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

This is nice! nit: Python supports multiline strings so you could do this:

Suggested change
expected_comment_body = (
"**Flagsmith feature linked:** `feature_with_value`\n"
+ "Default Values:\n"
+ "| Environment | Enabled | Value | Last Updated (UTC) |\n"
+ "| :--- | :----- | :------ | :------ |\n"
+ f"| [Test Environment](https://example.com/project/{project.id}/"
+ f"environment/{environment.api_key}/features?feature={feature_with_value.id}&tab=value) "
+ "| ❌ Disabled | `value` | 2024-01-01 00:00:00 |\n"
)
expected_comment_body = (
"**Flagsmith feature linked:** `feature_with_value`\n"
"Default Values:\n"
"| Environment | Enabled | Value | Last Updated (UTC) |\n"
"| :--- | :----- | :------ | :------ |\n"
f"| [Test Environment](https://example.com/project/{project.id}/"
f"environment/{environment.api_key}/features?feature={feature_with_value.id}&tab=value) "
"| ❌ Disabled | `value` | 2024-01-01 00:00:00 |\n"
)

Looks a bit nicer this way, IMO.

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.

Comment on lines +108 to +111
if v.get("segment_name") is not None and v["segment_name"] != last_segment_name:
result += "\n" + LINK_SEGMENT_TITLE % (v["segment_name"])
last_segment_name = v["segment_name"]
result += FEATURE_TABLE_HEADER
Copy link
Member

Choose a reason for hiding this comment

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

We should add a segment to the test or slap a # pragma: no cover on L108.

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.

@novakzaballa novakzaballa added this pull request to the merge queue May 15, 2024
Merged via the queue into main with commit bf67b1d May 15, 2024
24 checks passed
@novakzaballa novakzaballa deleted the fix/create-github-comment-as-table branch May 15, 2024 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Issue related to the REST API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants