Skip to content

Commit

Permalink
PRODUCTION_BRANCH -> PRODUCTION_BRANCHES to handle situations when th…
Browse files Browse the repository at this point in the history
…ere are more than one production branch

Signed-off-by: Andrey Devyatkin <[email protected]>
  • Loading branch information
Andrey9kin committed Sep 15, 2021
1 parent 17f838f commit 746fcf4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ services:
BRANCHES_TO_PROMOTE:
TIMEOUT_MINUTES:
TIMEZONE:
PRODUCTION_BRANCH:
PRODUCTION_BRANCHES:
SLACK_CHANNEL_NAME:
8 changes: 5 additions & 3 deletions helpers_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ def current_time(timezone):
return "{}:{}:{}".format(now.hour, now.minute, now.second)


def generate_time_based_message(prod_branch, branches, timezone):
if prod_branch not in ' '.join(branches):
def generate_time_based_message(production_branches, branches, timezone):
# if there is no overlap between branches to promote and production branches
# then skip adding time based message
if not list(set(production_branches) & set(branches)):
return ''
message = f'\nIt is {current_time(timezone)} in {timezone}.'
message = f'\n⚠️ It is {current_time(timezone)} in {timezone}.'
if is_friday_evening(timezone):
return (message
+ ' Deploying to production during Friday afternoon hours?'
Expand Down
7 changes: 5 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@
branches_to_promote = os.environ['BRANCHES_TO_PROMOTE'].split()
timeout_minutes = int(os.environ['TIMEOUT_MINUTES'])
timezone = os.environ['TIMEZONE']
production_branch = os.environ['PRODUCTION_BRANCH']
production_branches = os.environ['PRODUCTION_BRANCHES'].split()
slack_bot_token = os.environ["SLACK_BOT_TOKEN"]

print(f'branches_to_promote: {branches_to_promote}')
print(f'production_branches: {production_branches}')

ok_id = uuid.uuid4().hex
nok_id = uuid.uuid4().hex
app = helpers_slack.init_app(slack_bot_token, ok_id, nok_id)
Expand All @@ -49,7 +52,7 @@

for branch in branches_to_promote:
details += helpers_git.generate_diff(branch, current_commit_id, repo_url)
details += helpers_time.generate_time_based_message(production_branch, branches_to_promote, timezone)
details += helpers_time.generate_time_based_message(production_branches, branches_to_promote, timezone)

# Truncate too long messages to prevent Slack from posting them as several messages
# We saw Slack splitting message into two after 3800 but haven't found any documentation
Expand Down
2 changes: 1 addition & 1 deletion test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export REPOSITORY_URL=https://github.com/fivexl/magic-button
export BRANCHES_TO_PROMOTE=test
export TIMEOUT_MINUTES=1
export TIMEZONE=$(cat /etc/timezone)
export PRODUCTION_BRANCH=release
export PRODUCTION_BRANCHES=release
export SLACK_CHANNEL_NAME=magic-button-test

docker-compose up -d --build
Expand Down

0 comments on commit 746fcf4

Please sign in to comment.