Skip to content

Commit bdbb63d

Browse files
authored
chore: make the code more straightforward (#31)
1 parent 5e833f2 commit bdbb63d

File tree

3 files changed

+65
-30
lines changed

3 files changed

+65
-30
lines changed

action.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ runs:
4444
HELPER__LINEAR__TOKEN: ${{ inputs.linear-token }}
4545
HELPER__SLACK__BOT_TOKEN: ${{ inputs.slack-bot-token }}
4646
HELPER__SLACK__DEPLOY_CHANNEL: ${{ inputs.slack-channel-name }}
47+
HELPER__DEPLOY: ${{ inputs.enable-deploy }}
4748

4849
branding:
4950
color: 'blue'

ruff.toml

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ ignore = [# https://docs.astral.sh/ruff/settings/#lint_ignore
6464
"D106", # Missing docstring in public nested class
6565
"D107", # Missing docstring in __init__
6666
"RET504", # Missing return type annotation
67+
"PLR0913",
6768
]
6869

6970
[lint.per-file-ignores]

src/release_helper/main.py

+63-30
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from typing import TYPE_CHECKING
24

35
from loguru import logger
@@ -25,52 +27,83 @@ def process_potential_release() -> None:
2527
try:
2628
release_draft: GitRelease = github.get_draft_release()
2729
except ReleaseHelperError as e:
28-
slack.send_errors(channel=settings.helper.slack.deploy_channel, errors=[e])
29-
logger.info("No draft release found. Exiting.")
30+
handle_no_draft_release(slack, settings, e)
3031
return
3132

3233
issue_names = github.get_issues_from_release(release_draft)
33-
3434
issues, errors = linear.get_issues(issue_names)
3535

3636
if settings.helper.deploy:
37-
if len(errors) == 0:
38-
if all(issue.state.type == "completed" for issue in issues):
39-
github.deploy(release_draft)
40-
linear.set_issues_to_deployed(issues)
41-
slack.send_deploy_message(
42-
channel=settings.helper.slack.deploy_channel,
43-
release_title=release_draft.title,
44-
)
45-
logger.info("Release deployed.")
46-
else:
47-
slack.send_release_message(
48-
channel=settings.helper.slack.deploy_channel,
49-
release_draft=release_draft,
50-
issues=issues,
51-
repository=settings.github_repository,
52-
)
53-
slack.send_not_deploy_message(
54-
channel=settings.helper.slack.deploy_channel,
55-
release_title=release_draft.title,
56-
)
57-
logger.info("Not all issues are completed.")
58-
else:
59-
slack.send_errors(
60-
channel=settings.helper.slack.deploy_channel, errors=errors
61-
)
62-
logger.info("Errors found. Not deploying.")
37+
handle_deploy(settings, slack, github, linear, release_draft, issues, errors)
38+
else:
39+
handle_non_deploy(settings, slack, issues, release_draft)
40+
41+
42+
def handle_no_draft_release(
43+
error: ReleaseHelperError,
44+
settings: Settings,
45+
slack: MessagingSlack,
46+
) -> None:
47+
slack.send_errors(channel=settings.helper.slack.deploy_channel, errors=[error])
48+
logger.info("No draft release found. Exiting.")
49+
50+
51+
def handle_deploy(
52+
errors: list[Exception],
53+
github: SourceControlGithub,
54+
issues: list[IssueManagementLinear.Issue],
55+
linear: IssueManagementLinear,
56+
release_draft: GitRelease,
57+
settings: Settings,
58+
slack: MessagingSlack,
59+
) -> None:
60+
if errors:
61+
slack.send_errors(channel=settings.helper.slack.deploy_channel, errors=errors)
62+
logger.info("Errors found. Not deploying. %s", errors)
6363
return
6464

65+
if all(issue.state.type == "completed" for issue in issues):
66+
github.deploy(release_draft)
67+
linear.set_issues_to_deployed(issues)
68+
slack.send_deploy_message(
69+
channel=settings.helper.slack.deploy_channel,
70+
release_title=release_draft.title,
71+
)
72+
logger.info("Release deployed.")
73+
else:
74+
slack.send_release_message(
75+
channel=settings.helper.slack.deploy_channel,
76+
release_draft=release_draft,
77+
issues=issues,
78+
repository=settings.github_repository,
79+
)
80+
slack.send_not_deploy_message(
81+
channel=settings.helper.slack.deploy_channel,
82+
release_title=release_draft.title,
83+
)
84+
logger.info("Not all issues are completed. Not deploying.")
85+
86+
87+
def handle_non_deploy(
88+
issues: list[IssueManagementLinear.Issue],
89+
release_draft: GitRelease,
90+
settings: Settings,
91+
slack: MessagingSlack,
92+
) -> None:
6593
for issue in issues:
6694
if issue.state.type != "completed":
6795
block = slack.generate_user_message(issue)
6896
channel = settings.helper.slack.channels.get(
6997
issue.team.key.casefold(), settings.helper.slack.deploy_channel
7098
)
7199
slack.send_blocks(channel=channel, blocks=[block], text="")
100+
logger.info("Ticket Status messages sent.")
72101

73-
logger.info("Ticket Status messages sent.")
102+
slack.send_not_deploy_message(
103+
channel=settings.helper.slack.deploy_channel,
104+
release_title=release_draft.title,
105+
)
106+
logger.info("The deploy setting is '%s'. Not deploying.", settings.helper.deploy)
74107

75108

76109
if __name__ == "__main__":

0 commit comments

Comments
 (0)