Skip to content

Commit

Permalink
Merge pull request #101 from vpodzime/master-fixes
Browse files Browse the repository at this point in the history
A couple fixes for interactive use
  • Loading branch information
vpodzime authored May 13, 2024
2 parents 7b79659 + b68f4df commit bfef203
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 40 deletions.
63 changes: 28 additions & 35 deletions tom/bot.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -49,38 +47,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:
Expand Down
14 changes: 9 additions & 5 deletions tom/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit bfef203

Please sign in to comment.