# in a git repository specified in the GOPHER_CUSTOM_REPOSITORY # environment variable, which translates to CUSTOM_REPOSITORY_URL # in the job (see the definition for the updatecfg job in # conf/gopherbot.yaml). When this job is run, the robot will attempt # to clone or pull it's configuration repository. # Note that if your config repo has a '.gopherci/pipeline.sh', it'll # 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):
#!/usr/bin/python3 import os import sys sys.path.append("%s/lib" % os.getenv("GOPHER_INSTALLDIR")) from gopherbot_v2 import Robot bot = Robot() executable = sys.argv.pop(0) command = sys.argv.pop(0) if command == "configure": exit(0) repodata = bot.GetRepoData() def start_build(repository, branch, pipeline, args): if pipeline == "pipeline": bot.Say("Ok, I'll start the gopherci job for %s, %s branch..." % (repository, branch)) bot.AddJob("gopherci", ["build", repository, branch]) bot.AddTask("say", ["... build of %s/%s completed" % (repository, branch)]) bot.FailTask("say", ["... 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"
# in a git repository specified in the GOPHER_CUSTOM_REPOSITORY # environment variable, which translates to CUSTOM_REPOSITORY_URL # in the job (see the definition for the updatecfg job in # conf/robot.yaml). When this job is run, the robot will attempt # to clone or pull it's configuration repository. # Note that if your config repo has a '.gopherci/pipeline.sh', it'll # 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):
#!/usr/bin/python3 import os import sys sys.path.append("%s/lib" % os.getenv("GOPHER_INSTALLDIR")) from gopherbot_v2 import Robot 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)
#!/usr/bin/python3 import os import sys sys.path.append("%s/lib" % os.getenv("GOPHER_INSTALLDIR")) from gopherbot_v2 import Robot bot = Robot() default_config = ''' --- Help: - Keywords: [ "python" ] Helptext: [ "(bot), python (me!) - prove that python plugins work" ] - Keywords: [ "listen" ] Helptext: [ "(bot), listen (to me!) - ask a question" ] - Keywords: [ "remember", "memory" ] Helptext: [ "(bot), remember <anything> - prove the robot has a brain(tm)" ] - Keywords: [ "recall", "memory" ] Helptext: [ "(bot), recall - prove the robot has a brain(tm)" ] - Keywords: [ "forget", "memory" ] Helptext: [ "(bot), forget <#> - ask the robot to forget one of it's remembered 'facts'" ] - Keywords: [ "check" ] Helptext: [ "(bot), check me - get the bot to check you out" ] CommandMatchers: - Regex: (?i:python( me)?!?) Command: python - Regex: (?i:listen( to me)?!?) Command: listen - Regex: (?i:remember ([-\w .,!?:\/]+)) Command: remember
#!/usr/bin/env python3 # git-init.py - task for setting up git credentials # Currently this only adds ssh-init and ssh-scan <host> to # the pipeline if needed, but may eventually handle http credentials # with a git credential helper. # Usage: AddTask git-init <clone_url> import os import re import sys sys.path.append("%s/lib" % os.getenv("GOPHER_INSTALLDIR")) from gopherbot_v2 import Robot bot = Robot() cfgdir = os.getenv("GOPHER_CONFIGDIR") try: os.stat("%s/git/config" % cfgdir) except FileNotFoundError: bot.Log("Warn", "%s/git/config not found, git push will fail" % cfgdir) bot.SetParameter("XDG_CONFIG_HOME", cfgdir) # Pop off the executable path sys.argv.pop(0) clone_url = sys.argv.pop(0) if not clone_url.startswith("http"):
# called with two arguments, they are interpreted as the repository and branch # of a primary build. When called with four arguments, the first two are the # repository and branch to build, and the second two are the repository and # branch that triggered the build. # # The build type is responsible for calling Exclusive, setting up the build # directory, and adding the initial pipeline tasks. All other # pipeline/dependency logic is in gopherci. import os import re import sys sys.path.append("%s/lib" % os.getenv("GOPHER_INSTALLDIR")) from gopherbot_v2 import Robot bot = Robot() # Pop off the executable path sys.argv.pop(0) command = sys.argv.pop(0) if command != "init": exit(0) cfgdir = os.getenv("GOPHER_CONFIGDIR") cfgfile = os.path.join(cfgdir, "conf", "gopherbot.yaml") try: os.stat(cfgfile) except FileNotFoundError: pass
# called with two arguments, they are interpreted as the repository and branch # of a primary build. When called with four arguments, the first two are the # repository and branch to build, and the second two are the repository and # branch that triggered the build. # # The build type is responsible for calling Exclusive, setting up the build # directory, and adding the initial pipeline tasks. All other # pipeline/dependency logic is in gopherci. import os import re import sys sys.path.append("%s/lib" % os.getenv("GOPHER_INSTALLDIR")) from gopherbot_v2 import Robot bot = Robot() # Pop off the executable path sys.argv.pop(0) repository = sys.argv.pop(0) 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()
#!/usr/bin/env python3 # bootstrap.py - bootstrap a robot from env vars import os import re import sys sys.path.append("%s/lib" % os.getenv("GOPHER_INSTALLDIR")) from gopherbot_v2 import Robot bot = Robot() # Pop off the executable path sys.argv.pop(0) command = sys.argv.pop(0) if command != "init": exit(0) cfgdir = os.getenv("GOPHER_CONFIGDIR") cfgconf = os.path.join(cfgdir, "conf") hasconfig = True try: os.stat(cfgconf) except FileNotFoundError: hasconfig = False except: bot.Log("Error", "Checking for %s: %s" % (cfgconf, sys.exc_info()[0])) exit(1)
# type != none, another gopherci task is added with a third argument of "true" # When the gopherci job runs with three arguments, each dependendent build # is spawned. # # The result is if the initial build succeeds, all dependent builds will run # in parallel with no further interdependencies. # # NOTE: current gopherci does not cascade dependent builds; if a dependency # build is itself a de import os import sys sys.path.append("%s/lib" % os.getenv("GOPHER_INSTALLDIR")) from gopherbot_v2 import Robot bot = Robot() repodata = bot.GetRepoData() if not isinstance(repodata, dict): bot.Log( "Warn", "GopherCI triggered with invalid 'repositories.yaml', not a python 'dict'" ) exit(0) build_triggered = False # Pop off the executable path sys.argv.pop(0)
# type != none, another gopherci task is added with a third argument of "true" # When the gopherci job runs with three arguments, each dependendent build # is spawned. # # The result is if the initial build succeeds, all dependent builds will run # in parallel with no further interdependencies. # # NOTE: current gopherci does not cascade dependent builds; if a dependency # build is itself a de import os import sys sys.path.append("%s/lib" % os.getenv("GOPHER_INSTALLDIR")) from gopherbot_v2 import Robot bot = Robot() repodata = bot.GetRepoData() if not isinstance(repodata, dict): bot.Log( "Warn", "GopherCI triggered with invalid 'repositories.yaml', not a python 'dict'" ) exit(0) build_triggered = False # Pop off the executable path sys.argv.pop(0)
#!/usr/bin/python3 import os import sys import time sys.path.append("%s/lib" % os.getenv("GOPHER_INSTALLDIR")) from gopherbot_v2 import Robot cfgdir = os.getenv("GOPHER_CONFIGDIR") sys.path.append(cfgdir) import podlib.userpod as userpod 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")
# called with two arguments, they are interpreted as the repository and branch # of a primary build. When called with four arguments, the first two are the # repository and branch to build, and the second two are the repository and # branch that triggered the build. # # The build type is responsible for calling Exclusive, setting up the build # directory, and adding the initial pipeline tasks. All other # pipeline/dependency logic is in gopherci. import os import re import sys sys.path.append("%s/lib" % os.getenv("GOPHER_INSTALLDIR")) from gopherbot_v2 import Robot bot = Robot() # Pop off the executable path sys.argv.pop(0) # localbuild and all build types always get a "command" from gopherci, # never triggered. # One of "build", "depbuild", "job" command = sys.argv.pop(0) repository = sys.argv.pop(0) branch = sys.argv.pop(0) bot.SetParameter("GOPHERCI_BRANCH", branch) pipeline = "pipeline"