# get executed - useful for e.g. installing $HOME/.ssh/config. import os import re import sys sys.path.append("%s/lib" % os.getenv("GOPHER_INSTALLDIR")) from gopherbot_v2 import Robot bot = Robot() clone_url = os.getenv("GOPHER_CUSTOM_REPOSITORY") clone_branch = os.getenv("GOPHER_CUSTOM_BRANCH") cfgdir = os.getenv("GOPHER_CONFIGDIR") if not clone_url: bot.Say("GOPHER_CUSTOM_REPOSITORY not set") exit() if not cfgdir: bot.Say("GOPHER_CONFIGDIR not set") bot.Log("Error", "GOPHER_CONFIGDIR not set in updatecfg.py") exit() if not bot.Exclusive("updatecfg", False): bot.Say("Configuration update already in progress") bot.Log("Warn", "Configuration update already in progress, exiting") exit() bot.FailTask("status", [ "Updating configuration failed, check history for 'updatecfg'"]) if not clone_url.startswith("http"):
["... build of %s/%s failed" % (repository, branch)]) else: bot.Say( "Ok, I'll start the gopherci custom job for %s, %s branch, running pipeline: %s" % (repository, branch, pipeline)) bot.AddJob("gopherci", ["job", repository, branch, pipeline] + args) bot.AddTask( "say", ["... job %s/%s - %s: completed" % (repository, branch, pipeline)]) bot.FailTask( "say", ["... job %s/%s - %s: failed" % (repository, branch, pipeline)]) if not isinstance(repodata, dict): bot.Say("'repodata.yaml' missing or invalid; GetRepoData() failed") exit(0) if command == "build": build = [] repospec = sys.argv.pop(0).lower() fcount = len(repospec.split("/")) branch = sys.argv.pop(0) if len(branch) == 0: branch = "master" pipeline = sys.argv.pop(0) args = [] if len(pipeline) == 0: pipeline = "pipeline"
bot = Robot() default_config = ''' Channels: - random AllowDirect: false Help: - Keywords: [ "format", "world" ] Helptext: [ "(bot), format world - exercise formatting options" ] CommandMatchers: - Regex: '(?i:format world)' Command: "format" ''' executable = sys.argv.pop(0) command = sys.argv.pop(0) if command == "configure": print(default_config) if command == "format": bot = bot.MessageFormat("Variable") proto = bot.GetBotAttribute("protocol") bot.Say("Hello, %s World!" % proto) bot.Say('_Italics_ <One> *Bold* `Code` @parsley') bot.Say('_Italics_ <One> *Bold* `Code` @parsley', "raw") bot.Say('_Italics_ <One> *Bold* `Code` @parsley', "variable") bot.Say('_Italics_ <One> *Bold* `Code` @parsley', "fixed") bot.Say('_Italics_ <One> *Bold* `Code` @parsley', "bogus")
Config: Replies: - "You has the pythons" - "Are you JOKING?!? Pythons are DANGEROUS!!" - "Eh, how about a grass snake?" - "Sorry, I left it in my other jacket" ''' executable = sys.argv.pop(0) command = sys.argv.pop(0) if command == "configure": print(default_config) if command == "python": bot.Say("Sure, %s, gimme a sec to look for it..." % bot.GetSenderAttribute("firstName")) bot.Pause(1.5) bot.Say(bot.RandomString(bot.GetTaskConfig()["Replies"])) if command == "listen": dbot = bot.Direct() rep = dbot.PromptForReply("SimpleString", "Ok, what do you want to tell me?") if rep.ret == Robot.Ok: dbot.Say("I hear what you're saying - \"%s\"" % rep) else: bot.Say( "I'm sorry, I had a hard time hearing your replay - funny characters? Take too long?" ) if command == "remember":
branch = sys.argv.pop(0) bot.SetParameter("GOPHERCI_BRANCH", branch) if len(sys.argv) > 0: deprepo = sys.argv.pop(0) depbranch = sys.argv.pop(0) bot.SetParameter("GOPHERCI_DEPBUILD", "true") bot.SetParameter("GOPHERCI_DEPREPO", deprepo) bot.SetParameter("GOPHERCI_DEPBRANCH", depbranch) repodata = bot.GetRepoData() if repository in repodata: repoconf = repodata[repository] if "CloneURL" not in repoconf: bot.Say("No 'clone_url' specified for '%s' in repositories.yaml" % repository) exit() clone_url = repoconf["CloneURL"] if "KeepHistory" not in repoconf: keep_history = 7 else: keep_history = repoconf["KeepHistory"] repobranch = "%s/%s" % (repository, branch) if not bot.Exclusive(repobranch, False): bot.Log("Warn", "Build of '%s' already in progress, exiting" % repobranch) if len(bot.user) > 0: bot.Say( "localbuild of '%s' already in progress, not starting a new build" % repobranch)
bot = Robot() executable = sys.argv.pop(0) command = sys.argv.pop(0) if command == "configure": exit(0) if command == "init": exit(0) if command == "types": pod_types = userpod.pod_types() say = ["Pod types:"] bot.Say("\n".join(say + pod_types)) if command == "list": pod_dns = userpod.userpods("parse") if len(pod_dns) > 0: say = ["Running pods:"] bot.Say("\n".join(say + pod_dns)) else: bot.Say("No running pods found") if command == "launch": ptype = sys.argv.pop(0) annotations = { "nginx.ingress.kubernetes.io/auth-tls-secret": "admin/linuxjedi-ca-cert", "nginx.ingress.kubernetes.io/auth-tls-verify-client": "on",
if command == "depbuild": deprepo = sys.argv.pop(0) depbranch = sys.argv.pop(0) bot.SetParameter("GOPHERCI_DEPBUILD", "true") bot.SetParameter("GOPHERCI_DEPREPO", deprepo) bot.SetParameter("GOPHERCI_DEPBRANCH", depbranch) repodata = bot.GetRepoData() if repository in repodata: repoconf = repodata[repository] clone_url = repoconf["CloneURL"] if len(clone_url) == 0: bot.Say("No 'clone_url' specified for '%s' in repositories.yaml" % repository) exit(1) keep_history = repoconf["KeepLogs"] if keep_history == None: keep_history = -1 # Protect the repository directory with Exclusive if not bot.Exclusive(repository, False): bot.Log("Warn", "Build of '%s' already in progress, exiting" % repository) if len(bot.user) > 0: bot.Say( "build for '%s' already in progress, not starting a new build for branch '%s'" % (repository, branch)) exit()