Skip to content

Commit 2c95dd3

Browse files
authored
Merge pull request #370 from willcl-ark/non-mentioning-links
2 parents dde8899 + c03a0d7 commit 2c95dd3

6 files changed

+25
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ This action can be configured to authenticate with GitHub App Installation or Pe
154154
| `MAX_COMMENTS_EVAL` | False | 20 | Maximum number of comments per thread to evaluate for mentor stats |
155155
| `HEAVILY_INVOLVED_CUTOFF` | False | 3 | Cutoff after which a mentor's comments in one issue are no longer counted against their total score |
156156
| `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. |
157+
| `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. |
157158
| `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. |
158159

159160
## Further Documentation

config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def __init__(
6262
max_comments_eval: str,
6363
heavily_involved_cutoff: str,
6464
search_query: str,
65+
non_mentioning_links: bool,
6566
):
6667
self.gh_app_id = gh_app_id
6768
self.gh_app_installation_id = gh_app_installation_id
@@ -81,6 +82,7 @@ def __init__(
8182
self.max_comments_eval = max_comments_eval
8283
self.heavily_involved_cutoff = heavily_involved_cutoff
8384
self.search_query = search_query
85+
self.non_mentioning_links = non_mentioning_links
8486

8587
def __repr__(self):
8688
return (
@@ -103,6 +105,7 @@ def __repr__(self):
103105
f"{self.max_comments_eval},"
104106
f"{self.heavily_involved_cutoff},"
105107
f"{self.search_query}"
108+
f"{self.non_mentioning_links}"
106109
)
107110

108111

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

199203
return EnvVars(
200204
gh_app_id,
@@ -215,4 +219,5 @@ def get_env_vars(test: bool = False) -> EnvVars:
215219
max_comments_eval,
216220
heavily_involved_cutoff,
217221
search_query,
222+
non_mentioning_links,
218223
)

issue_metrics.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ def main():
306306
token = env_vars.gh_token
307307
ignore_users = env_vars.ignore_users
308308
hide_items_closed_count = env_vars.hide_items_closed_count
309+
non_mentioning_links = env_vars.non_mentioning_links
309310

310311
gh_app_id = env_vars.gh_app_id
311312
gh_app_installation_id = env_vars.gh_app_installation_id
@@ -414,6 +415,7 @@ def main():
414415
labels,
415416
search_query,
416417
hide_items_closed_count,
418+
non_mentioning_links,
417419
)
418420

419421
max_char_count = 65535

markdown_writer.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def write_to_markdown(
8585
search_query=None,
8686
hide_label_metrics=False,
8787
hide_items_closed_count=False,
88+
non_mentioning_links=False,
8889
) -> None:
8990
"""Write the issues with metrics to a markdown file.
9091
@@ -160,7 +161,13 @@ def write_to_markdown(
160161
# Replace any whitespace
161162
issue.title = issue.title.strip()
162163

163-
file.write(f"| " f"{issue.title} | " f"{issue.html_url} |")
164+
if non_mentioning_links:
165+
file.write(
166+
f"| {issue.title} | "
167+
f"{issue.html_url.replace('https://github.com', 'https://www.github.com')} |"
168+
)
169+
else:
170+
file.write(f"| {issue.title} | " f"{issue.html_url} |")
164171
if "Author" in columns:
165172
file.write(f" [{issue.author}](https://github.com/{issue.author}) |")
166173
if "Time to first response" in columns:

test_config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ def test_get_env_vars_with_github_app(self):
126126
"20",
127127
"3",
128128
SEARCH_QUERY,
129+
False,
129130
)
130131
result = get_env_vars(True)
131132
self.assertEqual(str(result), str(expected_result))
@@ -171,6 +172,7 @@ def test_get_env_vars_with_token(self):
171172
"20",
172173
"3",
173174
SEARCH_QUERY,
175+
False,
174176
)
175177
result = get_env_vars(True)
176178
self.assertEqual(str(result), str(expected_result))
@@ -250,6 +252,7 @@ def test_get_env_vars_optional_values(self):
250252
20,
251253
3,
252254
SEARCH_QUERY,
255+
False,
253256
)
254257
result = get_env_vars(True)
255258
self.assertEqual(str(result), str(expected_result))
@@ -286,6 +289,7 @@ def test_get_env_vars_optionals_are_defaulted(self):
286289
"20",
287290
"3",
288291
SEARCH_QUERY,
292+
False,
289293
)
290294
result = get_env_vars(True)
291295
self.assertEqual(str(result), str(expected_result))

test_markdown_writer.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,11 @@ def test_write_to_markdown_no_issues(self):
254254
"HIDE_TIME_TO_CLOSE": "True",
255255
"HIDE_TIME_TO_ANSWER": "True",
256256
"HIDE_LABEL_METRICS": "True",
257+
"NON_MENTIONING_LINKS": "True",
257258
},
258259
)
259260
class TestWriteToMarkdownWithEnv(unittest.TestCase):
260-
"""Test the write_to_markdown function with the HIDE* environment variables set."""
261+
"""Test the write_to_markdown function with the HIDE* and NON_MENTIONING_LINKS environment variables set."""
261262

262263
def test_writes_markdown_file_with_non_hidden_columns_only(self):
263264
"""
@@ -314,6 +315,7 @@ def test_writes_markdown_file_with_non_hidden_columns_only(self):
314315
search_query="repo:user/repo is:issue",
315316
hide_label_metrics=True,
316317
hide_items_closed_count=True,
318+
non_mentioning_links=True,
317319
)
318320

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

0 commit comments

Comments
 (0)