diff --git a/docker-compose.yml b/docker-compose.yml index a60875c..9a217ba 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,5 +16,5 @@ services: BRANCHES_TO_PROMOTE: TIMEOUT_MINUTES: TIMEZONE: - PRODUCTION_BRANCH: + PRODUCTION_BRANCHES: SLACK_CHANNEL_NAME: diff --git a/helpers_time.py b/helpers_time.py index 6de4143..3ee221c 100644 --- a/helpers_time.py +++ b/helpers_time.py @@ -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?' diff --git a/main.py b/main.py index 135278f..87b69b1 100644 --- a/main.py +++ b/main.py @@ -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) @@ -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 diff --git a/test.sh b/test.sh index 92df16a..402d64f 100755 --- a/test.sh +++ b/test.sh @@ -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