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

Adds jira wrapper API #31

Merged
merged 4 commits into from
Jan 11, 2024
Merged

Adds jira wrapper API #31

merged 4 commits into from
Jan 11, 2024

Conversation

schuylermartin45
Copy link
Collaborator

  • This API manages the API token in the "standard" packaging utils way
    • This class follows a singleton design, like the GitHub API wrapper
    • Access to the underlying object is restricted through use of a callback. This is intended to help with some future thread-safety goals and to reduce the number of constructions and authorization requests.
  • Backports some of the new ideas to the GitHub API wrapper
  • Adds unit tests. The GitHub and Jira APIs now have some amount of mocked-out unit testing to back them

- This API manages the API token in the "standard" packaging utils way
  - This class follows a singleton design, like the GitHub API wrapper
  - Access to the underlying object is restricted through use of a callback.
    This is intended to help with some future thread-safety goals and to reduce
    the number of constructions and authorization requests.
- Backports some of the new ideas to the GitHub API wrapper
- Adds unit tests. The GitHub and Jira APIs now have some amount of mocked-out
  unit testing to back them
anaconda_packaging_utils/api/github_api.py Outdated Show resolved Hide resolved
anaconda_packaging_utils/api/github_api.py Outdated Show resolved Hide resolved
anaconda_packaging_utils/api/jira_api.py Outdated Show resolved Hide resolved
anaconda_packaging_utils/api/jira_api.py Outdated Show resolved Hide resolved

class JiraApi:
"""
Singleton wrapper to the Python Jira project. This "ensures" that we only construct and authenticate the underlying

Choose a reason for hiding this comment

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

I hate singletons so much as they holding internal object state with itself, have you consider using factory pattern instead ?
They are perceived often as anti pattern, see https://medium.com/aia-sg-techblog/why-singleton-pattern-is-considered-as-anti-design-pattern-c81dd8b7e757

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I guess I was trying to minimize the number of auth calls and object constructions. I think the only state that should remain the same in these APIs is the authorization state, which I think we want for our tools.

Both of these should be making stateless HTTP REST calls under the hood. So I think the Singleton pattern makes a lot of sense here. But let me know if you have specific concerns.

Choose a reason for hiding this comment

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

The problem with singleton can start being apparent when you do tests, you returning JIRA object which would hold its state across different test cases, if you call any stateful method on JIRA object the result could be observer in follow up tests, which could break the 1st rule that the tests should be run independent from each other. The solution for ( if you still want to use singleton ) is to have a wrapper singleton in your test code which would be able to reset the underlying instance each time new test is run

anaconda_packaging_utils/api/jira_api.py Outdated Show resolved Hide resolved
anaconda_packaging_utils/api/jira_api.py Outdated Show resolved Hide resolved
for this to be able to be called.
:returns: Authenticated instance of the underlying JIRA API
"""
return JiraApi.__jira[0]

Choose a reason for hiding this comment

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

not thread safe with singleton initialization but probably not mean to be thread safe

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

JC and I briefly talked about this. My initial callback mechanism I just redacted could have leant itself to being more thread safe. That being said, it's unclear (from the small amount of research I've done) if the underlying JIRA API or the GitHub API are threadsafe anyways.

Copy link

@M-Waszkiewicz-Anaconda M-Waszkiewicz-Anaconda left a comment

Choose a reason for hiding this comment

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

LGTM

@schuylermartin45 schuylermartin45 merged commit 8a70b2c into main Jan 11, 2024
3 checks passed
@schuylermartin45 schuylermartin45 deleted the smartin_jira_api branch January 11, 2024 13:58
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