Skip to content

Commit

Permalink
bots: Get default repo from "origin" remote
Browse files Browse the repository at this point in the history
  • Loading branch information
mvollmer authored and martinpitt committed Nov 8, 2018
1 parent 027c08d commit 718be03
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bots/push-rewrite
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def git(*args):

def main():
parser = argparse.ArgumentParser(description='Force push after a rewrite')
parser.add_argument('--repo', help="The GitHub repository to work with", default="cockpit-project/cockpit")
parser.add_argument('--repo', help="The GitHub repository to work with", default=None)
parser.add_argument('remote', help='The remote to push to')
parser.add_argument('branch', nargs='?', help='The branch to push')
opts = parser.parse_args()
Expand Down
15 changes: 12 additions & 3 deletions bots/task/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import sys
import time
import urllib.parse
import subprocess
import re

from . import cache

Expand Down Expand Up @@ -81,13 +83,20 @@ def write(self, value):
with open(self.path, 'a') as f:
f.write(value)

def get_origin_repo():
res = subprocess.check_output([ "git", "remote", "get-url", "origin" ])
url = res.decode('utf-8').strip()
m = re.fullmatch("(git@github.com:|https://github.com/)(.*?)(\\.git)?", url)
if m:
return m.group(2)
raise RuntimeError("Not a GitHub repo: %s" % url)

class GitHub(object):
def __init__(self, base=None, cacher=None, repo=None):
if base is None:
if repo is None:
repo = os.environ.get("GITHUB_BASE", "cockpit-project/cockpit")
self.repo = repo or os.environ.get("GITHUB_BASE", None) or get_origin_repo()
netloc = os.environ.get("GITHUB_API", "https://api.github.com")
base = "{0}/repos/{1}/".format(netloc, repo)
base = "{0}/repos/{1}/".format(netloc, self.repo)
self.url = urllib.parse.urlparse(base)
self.conn = None
self.token = None
Expand Down
2 changes: 1 addition & 1 deletion bots/tests-trigger
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def main():
help='Force setting the status even if the program logic thinks it shouldn''t be done')
parser.add_argument('-a', '--allow', action='store_true', dest='allow',
help="Allow triggering for users that aren't whitelisted")
parser.add_argument('--repo', help="The repository to trigger the robots in", default="cockpit-project/cockpit")
parser.add_argument('--repo', help="The repository to trigger the robots in", default=None)
parser.add_argument('pull', help='The pull request to trigger')
parser.add_argument('context', nargs='?', help='The github task context to trigger')
opts = parser.parse_args()
Expand Down

0 comments on commit 718be03

Please sign in to comment.