Skip to content

Commit

Permalink
Merge pull request #370 from willcl-ark/non-mentioning-links
Browse files Browse the repository at this point in the history
  • Loading branch information
jmeridth authored Sep 19, 2024
2 parents dde8899 + c03a0d7 commit 2c95dd3
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ This action can be configured to authenticate with GitHub App Installation or Pe
| `MAX_COMMENTS_EVAL` | False | 20 | Maximum number of comments per thread to evaluate for mentor stats |
| `HEAVILY_INVOLVED_CUTOFF` | False | 3 | Cutoff after which a mentor's comments in one issue are no longer counted against their total score |
| `LABELS_TO_MEASURE` | False | `""` | A comma separated list of labels to measure how much time the label is applied. If not provided, no labels durations will be measured. Not compatible with discussions at this time. |
| `NON_MENTIONING_LINKS` | False | False | If set to `true`, will use non-mentioning GitHub links to avoid linking to the generated issue from the source repository. Links of the form `https://www.github.com` will be used. |
| `SEARCH_QUERY` | True | `""` | The query by which you can filter issues/PRs which must contain a `repo:`, `org:`, `owner:`, or a `user:` entry. For discussions, include `type:discussions` in the query. |

## Further Documentation
Expand Down
5 changes: 5 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def __init__(
max_comments_eval: str,
heavily_involved_cutoff: str,
search_query: str,
non_mentioning_links: bool,
):
self.gh_app_id = gh_app_id
self.gh_app_installation_id = gh_app_installation_id
Expand All @@ -81,6 +82,7 @@ def __init__(
self.max_comments_eval = max_comments_eval
self.heavily_involved_cutoff = heavily_involved_cutoff
self.search_query = search_query
self.non_mentioning_links = non_mentioning_links

def __repr__(self):
return (
Expand All @@ -103,6 +105,7 @@ def __repr__(self):
f"{self.max_comments_eval},"
f"{self.heavily_involved_cutoff},"
f"{self.search_query}"
f"{self.non_mentioning_links}"
)


Expand Down Expand Up @@ -195,6 +198,7 @@ def get_env_vars(test: bool = False) -> EnvVars:
min_mentor_comments = os.getenv("MIN_MENTOR_COMMENTS", "10")
max_comments_eval = os.getenv("MAX_COMMENTS_EVAL", "20")
heavily_involved_cutoff = os.getenv("HEAVILY_INVOLVED_CUTOFF", "3")
non_mentioning_links = get_bool_env_var("NON_MENTIONING_LINKS", False)

return EnvVars(
gh_app_id,
Expand All @@ -215,4 +219,5 @@ def get_env_vars(test: bool = False) -> EnvVars:
max_comments_eval,
heavily_involved_cutoff,
search_query,
non_mentioning_links,
)
2 changes: 2 additions & 0 deletions issue_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ def main():
token = env_vars.gh_token
ignore_users = env_vars.ignore_users
hide_items_closed_count = env_vars.hide_items_closed_count
non_mentioning_links = env_vars.non_mentioning_links

gh_app_id = env_vars.gh_app_id
gh_app_installation_id = env_vars.gh_app_installation_id
Expand Down Expand Up @@ -414,6 +415,7 @@ def main():
labels,
search_query,
hide_items_closed_count,
non_mentioning_links,
)

max_char_count = 65535
Expand Down
9 changes: 8 additions & 1 deletion markdown_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def write_to_markdown(
search_query=None,
hide_label_metrics=False,
hide_items_closed_count=False,
non_mentioning_links=False,
) -> None:
"""Write the issues with metrics to a markdown file.
Expand Down Expand Up @@ -160,7 +161,13 @@ def write_to_markdown(
# Replace any whitespace
issue.title = issue.title.strip()

file.write(f"| " f"{issue.title} | " f"{issue.html_url} |")
if non_mentioning_links:
file.write(
f"| {issue.title} | "
f"{issue.html_url.replace('https://github.com', 'https://www.github.com')} |"
)
else:
file.write(f"| {issue.title} | " f"{issue.html_url} |")
if "Author" in columns:
file.write(f" [{issue.author}](https://github.com/{issue.author}) |")
if "Time to first response" in columns:
Expand Down
4 changes: 4 additions & 0 deletions test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def test_get_env_vars_with_github_app(self):
"20",
"3",
SEARCH_QUERY,
False,
)
result = get_env_vars(True)
self.assertEqual(str(result), str(expected_result))
Expand Down Expand Up @@ -171,6 +172,7 @@ def test_get_env_vars_with_token(self):
"20",
"3",
SEARCH_QUERY,
False,
)
result = get_env_vars(True)
self.assertEqual(str(result), str(expected_result))
Expand Down Expand Up @@ -250,6 +252,7 @@ def test_get_env_vars_optional_values(self):
20,
3,
SEARCH_QUERY,
False,
)
result = get_env_vars(True)
self.assertEqual(str(result), str(expected_result))
Expand Down Expand Up @@ -286,6 +289,7 @@ def test_get_env_vars_optionals_are_defaulted(self):
"20",
"3",
SEARCH_QUERY,
False,
)
result = get_env_vars(True)
self.assertEqual(str(result), str(expected_result))
Expand Down
8 changes: 5 additions & 3 deletions test_markdown_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,11 @@ def test_write_to_markdown_no_issues(self):
"HIDE_TIME_TO_CLOSE": "True",
"HIDE_TIME_TO_ANSWER": "True",
"HIDE_LABEL_METRICS": "True",
"NON_MENTIONING_LINKS": "True",
},
)
class TestWriteToMarkdownWithEnv(unittest.TestCase):
"""Test the write_to_markdown function with the HIDE* environment variables set."""
"""Test the write_to_markdown function with the HIDE* and NON_MENTIONING_LINKS environment variables set."""

def test_writes_markdown_file_with_non_hidden_columns_only(self):
"""
Expand Down Expand Up @@ -314,6 +315,7 @@ def test_writes_markdown_file_with_non_hidden_columns_only(self):
search_query="repo:user/repo is:issue",
hide_label_metrics=True,
hide_items_closed_count=True,
non_mentioning_links=True,
)

# Check that the function writes the correct markdown file
Expand All @@ -328,8 +330,8 @@ def test_writes_markdown_file_with_non_hidden_columns_only(self):
"| Total number of items created | 2 |\n\n"
"| Title | URL | Author |\n"
"| --- | --- | --- |\n"
"| Issue 1 | https://github.com/user/repo/issues/1 | [alice](https://github.com/alice) |\n"
"| Issue 2 | https://github.com/user/repo/issues/2 | [bob](https://github.com/bob) |\n\n"
"| Issue 1 | https://www.github.com/user/repo/issues/1 | [alice](https://github.com/alice) |\n"
"| Issue 2 | https://www.github.com/user/repo/issues/2 | [bob](https://github.com/bob) |\n\n"
"_This report was generated with the [Issue Metrics Action](https://github.com/github/issue-metrics)_\n"
"Search query used to find these items: `repo:user/repo is:issue`\n"
)
Expand Down

0 comments on commit 2c95dd3

Please sign in to comment.