#44 Improve notes
Closed 2 months ago by lruzicka. Opened 2 months ago by lruzicka.

file modified
+15 -9
@@ -885,18 +885,24 @@ 

          return (False, 'too many errors')

  

  def karma_info(karma, colorize=True):

-     """ Takes a list of various karma values, counts single values and returns

-     an info string that will be printed out when the info is requested. """

+     """Takes a list of various karma values, counts single values and returns

+     an info string that will be printed out when the info is requested."""

      neutral = karma.count(0)

      negative = karma.count(-1)

-     neline = color(f"{neutral} neutral", "orange_1", colorize)

-     ngline = color(f"{negative} negative", "red", colorize)

- 

-     # Only return info if there actually is a karma.

+     # Create empty strings for both neutral and negative karma

+     # and only fill them if any of them is bigger than 0, i.e.

+     # there indeed is some karma.

+     neline = ngline = connect = info = ""

+     if neutral > 0:

+         neline = color(f"{neutral} neutral", "orange_1", colorize)

+     if negative > 0:

+         ngline = color(f"{negative} negative", "red", colorize)

+     if neutral > 0 and negative > 0:

+         connect = "and "

+ 

+     # We now return the note only if there is something.

      if neutral > 0 or negative > 0:

-         info = f"\n  Note: This update has {neline} and {ngline} karma. Consider a review.\n"

-     else:

-         info = ""

+         info = f"\n  Note: This update has {neline}{connect}{ngline} karma. Consider a review.\n"

      return info

  

  def color(text, colorname, colorize=True):

This PR changes the behaviour to show the notes. Currently,
the note was shown anytime there was neutral and negative karma,
and it always showed both neutral and negative karma. Therefore,
we had situations with "there is 1 neutral and 0 negative" where
the red negative statement would be misleading to the user.

Now, we only show what is really there, so no negative karma
is mentioned when the note only shows the neutral karma, and
vice-versa.

This PR fixes https://pagure.io/fedora-easy-karma/issue/43.

Metadata Update from @lruzicka:
- Request assigned

2 months ago

Thanks, I'm going to review it. Just a note, if you want the PR to automatically close a ticket, add it into the commit message in this form:

Fixes: <url or #number>

Freeform will not work ;-)

This can nicely be all initialized as:

neline = ngline = connect = info = ""

I have to say I'd a bit confused by the ending space. Can't this be written easier this way? (parts of code skipped)

neline = color(f"{neutral} neutral", "orange_1", colorize)
ngline = color(f"{negative} negative", "red", colorize)
connect = " and "
info = f"\n  Note: This update has {neline}{connect}{ngline} karma. Consider a review.\n"

LGTM. Consider the improvements above, if you prefer. Then please merge to master. (You might also want to adjust the commit message to autoclose the ticket, as described above).

Thanks a lot for your work!

I have to say I'd a bit confused by the ending space. Can't this be written easier this way? (parts of code skipped)
neline = color(f"{neutral} neutral", "orange_1", colorize) ngline = color(f"{negative} negative", "red", colorize) connect = " and " info = f"\n Note: This update has {neline}{connect}{ngline} karma. Consider a review.\n"

Yeah, I over-engineered this. This would work, too.

rebased onto 3718830

2 months ago

OMG, I merged this via CLI and now I am stuck with a PR that only can be closed without merging. I am closing this but it is merged.

Pull-Request has been closed by lruzicka

2 months ago

Yeah, I over-engineered this. This would work, too.

But I think you made a mistake. Line 901 is connect = "and " while I think it should be connect = " and ".

OMG, I merged this via CLI and now I am stuck with a PR that only can be closed without merging. I am closing this but it is merged.

That's normal (in Pagure ;-) ). Next time, you can add this to the commit message as well:

Merges: https://pagure.io/fedora-easy-karma/pull-request/44

and it will also close this ticket as merged. Or close it manually (as closed), it really doesn't matter.

Yeah, I over-engineered this. This would work, too.

But I think you made a mistake. Line 901 is connect = "and " while I think it should be connect = " and ".

OMG, I merged this via CLI and now I am stuck with a PR that only can be closed without merging. I am closing this but it is merged.

That's normal (in Pagure ;-) ). Next time, you can add this to the commit message as well:
Merges: https://pagure.io/fedora-easy-karma/pull-request/44
and it will also close this ticket as merged. Or close it manually (as closed), it really doesn't matter.

Gosh. I will fix it with another commit then.

Metadata