Skip to content

Commit b51edd8

Browse files
committed
Refactor GitHub Actions shield functions, and work towards new shields in shields block.
1 parent e84c2d3 commit b51edd8

File tree

3 files changed

+82
-44
lines changed

3 files changed

+82
-44
lines changed

repo_helper/_docs_shields.py

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"make_docs_typing_shield",
6868
"make_docs_pre_commit_shield",
6969
"make_docs_pre_commit_ci_shield",
70+
"make_docs_actions_shield",
7071
]
7172

7273

@@ -101,26 +102,45 @@ def make_docs_docs_check_shield(repo_name: str, username: str) -> str:
101102
:alt: Docs Check Status"""
102103

103104

104-
def make_docs_actions_linux_shield(
105+
def make_docs_actions_shield(
105106
repo_name: str,
106107
username: str,
108+
name: str,
109+
alt: str,
107110
) -> str:
108111
"""
109112
Create a shield to indicate the status of the tests on Linux.
110113
111114
:param repo_name: The name of the repository.
112115
:param username: The username of the GitHub account that owns the repository.
116+
:param name: The name of the workflow.
117+
:param alt: Alternative text for the image when it cannot be shown.
113118
114119
:return: The shield.
120+
121+
.. versionadded:: 2020.12.16
115122
"""
116123

117-
return """\
124+
return f"""\
118125
.. actions-shield::
119-
:workflow: Linux
120-
:alt: Linux Test Status"""
126+
:workflow: {name}
127+
:alt: {alt}"""
121128

122129

123-
make_docs_actions_linux_shield = make_docs_actions_linux_shield
130+
def make_docs_actions_linux_shield(
131+
repo_name: str,
132+
username: str,
133+
) -> str:
134+
"""
135+
Create a shield to indicate the status of the tests on Linux.
136+
137+
:param repo_name: The name of the repository.
138+
:param username: The username of the GitHub account that owns the repository.
139+
140+
:return: The shield.
141+
"""
142+
143+
return make_docs_actions_shield(repo_name, username, "Linux", "Linux Test Status")
124144

125145

126146
def make_docs_actions_windows_shield(repo_name: str, username: str) -> str:
@@ -133,10 +153,7 @@ def make_docs_actions_windows_shield(repo_name: str, username: str) -> str:
133153
:return: The shield.
134154
"""
135155

136-
return """\
137-
.. actions-shield::
138-
:workflow: Windows
139-
:alt: Windows Test Status"""
156+
return make_docs_actions_shield(repo_name, username, "Windows", "Windows Test Status")
140157

141158

142159
def make_docs_actions_macos_shield(repo_name: str, username: str) -> str:
@@ -149,10 +166,7 @@ def make_docs_actions_macos_shield(repo_name: str, username: str) -> str:
149166
:return: The shield.
150167
"""
151168

152-
return """\
153-
.. actions-shield::
154-
:workflow: macOS
155-
:alt: macOS Test Status"""
169+
return make_docs_actions_shield(repo_name, username, "macOS", "macOS Test Status")
156170

157171

158172
def make_docs_requires_shield(repo_name: str, username: str) -> str:

repo_helper/blocks/__init__.py

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@
3636

3737
# this package
3838
from repo_helper._docs_shields import (
39-
make_docs_actions_linux_shield,
40-
make_docs_actions_macos_shield,
41-
make_docs_actions_windows_shield,
39+
make_docs_actions_shield,
4240
make_docs_activity_shield,
4341
make_docs_codefactor_shield,
4442
make_docs_conda_platform_shield,
@@ -62,9 +60,7 @@
6260
make_docs_wheel_shield
6361
)
6462
from repo_helper.shields import (
65-
make_actions_linux_shield,
66-
make_actions_macos_shield,
67-
make_actions_windows_shield,
63+
make_actions_shield,
6864
make_activity_shield,
6965
make_codefactor_shield,
7066
make_conda_platform_shield,
@@ -394,9 +390,7 @@ def set_readme_mode(self) -> None:
394390
Create shields for insertion into ``README.rst``.
395391
"""
396392

