Skip to content

Commit

Permalink
Change notification to be sent to the service
Browse files Browse the repository at this point in the history
  • Loading branch information
niveathika committed Jun 25, 2021
1 parent 22667ac commit 46971a2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 26 deletions.
16 changes: 6 additions & 10 deletions dependabot/notify_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,20 @@
import constants


def send_message(message):
build_chat_id = os.environ[constants.ENV_CHAT_ID]
build_chat_key = os.environ[constants.ENV_CHAT_KEY]
build_chat_token = os.environ[constants.ENV_CHAT_TOKEN]
def send_message(payload):
# Change URL and add security header
service_base = ''

url = 'https://chat.googleapis.com/v1/spaces/' + build_chat_id + \
'/messages?key=' + build_chat_key + '&token=' + build_chat_token

bot_message = {'text': message}
message_headers = {'Content-Type': 'application/json; charset=UTF-8'}
url = 'https://' + service_base + '/notification'
message_headers = {'Content-Type': 'application/json'}

http_obj = Http()

resp = http_obj.request(
uri=url,
method='POST',
headers=message_headers,
body=dumps(bot_message),
body=dumps(payload),
)[0]

if resp.status == 200:
Expand Down
51 changes: 35 additions & 16 deletions dependabot/update_dependencies_in_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,10 @@ def main():
update_module(idx, current_level)

if auto_merge_pull_requests.lower() == 'true':
module_release_failure, chat_message = wait_for_current_level_build(current_level)
module_release_failure, payload = wait_for_current_level_build(current_level)
if module_release_failure:
print(chat_message)
chat_message += "After following up on the above, retrigger the <" + \
"https://github.com/ballerina-platform/ballerina-release/actions/workflows/update_dependency_version.yml" + \
"|Dependency Update Workflow>"
notify_chat.send_message(chat_message)
print(payload)
notify_chat.send_message(payload)
sys.exit(1)
print('Successfully bumped dependencies in extensions packed in ballerina-distribution')

Expand Down Expand Up @@ -188,44 +185,66 @@ def wait_for_current_level_build(level):
sys.exit(1)

module_release_failure = False
chat_message = "Dependency update to lang version \'" + lang_version + "\'.\n"
payload = {
'ballerinaVersion': lang_version,
'prChecksFailed': [],
'prMergeFailed': [],
'buildCheckFailed': [],
'buildVersionCannotBeIdentified': []
}
pr_checks_failed_modules = list(
filter(lambda s: s[MODULE_CONCLUSION] == MODULE_CONCLUSION_PR_CHECK_FAILURE, current_level_modules))
if len(pr_checks_failed_modules) != 0:
module_release_failure = True
chat_message += 'Following modules\' Automated Dependency Update PRs have failed checks...' + "\n"
print('Following modules\' Automated Dependency Update PRs have failed checks...\n')
for module in pr_checks_failed_modules:
chat_message += "<" + module[MODULE_CREATED_PR].html_url + "|" + module['name'] + ">" + "\n"
payload['prChecksFailed'].append({
'name': module['name'],
'link': module[MODULE_CREATED_PR].html_url
});
print(module['name'] + " (" + module[MODULE_CREATED_PR].html_url + ")\n")

pr_merged_failed_modules = list(
filter(lambda s: s[MODULE_CONCLUSION] == MODULE_CONCLUSION_PR_MERGE_FAILURE, current_level_modules))
if len(pr_merged_failed_modules) != 0:
module_release_failure = True
chat_message += 'Following modules\' Automated Dependency Update PRs could not be merged...' + "\n"
print('Following modules\' Automated Dependency Update PRs could not be merged...\n')
for module in pr_merged_failed_modules:
chat_message += "<" + module[MODULE_CREATED_PR].html_url + "|" + module['name'] + ">" + "\n"
payload['prMergeFailed'].append({
'name': module['name'],
'link': module[MODULE_CREATED_PR].html_url
});
print(module['name'] + " (" + module[MODULE_CREATED_PR].html_url + ")\n")

build_checks_failed_modules = list(
filter(lambda s: s[MODULE_CONCLUSION] == MODULE_CONCLUSION_BUILD_FAILURE, current_level_modules))
if len(build_checks_failed_modules) != 0:
module_release_failure = True
chat_message += 'Following modules\' Timestamped Build checks have failed...' + "\n"
print('Following modules\' Timestamped Build checks have failed...\n')
for module in build_checks_failed_modules:
build_actions_page = constants.BALLERINA_ORG_URL + module['name'] + "/actions/workflows/" + \
module[MODULE_BUILD_ACTION_FILE] + ".yml"
chat_message += "<" + build_actions_page + "|" + module['name'] + ">" + "\n"
payload['buildCheckFailed'].append({
'name': module['name'],
'link': build_actions_page
});
print(module['name'] + " (" + build_actions_page + ")\n")

build_version_failed_modules = list(
filter(lambda s: s[MODULE_CONCLUSION] == MODULE_CONCLUSION_VERSION_CANNOT_BE_IDENTIFIED, current_level_modules))
if len(build_version_failed_modules) != 0:
module_release_failure = True
chat_message += 'Following modules\' latest Timestamped Build Version cannot be identified...' + "\n"
print('Following modules\' latest Timestamped Build Version cannot be identified...\n')
for module in build_version_failed_modules:
build_actions_page = constants.BALLERINA_ORG_URL + module['name'] + "/actions/workflows/" + \
module[MODULE_BUILD_ACTION_FILE] + ".yml"
chat_message += "<" + build_actions_page + "|" + module['name'] + ">" + "\n"
payload['buildVersionCannotBeIdentified'].append({
'name': module['name'],
'link': build_actions_page
});
print(module['name'] + " (" + build_actions_page + ")\n")

return module_release_failure, chat_message
return module_release_failure, payload


def check_pending_pr_checks(index: int):
Expand Down

0 comments on commit 46971a2

Please sign in to comment.