Beispiel #1
0
def get_job_name_and_build_number(url):
    """
    Simple, naive implementation of getting job name and build number from URL.
    """
    # strip /console if present
    if url.endswith('/console'):
        url = url[:len(url) - 8]
    # make sure it's a job URL
    if 'job/' not in url:
        raise Exception("Could not parse URL - 'job/' not in %s" % url)
    # if it ends in a build number, capture that and then strip it
    build_no = None
    m = re.match(r'.*(/\d+/?)$', url)
    if m is not None and m.group(1) != '':
        build_no = int(m.group(1).strip('/'))
        url = url[:(-1 * len(m.group(1))) + 1]
    # get the path
    parsed = urlparse(url)
    # simple, naive job URL parsing
    job = parsed.path
    # handle Multibranch job URLs
    if '/view/change-requests/job/' in job:
        job = job.replace('/view/change-requests/job/', '/job/')
    job = job.replace('job/', '').strip('/')
    return job, build_no
Beispiel #2
0
def get_job_name_and_build_number(url):
    """
    Simple, naive implementation of getting job name and build number from URL.
    """
    # strip /console if present
    if url.endswith('/console'):
        url = url[:len(url) - 8]
    # make sure it's a job URL
    if 'job/' not in url:
        raise Exception("Could not parse URL - 'job/' not in %s" % url)
    # if it ends in a build number, capture that and then strip it
    build_no = None
    m = re.match(r'.*(/\d+/?)$', url)
    if m is not None and m.group(1) != '':
        build_no = int(m.group(1).strip('/'))
        url = url[:(-1 * len(m.group(1))) + 1]
    # get the path
    parsed = urlparse(url)
    # simple, naive job URL parsing
    job = parsed.path
    # handle Multibranch job URLs
    if '/view/change-requests/job/' in job:
        job = job.replace('/view/change-requests/job/', '/job/')
    # handle pipeline job URLs
    if '/view/Pipeline_' in job:
        job = re.sub('\/view\/Pipeline_[^\/]+\/', '/', job)
    job = job.replace('job/', '').strip('/')
    return job, build_no
Beispiel #3
0
def get_jenkins_base_url(url):
    """
    Shamelessly stolen from twoline-utils by @coddingtonbear
    https://github.com/coddingtonbear/twoline-utils/blob/master/twoline_utils/commands.py
    licensed under MIT license, Copyright 2014 Adam Coddington
    """
    parsed = urlparse(url)
    return parsed.scheme + '://' + parsed.netloc
Beispiel #4
0
def get_jenkins_base_url(url):
    """
    Shamelessly stolen from twoline-utils by @coddingtonbear
    https://github.com/coddingtonbear/twoline-utils/blob/master/twoline_utils/commands.py
    licensed under MIT license, Copyright 2014 Adam Coddington
    """
    parsed = urlparse(url)
    return parsed.scheme + '://' + parsed.netloc
Beispiel #5
0
 def convert(self, value, param, ctx):
     if not isinstance(value, tuple):
         value = urlparse.urlparse(value)
         if value.scheme not in ('http', 'https'):
             self.fail(
                 'invalid URL scheme (%s).  Only HTTP URLs are '
                 'allowed' % value.scheme, param, ctx)
     return value
Beispiel #6
0
def get_job_name_and_build_number(url):
    """
    Simple, naive implementation of getting job name and build number from URL.
    """
    # strip /console if present
    if url.endswith('/console'):
        url = url[:len(url) - 8]
    # make sure it's a job URL
    if 'job/' not in url:
        raise Exception("Could not parse URL - 'job/' not in %s" % url)
    # if it ends in a build number, capture that and then strip it
    build_no = None
    m = re.match(r'.*(/\d+/?)$', url)
    if m is not None and m.group(1) != '':
        build_no = int(m.group(1).strip('/'))
        url = url[:(-1 * len(m.group(1))) + 1]
    # get the path
    parsed = urlparse(url)
    # simple, naive job URL parsing
    job = parsed.path.replace('job/', '').strip('/')
    return job, build_no
 def get_jenkins_base_url(url):
     parsed = urlparse(url)
     return parsed.scheme + '://' + parsed.netloc
Beispiel #8
0
 def convert(self, value, param, ctx):
     if not isinstance(value, tuple):
         value = urlparse.urlparse(value)
         if value.scheme not in ("http", "https"):
             self.fail("invalid URL scheme (%s).  Only HTTP URLs are " "allowed" % value.scheme, param, ctx)
     return value
Beispiel #9
0
def resolve_input(ctx, param, value):
    # this will catch both http and https
    if value.startswith("http"):
        return urlparse.urlparse(value)
    else:
        return click.utils.open_file(value)
 def get_jenkins_base_url(url):
     parsed = urlparse(url)
     return parsed.scheme + '://' + parsed.netloc
Beispiel #11
0
def resolve_input(ctx, param, value):
    # this will catch both http and https
    if value.startswith('http'):
        return urlparse.urlparse(value)
    else:
        return click.utils.open_file(value)