397-
self.make_actions_linux_shield = make_actions_linux_shield
398-
self.make_actions_macos_shield = make_actions_macos_shield
399-
self.make_actions_windows_shield = make_actions_windows_shield
393+
self.make_actions_shield = make_actions_shield
400394
self.make_activity_shield = make_activity_shield
401395
self.make_codefactor_shield = make_codefactor_shield
402396
self.make_conda_platform_shield = make_conda_platform_shield
@@ -424,9 +418,7 @@ def set_docs_mode(self) -> None:
424418
Create shields for insertion into Sphinx documentation.
425419
"""
426420

427-
self.make_actions_linux_shield = make_docs_actions_linux_shield
428-
self.make_actions_macos_shield = make_docs_actions_macos_shield
429-
self.make_actions_windows_shield = make_docs_actions_windows_shield
421+
self.make_actions_shield = make_docs_actions_shield
430422
self.make_activity_shield = make_docs_activity_shield
431423
self.make_codefactor_shield = make_docs_codefactor_shield
432424
self.make_conda_platform_shield = make_docs_conda_platform_shield
@@ -482,6 +474,13 @@ def make(self) -> str:
482474
substitutions["license"] = self.make_license_shield(repo_name, username)
483475
substitutions["language"] = self.make_language_shield(repo_name, username)
484476

477+
sections["QA"] = ["codefactor", "actions_macos"]
478+
substitutions["codefactor"] = self.make_codefactor_shield(repo_name, username)
479+
sections["QA"].append("actions_flake8")
480+
substitutions["actions_flake8"] = self.make_actions_shield(repo_name, username, "Flake8", "Flake8 Status")
481+
sections["QA"].append("actions_mypy")
482+
substitutions["actions_mypy"] = self.make_actions_shield(repo_name, username, "mypy", "mypy status")
483+
485484
if self.docs:
486485
sections["Docs"] = ["docs", "docs_check"]
487486
substitutions["docs"] = self.make_rtfd_shield(repo_name, self.docs_url)
@@ -491,22 +490,37 @@ def make(self) -> str:
491490

492491
if "Linux" in self.platforms:
493492
sections["Tests"].append("actions_linux")
494-
substitutions["actions_linux"] = self.make_actions_linux_shield(repo_name, username)
493+
substitutions["actions_linux"] = self.make_actions_shield(
494+
repo_name,
495+
username,
496+
"Linux",
497+
"Linux Test Status",
498+
)
495499
if "Windows" in self.platforms:
496500
sections["Tests"].append("actions_windows")
497-
substitutions["actions_windows"] = self.make_actions_windows_shield(repo_name, username)
501+
substitutions["actions_windows"] = self.make_actions_shield(
502+
repo_name,
503+
username,
504+
"Windows",
505+
"Windows Test Status",
506+
)
498507
if "macOS" in self.platforms:
499508
sections["Tests"].append("actions_macos")
500-
substitutions["actions_macos"] = self.make_actions_macos_shield(repo_name, username)
509+
substitutions["actions_macos"] = self.make_actions_shield(
510+
repo_name,
511+
username,
512+
"macOS",
513+
"macOS Test Status",
514+
)
501515

502516
if self.tests:
503517
sections["Tests"].append("coveralls")
504518
substitutions["coveralls"] = self.make_coveralls_shield(repo_name, username)
505519

506520
sections["Tests"].append("codefactor")
507-
substitutions["codefactor"] = self.make_codefactor_shield(repo_name, username)
508521

509522
if self.pre_commit:
523+
sections["QA"].append("pre_commit_ci")
510524
sections["Tests"].append("pre_commit_ci")
511525
substitutions["pre_commit_ci"] = self.make_pre_commit_ci_shield(repo_name, username)
512526

repo_helper/shields.py

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,9 @@
2525

2626
# stdlib
2727
import datetime
28+
import urllib.parse
2829
from typing import Union
2930

30-
# 3rd party
31-
from typing_extensions import Literal
32-
3331
__all__ = [
3432
"make_actions_linux_shield",
3533
"make_actions_macos_shield",
@@ -57,6 +55,7 @@
5755
"make_actions_linux_shield",
5856
"make_typing_shield",
5957
"make_wheel_shield",
58+
"make_actions_shield",
6059
]
6160

6261

@@ -94,20 +93,37 @@ def make_docs_check_shield(repo_name: str, username: str) -> str:
9493
:alt: Docs Check Status"""
9594

9695

97-
def make_actions_linux_shield(repo_name: str, username: str) -> str:
96+
def make_actions_shield(repo_name: str, username: str, name: str, alt: str) -> str:
9897
"""
9998
Create a shield to indicate the status of the tests on Linux.
10099
101100
:param repo_name: The name of the repository.
102101
:param username: The username of the GitHub account that owns the repository.
102+
:param name: The name of the workflow.
103+
:param alt: Alternative text for the image when it cannot be shown.
103104
104105
:return: The shield.
106+
107+
.. versionadded:: 2020.12.16
105108
"""
106109

107110
return f"""\
108-
.. image:: https://github.com/{username}/{repo_name}/workflows/Linux/badge.svg
109-
:target: https://github.com/{username}/{repo_name}/actions?query=workflow%3A%22Linux%22
110-
:alt: Linux Test Status"""
111+
.. image:: https://github.com/{username}/{repo_name}/workflows/{name}/badge.svg
112+
:target: https://github.com/{username}/{repo_name}/actions?query=workflow%3A%22{urllib.parse.quote(name)}%22
113+
:alt: {alt}"""
114+
115+
116+
def make_actions_linux_shield(repo_name: str, username: str) -> str:
117+
"""
118+
Create a shield to indicate the status of the tests on Linux.
119+
120+
:param repo_name: The name of the repository.
121+
:param username: The username of the GitHub account that owns the repository.
122+
123+
:return: The shield.
124+
"""
125+
126+
return make_actions_shield(repo_name, username, "Linux", "Linux Test Status")
111127

112128

113129
def make_actions_windows_shield(repo_name: str, username: str) -> str:
@@ -120,10 +136,7 @@ def make_actions_windows_shield(repo_name: str, username: str) -> str:
120136
:return: The shield.
121137
"""
122138

123-
return f"""\
124-
.. image:: https://github.com/{ username }/{ repo_name }/workflows/Windows/badge.svg
125-
:target: https://github.com/{ username }/{ repo_name }/actions?query=workflow%3A%22Windows%22
126-
:alt: Windows Test Status"""
139+
return make_actions_shield(repo_name, username, "Windows", "Windows Test Status")
127140

128141

129142
def make_actions_macos_shield(repo_name: str, username: str) -> str:
@@ -136,10 +149,7 @@ def make_actions_macos_shield(repo_name: str, username: str) -> str:
136149
:return: The shield.
137150
"""
138151

139-
return f"""\
140-
.. image:: https://github.com/{ username }/{ repo_name }/workflows/macOS/badge.svg
141-
:target: https://github.com/{ username }/{ repo_name }/actions?query=workflow%3A%22macOS%22
142-
:alt: macOS Test Status"""
152+
return make_actions_shield(repo_name, username, "macOS", "macOS Test Status")
143153

144154

145155
def make_requires_shield(repo_name: str, username: str) -> str:

0 commit comments

Comments
 (0)