|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +import tokenize |
| 4 | + |
| 5 | +from pydocstringformatter._formatting import Formatter |
| 6 | +from pydocstringformatter._utils.file_diference import compare_formatters |
| 7 | + |
| 8 | + |
| 9 | +def create_gh_issue_template( |
| 10 | + token: tokenize.TokenInfo, formatters: dict[str, Formatter], filename: str |
| 11 | +) -> str: |
| 12 | + """Make a template for a GitHub issue. |
| 13 | +
|
| 14 | + Args: |
| 15 | + token: The token that caused the issue. |
| 16 | + formatters: The formatters that caused the issue. |
| 17 | + filename: The filename of the file that caused the issue. |
| 18 | + """ |
| 19 | + formatter_names = list(formatters) |
| 20 | + msg = "" |
| 21 | + if len(formatter_names) > 2: |
| 22 | + msg = f""" |
| 23 | +Conflicting formatters: {", ".join(formatters)} |
| 24 | +""" |
| 25 | + diff = f"Diff too intricate to compute for {len(formatter_names)} formatters." |
| 26 | + else: |
| 27 | + if len(formatter_names) == 2: |
| 28 | + msg = f""" |
| 29 | +Conflicting formatters: {" and ".join(formatter_names)} |
| 30 | +These formatters conflict with each other for: |
| 31 | +
|
| 32 | +```python |
| 33 | +{token.string} |
| 34 | +``` |
| 35 | +""" |
| 36 | + formatter_1 = formatters[formatter_names[0]] |
| 37 | + formatter_2 = formatters[formatter_names[1]] |
| 38 | + else: |
| 39 | + msg = f""" |
| 40 | +Formatter: {formatter_names[0]} |
| 41 | +This formatter is not able to make stable changes for: |
| 42 | +
|
| 43 | +```python |
| 44 | +{token.string} |
| 45 | +``` |
| 46 | +""" |
| 47 | + formatter_1 = formatters[formatter_names[0]] |
| 48 | + formatter_2 = formatter_1 |
| 49 | + |
| 50 | + diff = compare_formatters( |
| 51 | + token, |
| 52 | + formatter_1, |
| 53 | + formatter_2, |
| 54 | + title_extra=str(filename), |
| 55 | + ) |
| 56 | + |
| 57 | + out = f""" |
| 58 | +Unfortunately an error occurred while formatting a docstring. |
| 59 | +Please help us fix this bug by opening an issue at: |
| 60 | +https://github.com/DanielNoord/pydocstringformatter/issues/new |
| 61 | +
|
| 62 | +{"-" * 80} |
| 63 | +
|
| 64 | +You can use the following template when you open the issue: |
| 65 | +
|
| 66 | +# Description: |
| 67 | +
|
| 68 | +{msg} |
| 69 | +
|
| 70 | +# Diff: |
| 71 | +
|
| 72 | +```diff |
| 73 | +{diff} |
| 74 | +``` |
| 75 | +
|
| 76 | +""" |
| 77 | + |
| 78 | + return out |
0 commit comments