From ce1830701b3aa65ea75c06e5184a47024019a330 Mon Sep 17 00:00:00 2001 From: Vratislav Podzimek Date: Fri, 10 May 2024 14:24:49 +0200 Subject: [PATCH 1/3] Always create an instance of Slack for Bot The code relies on it in many places even if it doesn't actually communicate to Slack in any way (in the interactive mode, for example). --- tom/bot.py | 57 +++++++++++++++++++++++++----------------------------- 1 file changed, 26 insertions(+), 31 deletions(-) diff --git a/tom/bot.py b/tom/bot.py index 97cf153..1aad45d 100644 --- a/tom/bot.py +++ b/tom/bot.py @@ -49,38 +49,33 @@ def __init__(self, config, secrets, directory, interactive, reports): self.github = GitHub(secrets["GITHUB_TOKEN"], self.username, self.jenkins_repos) - self.slack = None - self.dispatcher = None - if secrets.get("SLACK_READ_TOKEN"): - self.slack = Slack( - read_token=secrets.get("SLACK_READ_TOKEN"), - bot_token=secrets.get("SLACK_SEND_TOKEN"), - app_token=secrets.get("SLACK_APP_TOKEN"), - username=self.username, - interactive=interactive, - ) - self.dispatcher = CommandDispatcher(self.slack) + self.slack = Slack( + read_token=secrets.get("SLACK_READ_TOKEN"), + bot_token=secrets.get("SLACK_SEND_TOKEN"), + app_token=secrets.get("SLACK_APP_TOKEN"), + username=self.username, + interactive=interactive, + ) + self.dispatcher = CommandDispatcher(self.slack) - if "create_prs_from_slack" in self.bot_features: - self.github_interface = GitHubInterface( - self.github, self.slack, self.dispatcher - ) - if "update_dependencies" in self.bot_features: - self.updater = UpdateChecker( - self.github, self.slack, self.dispatcher, "Lex-2008" - ) - if "generate_changelogs" in self.bot_features: - self.changelogger = ChangelogGenerator( - self.github, self.slack, self.dispatcher, "Lex-2008" - ) - if "map_packages" in self.bot_features: - self.package_mapper = PackageMapper( - self.github, self.slack, self.dispatcher, "Lex-2008" - ) - if "tag_builds" in self.bot_features: - self.tagger = Tagger( - self.github, self.slack, self.dispatcher, "Lex-2008" - ) + if "create_prs_from_slack" in self.bot_features: + self.github_interface = GitHubInterface( + self.github, self.slack, self.dispatcher + ) + if "update_dependencies" in self.bot_features: + self.updater = UpdateChecker( + self.github, self.slack, self.dispatcher, "Lex-2008" + ) + if "generate_changelogs" in self.bot_features: + self.changelogger = ChangelogGenerator( + self.github, self.slack, self.dispatcher, "Lex-2008" + ) + if "map_packages" in self.bot_features: + self.package_mapper = PackageMapper( + self.github, self.slack, self.dispatcher, "Lex-2008" + ) + if "tag_builds" in self.bot_features: + self.tagger = Tagger(self.github, self.slack, self.dispatcher, "Lex-2008") def post(self, path, data, msg=None): if self.interactive: From 1a6c291704a2a18492de3b3a3585f68d67e6ba43 Mon Sep 17 00:00:00 2001 From: Vratislav Podzimek Date: Fri, 10 May 2024 14:26:25 +0200 Subject: [PATCH 2/3] Clean unused imports in tom/bot.py --- tom/bot.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tom/bot.py b/tom/bot.py index 1aad45d..0323f14 100644 --- a/tom/bot.py +++ b/tom/bot.py @@ -1,20 +1,18 @@ import re -import sys import random -import json import datetime import logging as log from copy import copy from typing import Dict -from tom.github import GitHub, GitHubInterface, PR, Comment +from tom.github import GitHub, GitHubInterface, PR from tom.jenkins import Jenkins from tom.slack import Slack, CommandDispatcher from tom.dependencies import UpdateChecker from tom.changelog import ChangelogGenerator from tom.packages import PackageMapper from tom.tag import Tagger -from tom.utils import confirmation, pretty, email_sha256, write_json +from tom.utils import confirmation, email_sha256 class Bot: From b68f4dfc32f4d141ce30a969b67b8c9662c59a1a Mon Sep 17 00:00:00 2001 From: Vratislav Podzimek Date: Fri, 10 May 2024 14:29:38 +0200 Subject: [PATCH 3/3] Push to git repos with "-u" by default Setting the pushed branch at the remote as the upstream branch for the local one. This was probably the intention at some point because the docstring mentions it. --- tom/git.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tom/git.py b/tom/git.py index 73ca722..b6c5ce5 100644 --- a/tom/git.py +++ b/tom/git.py @@ -140,9 +140,13 @@ def commit(self, message): """Creates commit with message""" self.run_command("commit", "-m", message, "--allow-empty") - def push(self, ref=None, remote="origin"): + def push(self, ref=None, remote="origin", upstream=True): """Pushes local branch or tag to remote repo, optionally also setting it as upstream""" - if ref: - self.run_command("push", remote, ref) - else: - self.run_command("push", remote) + cmd = ["push"] + if upstream: + cmd.append("-u") + cmd.append(remote) + if ref is not None: + cmd.append(ref) + + self.run_command(*cmd)