-
Notifications
You must be signed in to change notification settings - Fork 127
Refactor issue_key function to sort issues in a human-friendly way #608
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
2fe403a
Refactor issue_key function to sort issues in a human-friendly way
SmileyChris 8f1d692
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 88555d4
Rename newsfragment
SmileyChris 08e4281
Merge remote-tracking branch 'upstream/trunk' into Better-issue-sorting
SmileyChris 989ed4e
Small improvement to test to show how text with numeric issues are so…
SmileyChris 081af67
Update src/towncrier/_builder.py docstring grammar
SmileyChris b39dd8a
clarify new behaviour in newsfragment
SmileyChris 5931717
Add some docstrings/comments to tests
SmileyChris ed811ff
linelength fix
SmileyChris a189c9e
Clarify news fragments vs tickets
SmileyChris e5bdcb0
Consistent use of "issue" rather than "ticket"
SmileyChris 3c4c2ca
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 2b30cad
typo
SmileyChris debc575
Merge remote-tracking branch 'upstream/trunk' into Better-issue-sorting
SmileyChris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| Issues are now sorted by issue number even if they have non-digit characters. | ||
SmileyChris marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| For example:: | ||
|
|
||
| - some issue (gh-3, gh-10) | ||
| - another issue (gh-4) | ||
| - yet another issue (gh-11) | ||
|
|
||
| The sorting algorithm groups the issues first by non-text characters and then by number. | ||
SmileyChris marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,9 +1,11 @@ | ||||||
| # Copyright (c) Povilas Kanapickas, 2019 | ||||||
| # See LICENSE for details. | ||||||
|
|
||||||
| from textwrap import dedent | ||||||
|
|
||||||
| from twisted.trial.unittest import TestCase | ||||||
|
|
||||||
| from .._builder import parse_newfragment_basename | ||||||
| from .._builder import parse_newfragment_basename, render_fragments | ||||||
|
|
||||||
|
|
||||||
| class TestParseNewsfragmentBasename(TestCase): | ||||||
|
|
@@ -132,3 +134,73 @@ def test_orphan_all_digits(self): | |||||
| parse_newfragment_basename("+123.feature", ["feature"]), | ||||||
| ("+123", "feature", 0), | ||||||
| ) | ||||||
|
|
||||||
|
|
||||||
| class TestIssueOrdering(TestCase): | ||||||
SmileyChris marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
SmileyChris marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| """ | ||||||
| Tests to ensure that issues are ordered correctly in the output. | ||||||
|
|
||||||
| This tests both ordering of issues within a fragment and ordering of | ||||||
| fragments within a section. | ||||||
| """ | ||||||
|
|
||||||
| template = dedent( | ||||||
| """ | ||||||
| {% for section_name, category in sections.items() %} | ||||||
| {% if section_name %}# {{ section_name }}{% endif %} | ||||||
| {%- for category_name, issues in category.items() %} | ||||||
| ## {{ category_name }} | ||||||
| {% for issue, numbers in issues.items() %} | ||||||
| - {{ issue }}{% if numbers %} ({{ numbers|join(', ') }}){% endif %} | ||||||
|
|
||||||
| {% endfor %} | ||||||
| {% endfor -%} | ||||||
| {% endfor -%} | ||||||
| """ | ||||||
| ) | ||||||
|
|
||||||
| def render(self, fragments): | ||||||
| return render_fragments( | ||||||
| template=self.template, | ||||||
| issue_format=None, | ||||||
| fragments=fragments, | ||||||
| definitions={}, | ||||||
| underlines=[], | ||||||
| wrap=False, | ||||||
| versiondata={}, | ||||||
| ) | ||||||
|
|
||||||
| def test_ordering(self): | ||||||
| """ | ||||||
| Issues are ordered first by the non-text component, then by their number. | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess here "issues" means "news fragments"
Suggested change
|
||||||
|
|
||||||
| For backwards compatibility, issues with no number are grouped first and issues | ||||||
| which are only a number are grouped last. | ||||||
|
|
||||||
| Orhpan issues are always last, sorted by their fragment text. | ||||||
SmileyChris marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| """ | ||||||
| output = self.render( | ||||||
| { | ||||||
| "": { | ||||||
| "feature": { | ||||||
| "Added Cheese": ["10", "gh-25", "gh-3", "4"], | ||||||
| "Added Fish": [], | ||||||
| "Added Bread": [], | ||||||
| "Added Milk": ["gh-1"], | ||||||
| "Added Eggs": ["gh-2", "random"], | ||||||
| } | ||||||
| } | ||||||
| }, | ||||||
| ) | ||||||
| # "Eggs" are first because they have an issue with no number, and the first | ||||||
| # issue for each fragment is what is used for sorting the overall list. | ||||||
| assert output == dedent( | ||||||
| """ | ||||||
| ## feature | ||||||
| - Added Eggs (random, gh-2) | ||||||
| - Added Milk (gh-1) | ||||||
| - Added Cheese (gh-3, gh-25, #4, #10) | ||||||
| - Added Bread | ||||||
| - Added Fish | ||||||
| """ | ||||||
| ) | ||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.