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

Implement getter of SHA for branches #668

Merged

Conversation

mfocko
Copy link
Member

@mfocko mfocko commented Jan 3, 2022

Required for passing commit hashes from service to testing farm for
merging of tests that are run on their side or usage in tmt preparation.

Signed-off-by: Matej Focko [email protected]

TODO:

  • tests
  • consider shared method get_sha_from(branch=None, tag=None) -> Optional[str]

We have introduced a new function into ogr that allows you to get commit SHA of the HEAD of the branch.

Sorry, something went wrong.

@mfocko mfocko added kind/feature New feature or a request for enhancement. area/github Related to GitHub implementation. area/gitlab Related to GitLab implementation. pagure Related to Pagure implementation. has-release-notes labels Jan 3, 2022
@softwarefactory-project-zuul
Copy link
Contributor

Build succeeded.

@mfocko
Copy link
Member Author

mfocko commented Jan 3, 2022

@csomh @TomasTomecek @lachmanfrantisek I would also like some opinion on the TODO and that is changing interface to: get_sha_from(branch=None, tag=None) which seems (at least to me) like a „Python-like“ API, but the implementation looks much worse:

# BaseProject
def get_sha_from(branch: str = None, tag: str = None) -> Optional[str]:
  # check if provided «exactly» one of ‹branch› or ‹tag›
  #   throw exception if not
  return None

# projects
def get_sha_from(branch: str = None, tag: str = None) -> Optional[str]:
  super().get_sha_from(branch=branch, tag=tag)

  if branch:
    # code for SHA of branch
    pass

  # code for SHA of tag
  return None

On the bright side, I like the idea of only one function, doing only one thing (that is getting the SHA, regardless whether of tag or branch). On the other side, I don't like the way it has to be implemented, SRP of it and I also feel like factoring out getting SHA of branch and tag, which basically means we could end up with 3 functions:

get_sha_from(branch=None, tag=None) # this one calls internally the other 2
get_sha_from_tag(tag)
get_sha_from_branch(branch)

↑ this also changes the TODO from «changing» to «extending» interface

And my judgement might be also affected by „indentation hell“, because both Git(Hub|Lab) throw an exception if the branch doesn't exist, so it looks meh even without being nested in another block…

@softwarefactory-project-zuul
Copy link
Contributor

Build succeeded.

@csomh
Copy link
Contributor

csomh commented Jan 3, 2022

To me this seems like a syntactic nuance from a user point of view:

get_sha_from(branch="branch")
get_sha_from_branch("branch")
get_sha_from(tag="tag")
get_sha_from_tag("tag")

And I don't have the "more Pythonic"-feeling towards any of the above :-)

As you said get_sha_from() would complicate implementation (and now that I think about it, could be somewhat confusing for users: it's not obvious just by looking at the method signature if providing no or both arguments is a valid option or not), so I would argue against going that way.

ogr/abstract.py Outdated
# TODO: Consider ‹get_sha_from(branch=None, tag=None)›
def get_sha_from_branch(self, branch: str) -> Optional[str]:
Copy link
Member

Choose a reason for hiding this comment

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

I'd say having two separate methods for each is a better design :) get_sha_from sounds like it would be too complicated and prone to errors - also with modern editors you are immediately being offered a list methods so it's easier to pick one which has narrow scope

mfocko added 2 commits January 3, 2022 18:24

Unverified

This user has not yet uploaded their public signing key.
Required for passing commit hashes from service to testing farm for
merging of tests that are run on their side or usage in tmt preparation.

Signed-off-by: Matej Focko <[email protected]>

Unverified

This user has not yet uploaded their public signing key.
Signed-off-by: Matej Focko <[email protected]>
@mfocko mfocko force-pushed the get-sha-from-branch branch from 4633bb5 to 685904e Compare January 3, 2022 17:24
@mfocko
Copy link
Member Author

mfocko commented Jan 3, 2022

removed TODO from the code

@softwarefactory-project-zuul
Copy link
Contributor

Build succeeded.

@mfocko mfocko added the mergeit When set, zuul wil gate and merge the PR. label Jan 3, 2022
@softwarefactory-project-zuul
Copy link
Contributor

Build succeeded (gate pipeline).

@softwarefactory-project-zuul softwarefactory-project-zuul bot merged commit a8455da into packit:main Jan 3, 2022
@mfocko mfocko deleted the get-sha-from-branch branch March 6, 2022 01:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/github Related to GitHub implementation. area/gitlab Related to GitLab implementation. kind/feature New feature or a request for enhancement. mergeit When set, zuul wil gate and merge the PR. pagure Related to Pagure implementation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants