예제 #1
0
    def on_message(self, headers, message):
        logging.warn("New build id arrived: %s" % message)
        # Remove output file after each run to avoid filling up the container.
        self.conn.ack(headers.get('message-id'), headers.get('subscription'))
        os.system("rm -rf clonedrepo")
        # Fetch slug and branch name from travis given buildid.
        reposlug = ""
        repobranch = ""
        selector = ""
        if not SLUG_MODE:
            t = TravisPy()
            build = t.build(message)
            repoid = build['repository_id']
            repobranch = build.commit.branch
            repo = t.repo(repoid)
            reposlug = repo.slug

        else:
            # Expect message format 'selector,branchname,selector'
            strList = message.split(",")
            logging.warn(message)
            logging.warn(strList)
            reposlug = strList[0]
            repobranch = strList[1]
            selector = strList[2]

        # Clone the repo branch
        token = os.getenv('GITHUB_OAUTH') or ''
        url = 'https://:@github.com/' + reposlug + '.git'
        repo = None
        branch_exist = True
        logging.warn('Cloning url ' + url)

        try:
            repo = git.Repo.clone_from(url, 'clonedrepo', branch=repobranch)
        except:
            logging.warn("Branch " + str(repobranch) + " or the repo " +
                         str(reposlug) + " itself does not exist anymore")
            branch_exist = False
            report_error(
                "Invalid repo or branch, double check if the input repo url is correct \n \n --STAMP/Dspot",
                "", reposlug, repobranch)

        # Check if project support dspot otherwise try autoconfiguring
        # assuming that dspot configurations is in the top most directory of
        # the project
        timecap = '-{date:%Y-%m-%d-%H-%M-%S}'.format(
            date=datetime.datetime.now())
        if branch_exist:
            if not run_Dspot_preconfig(reposlug, repobranch, selector):
                logging.warn(
                    "PROJECT DOES NOT SUPPORT DSPOT, COMMENCING AUTOCONFIGURING"
                )
                run_Dspot_autoconfig(reposlug, repobranch, selector)

            logging.warn("PIPELINE MESSAGE: DONE , AWAITING FOR NEW BUILD ID")
예제 #2
0
    def on_message(self, headers, message):
        logging.warning("New build id arrived: %s" % message)
        # Remove output file after each run to avoid filling up the container.
        self.conn.ack(headers.get('message-id'), headers.get('subscription'))
        os.system("rm -rf clonedrepo")
        # Fetch slug and branch name from travis given buildid.
        t = TravisPy()
        build = t.build(message)
        repoid = build['repository_id']
        repobranch = build.commit.branch
        repo = t.repo(repoid)
        reposlug = repo.slug
        # Clone the repo branch
        token = os.getenv('GITHUB_OAUTH') or ''
        url = 'https://github.com/' + reposlug + '.git'
        repo = None
        branch_exist = True
        logging.warning('Cloning url ' + url)

        try:
            repo = git.Repo.clone_from(url, 'clonedrepo', branch=repobranch)
        except:
            logging.warning("Branch " + str(repobranch) + " or the repo " +
                            str(reposlug) + " itself does not exist anymore")
            branch_exist = False

        # Check if project support dspot otherwise try autoconfiguring
        # assuming that dspot configurations is in the top most directory of
        # the project
        POM_FILE = "clonedrepo/pom.xml"
        timecap = '-{date:%Y-%m-%d-%H-%M-%S}'.format(
            date=datetime.datetime.now())

        if branch_exist:
            if not run_Dspot_preconfig(POM_FILE, reposlug, timecap):
                logging.warning("PROJECT DOES NOT SUPPORT DSPOT")
                run_Dspot_autoconfig(reposlug, timecap)

            # Commit build to github
            if check_endprocess_gitcommit(repo):
                templist = os.getenv("PUSH_URL").split('//')
                pushurl = templist[0] + '//' + token + '@' + templist[1]
                branch_name = reposlug.replace('/', "-") + timecap

                logging.warning('Commit to git as new branch with name ' +
                                branch_name)

                current = repo.git.checkout('-b', branch_name)
                # current.checkout()
                time.sleep(10)
                repo.git.add(A=True)
                repo.git.commit(m='update from dspot')
                repo.git.push(pushurl, branch_name)
                logging.warning("GITHUB NAME: " + os.getenv("GITHUB_USERNAME"))
            logging.warning(
                "PIPELINE MESSAGE: DONE , AWAITING FOR NEW BUILD ID")