Skip to content

Commit cf57ec0

Browse files
committed
Add dry-run option to run without sending request
I've added a dry-run option that allows you to run the application without actually sending the embed to Discord. This can be handy for debugging or testing the application.
1 parent d1cb23c commit cf57ec0

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

github_status_embed/__main__.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,27 @@
4545
for argument, configuration in action_specs["inputs"].items():
4646
parser.add_argument(argument, help=configuration["description"])
4747

48-
parser.add_argument("--debug", help="enable debug logging", action="store_true", dest="debug")
48+
parser.add_argument(
49+
"--debug",
50+
help="enable debug logging",
51+
action="store_true",
52+
dest="debug",
53+
)
54+
parser.add_argument(
55+
"--dry-run",
56+
help="do not send webhook request",
57+
action="store_true",
58+
dest="dry_run"
59+
)
4960

5061

5162
if __name__ == "__main__":
5263
arguments = vars(parser.parse_args())
5364
debug = arguments.pop('debug')
65+
dry_run = arguments.pop('dry_run')
5466

5567
# Set up logging and make sure to mask the webhook_token in log records
56-
level = logging.DEBUG if debug else logging.ERROR
68+
level = logging.DEBUG if debug else logging.WARNING
5769
setup_logging(level, masked_values=[arguments['webhook_token']])
5870

5971
# If debug logging is requested, enable it for our application only
@@ -67,7 +79,7 @@
6779
pull_request = PullRequest.from_arguments(arguments)
6880

6981
# Send webhook
70-
success = send_webhook(workflow, webhook, pull_request)
82+
success = send_webhook(workflow, webhook, pull_request, dry_run)
7183

7284
if not success:
7385
log.debug("Exiting with status code 1")

github_status_embed/webhook.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ def send_webhook(
113113
workflow: types.Workflow,
114114
webhook: types.Webhook,
115115
pull_request: typing.Optional[types.PullRequest],
116+
dry_run: bool = False,
116117
) -> bool:
117118
"""Send an embed to specified webhook."""
118119
if pull_request is None:
@@ -124,6 +125,9 @@ def send_webhook(
124125

125126
log.debug("Generated payload:\n%s", json.dumps(payload, indent=4))
126127

128+
if dry_run:
129+
return True
130+
127131
response = requests.post(webhook.url, json=payload)
128132

129133
log.debug(f"Response: [{response.status_code}] {response.reason}")

0 commit comments

Comments
 (0)