Repository: twisted/towncrier

Issue:
Leading zeros in issue-numbers are not stripped
If the issue-number in the newsfragment-file has leading zeros, these are kept when printing the issue-number: A file named `0020.feature.txt` will result into the entry `- blablabla (#0020)`.

I would expect leading zeros to be removed the example above to result into the entry `- blablabla (#20)`.

Discussion:
codecov-io: # [Codecov](https://codecov.io/gh/twisted/towncrier/pull/278?src=pr&el=h1) Report
> Merging [#278](https://codecov.io/gh/twisted/towncrier/pull/278?src=pr&el=desc) into [master](https://codecov.io/gh/twisted/towncrier/commit/5c431028a3b699c74b162014e907272cbea8ac81?el=desc) will **increase** coverage by `0.16%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/twisted/towncrier/pull/278/graphs/tree.svg?width=650&height=150&src=pr&token=9npndnog2E)](https://codecov.io/gh/twisted/towncrier/pull/278?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #278      +/-   ##
==========================================
+ Coverage   89.49%   89.66%   +0.16%     
==========================================
  Files          11       11              
  Lines         438      445       +7     
  Branches       87       87              
==========================================
+ Hits          392      399       +7     
  Misses         25       25              
  Partials       21       21              
```


| [Impacted Files](https://codecov.io/gh/twisted/towncrier/pull/278?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/towncrier/\_builder.py](https://codecov.io/gh/twisted/towncrier/pull/278/diff?src=pr&el=tree#diff-c3JjL3Rvd25jcmllci9fYnVpbGRlci5weQ==) | `93.84% <100.00%> (+0.35%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/twisted/towncrier/pull/278?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/twisted/towncrier/pull/278?src=pr&el=footer). Last update [5c43102...3b42c98](https://codecov.io/gh/twisted/towncrier/pull/278?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/src/towncrier/_builder.py b/src/towncrier/_builder.py
index 6135df8..2a8f0b2 100644
--- a/src/towncrier/_builder.py
+++ b/src/towncrier/_builder.py
@@ -11,6 +11,15 @@ from collections import OrderedDict
 from jinja2 import Template
 
 
+def strip_if_integer_string(s):
+    try:
+        i = int(s)
+    except ValueError:
+        return s
+
+    return str(i)
+
+
 # Returns ticket, category and counter or (None, None, None) if the basename
 # could not be parsed or doesn't contain a valid category.
 def parse_newfragment_basename(basename, definitions):
@@ -21,6 +30,7 @@ def parse_newfragment_basename(basename, definitions):
         return invalid
     if len(parts) == 2:
         ticket, category = parts
+        ticket = strip_if_integer_string(ticket)
         return (ticket, category, 0) if category in definitions else invalid
 
     # There are at least 3 parts. Search for a valid category from the second
@@ -35,7 +45,7 @@ def parse_newfragment_basename(basename, definitions):
             # NOTE: This allows news fragment names like fix-1.2.3.feature or
             # something-cool.feature.ext for projects that don't use ticket
             # numbers in news fragment names.
-            ticket = parts[i-1]
+            ticket = strip_if_integer_string(parts[i-1])
             counter = 0
             # Use the following part as the counter if it exists and is a valid
             # digit.
diff --git a/src/towncrier/newsfragments/126.feature b/src/towncrier/newsfragments/126.feature
new file mode 100644
index 0000000..be6e633
--- /dev/null
+++ b/src/towncrier/newsfragments/126.feature
@@ -0,0 +1,1 @@
+Ticket number from file names will be stripped down to avoid ticket links such as ``#007``.
\ No newline at end of file


Test patch:
diff --git a/src/towncrier/test/test_builder.py b/src/towncrier/test/test_builder.py
index e6d0ed0..7f48a2e 100644
--- a/src/towncrier/test/test_builder.py
+++ b/src/towncrier/test/test_builder.py
@@ -66,3 +66,18 @@ class TestParseNewsfragmentBasename(TestCase):
             parse_newfragment_basename("baz.1.2.feature.3", ["feature"]),
             ("2", "feature", 3),
         )
+
+    def test_strip(self):
+        """Leading spaces and subsequent leading zeros are stripped
+        when parsing newsfragment names into ticket numbers etc.
+        """
+        self.assertEqual(
+            parse_newfragment_basename("  007.feature", ["feature"]),
+            ("7", "feature", 0)
+        )
+
+    def test_strip_with_counter(self):
+        self.assertEqual(
+            parse_newfragment_basename("  007.feature.3", ["feature"]),
+            ("7", "feature", 3)
+        )