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

WIP: Add support for Secret Incidents API endpoints #84

Closed
wants to merge 7 commits into from

Conversation

irgeek
Copy link

@irgeek irgeek commented Dec 29, 2023

The PR adds models and methods to handle the Secret Incidents API endpoints. It still needs a changelog entry and (probably) some cleanup, but I wanted to get some feedback before I put too much work into it. As requested I've sliced the changes up in to several commits for ease of review.

@codecov-commenter
Copy link

codecov-commenter commented Dec 29, 2023

Codecov Report

Attention: 12 lines in your changes are missing coverage. Please review.

Comparison is base (7cf0356) 92.28% compared to head (640ad48) 93.29%.

Files Patch % Lines
pygitguardian/client.py 84.50% 11 Missing ⚠️
pygitguardian/utils/response.py 96.00% 1 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #84      +/-   ##
==========================================
+ Coverage   92.28%   93.29%   +1.01%     
==========================================
  Files           6       11       +5     
  Lines         622      895     +273     
==========================================
+ Hits          574      835     +261     
- Misses         48       60      +12     
Flag Coverage Δ
unittests 93.29% <95.78%> (+1.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.

@irgeek
Copy link
Author

irgeek commented Dec 29, 2023

The lint check is failing because ggshield complains about the API key.

Copy link
Collaborator

@agateau-gg agateau-gg left a comment

Choose a reason for hiding this comment

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

Wow, that's some huge work, thanks!

I made some remarks inline, but here are some more general ones:

I'd rather avoid too deep file hierarchies and make the following changes:

  • merge all incident_models code into an incident_models.py module, similar to what you did with source_models.py.
  • merge utils/tools.py into utils/init.py

I think an utils package should not contain model-specific code so I would move load_incident_response() to incident_models.py.

I am not fond of the _url param added to GGClient.request(). I understand this is required to support paging, but I'd rather not add such a parameter to py-gitguardian public API. Maybe you can take the bulk of the requests() method minus the endpoint-to-url code, move it to utils and have both GGClient.request() and code using paging to use it?

Some of the functions you added take a lot of optional arguments. You should make them keyword-only arguments.

@@ -5,6 +5,7 @@ verify_ssl = true

[packages]
pygitguardian = { editable = true, path = "." }
strenum = "*"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Adding StrEnum here is not required: non-dev dependencies only need to be in setup.py.

"typing-extensions",
"urllib3<2",
"strenum",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you pin StrEnum to >=0.4, <0.5 (even if you are very close to StrEnum maintainer 😉)?

Comment on lines +69 to +70
present = auto()
removed = auto()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you make these values upper-case, like the others?

Comment on lines +90 to +91
def __int__(self):
return self.id
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd rather not have such magic behavior, using .id is simple enough.



def count_not_none(seq: Sequence[Any]) -> int:
"""Count the number of None values in a sequence"""
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"""Count the number of None values in a sequence"""
"""Count the number of not-None values in a sequence"""


def ensure_mutually_exclusive(msg: str, *seq: Any) -> None:
"""
Ensure only one value in a sequence is None.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Ensure only one value in a sequence is None.
Ensure only one value in a sequence is not None.


def count_not_none(seq: Sequence[Any]) -> int:
"""Count the number of None values in a sequence"""
return sum(0 if v is None else 1 for v in seq)
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: can be slightly simplified:

Suggested change
return sum(0 if v is None else 1 for v in seq)
return sum(1 for v in seq if v is not None)

Comment on lines +40 to +45
type: str # TODO: Reserved word
full_name: str
health: SourceHealth = field(metadata={"by_value": True})
open_incidents_count: int # TODO: Type documented as "number" - what's the difference?
closed_incidents_count: int # TODO: Also "number"
visibility: str # TODO: Really? str
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are those TODO actionable? If not, better remove them.



@dataclass
class Match(Base, FromDictMixin):
Copy link
Collaborator

Choose a reason for hiding this comment

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

There is already a Match class in models, can we name this one OccurrenceMatch?

@agateau-gg
Copy link
Collaborator

Sorry I have to close this PR. It has not moved for several months now. Meanwhile incident support has just been added by #114.

@agateau-gg agateau-gg closed this Aug 28, 2024
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.

3 participants