You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
109 lines
3.5 KiB
Python
109 lines
3.5 KiB
Python
import json
|
|
import os
|
|
from typing import Dict, List, Tuple
|
|
|
|
from pykeybase.chat import KeybaseChat
|
|
|
|
DRONE_ENV_VARS = {"CI",
|
|
"DRONE",
|
|
"DRONE_BRANCH",
|
|
"DRONE_BUILD_ACTION",
|
|
"DRONE_BUILD_CREATED",
|
|
"DRONE_BUILD_EVENT",
|
|
"DRONE_BUILD_FINISHED",
|
|
"DRONE_BUILD_NUMBER",
|
|
"DRONE_BUILD_PARENT",
|
|
"DRONE_BUILD_STARTED",
|
|
"DRONE_BUILD_STATUS",
|
|
"DRONE_CALVER",
|
|
"DRONE_COMMIT",
|
|
"DRONE_COMMIT_AFTER",
|
|
"DRONE_COMMIT_AUTHOR",
|
|
"DRONE_COMMIT_AUTHOR_AVATAR",
|
|
"DRONE_COMMIT_AUTHOR_EMAIL",
|
|
"DRONE_COMMIT_AUTHOR_NAME",
|
|
"DRONE_COMMIT_BEFORE",
|
|
"DRONE_COMMIT_BRANCH",
|
|
"DRONE_COMMIT_LINK",
|
|
"DRONE_COMMIT_MESSAGE",
|
|
"DRONE_COMMIT_REF",
|
|
"DRONE_COMMIT_SHA",
|
|
"DRONE_DEPLOY_TO",
|
|
"DRONE_FAILED_STAGES",
|
|
"DRONE_FAILED_STEPS",
|
|
"DRONE_GIT_HTTP_URL",
|
|
"DRONE_GIT_SSH_URL",
|
|
"DRONE_PULL_REQUEST",
|
|
"DRONE_REMOTE_URL",
|
|
"DRONE_REPO",
|
|
"DRONE_REPO_BRANCH",
|
|
"DRONE_REPO_LINK",
|
|
"DRONE_REPO_NAME",
|
|
"DRONE_REPO_NAMESPACE",
|
|
"DRONE_REPO_OWNER",
|
|
"DRONE_REPO_PRIVATE",
|
|
"DRONE_REPO_SCM",
|
|
"DRONE_REPO_VISIBILITY",
|
|
"DRONE_SEMVER",
|
|
"DRONE_SEMVER_BUILD",
|
|
"DRONE_SEMVER_ERROR",
|
|
"DRONE_SEMVER_MAJOR",
|
|
"DRONE_SEMVER_MINOR",
|
|
"DRONE_SEMVER_PATCH",
|
|
"DRONE_SEMVER_PRERELEASE",
|
|
"DRONE_SEMVER_SHORT",
|
|
"DRONE_SOURCE_BRANCH",
|
|
"DRONE_STAGE_ARCH",
|
|
"DRONE_STAGE_DEPENDS_ON",
|
|
"DRONE_STAGE_FINISHED",
|
|
"DRONE_STAGE_KIND",
|
|
"DRONE_STAGE_MACHINE",
|
|
"DRONE_STAGE_NAME",
|
|
"DRONE_STAGE_NUMBER",
|
|
"DRONE_STAGE_OS",
|
|
"DRONE_STAGE_STARTED",
|
|
"DRONE_STAGE_STATUS",
|
|
"DRONE_STAGE_TYPE",
|
|
"DRONE_STAGE_VARIANT",
|
|
"DRONE_STEP_NAME",
|
|
"DRONE_STEP_NUMBER",
|
|
"DRONE_SYSTEM_HOST",
|
|
"DRONE_SYSTEM_HOSTNAME",
|
|
"DRONE_SYSTEM_PROTO",
|
|
"DRONE_SYSTEM_VERSION",
|
|
"DRONE_TAG",
|
|
"DRONE_TARGET_BRANCH"}
|
|
|
|
|
|
def build_drone_env_dict() -> Dict[str, str]:
|
|
return {key: os.environ.get(key, "") for key in DRONE_ENV_VARS}
|
|
|
|
|
|
def build_keybase_teams() -> List[Tuple[str, str]]:
|
|
keybase_teams = []
|
|
teams_list = os.environ.get("KEYBASE_TEAMS", "").split(",")
|
|
for team in teams_list:
|
|
keybase_teams.append(tuple(team.split(".")))
|
|
|
|
if not keybase_teams:
|
|
keybase_teams = [("", "")]
|
|
|
|
return keybase_teams
|
|
|
|
|
|
def main():
|
|
# Teams to notify format "<team>.<channel>,<team>.<channel>"
|
|
keybase_teams = build_keybase_teams()
|
|
keybase_chat = KeybaseChat()
|
|
env_map = build_drone_env_dict()
|
|
msg = json.dumps(env_map, indent=4)
|
|
|
|
print(msg)
|
|
|
|
for team in keybase_teams:
|
|
keybase_chat.send_team_message(team=team[0], message=msg, channel=team[1])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|