예제 #1
0
def runit(days, tokenfile, project,debug):
    if not os.path.exists("logs"):
        os.mkdir("logs")

    if debug:
        do_debug()
    
    monthcut = (datetime.datetime.now() - datetime.timedelta(days=days)).replace(
        tzinfo=datetime.timezone.utc)
    token = open(tokenfile).read().strip()
    t = TravisPy(token)
    user = t.user()
    repos = user.repos()
    respository_id = None
    for x in repos['repositories']:
        print(x)
        print(x['name'])
        #print(dir(x))
        slug =x['slug']
        print (slug, x['id'])
        repo_id = x['id']

        
        ppath = "logs/" + slug
        if not os.path.exists(ppath):
            os.makedirs(ppath)

        if project == "":
            do_project(t, repo_id,monthcut, slug)
        elif project == x.slug:
            do_project(t, repo_id,monthcut, slug)
            return
예제 #2
0
 def __init__(self, username, uri=None):
     kwargs = {}
     if uri:  # leave as unspecified to use default
         kwargs['uri'] = uri
     self.client = TravisPy(**kwargs)
     self.username = username
     self.logger = logger.Logger('travis_ci')
예제 #3
0
def trigger_build(repo, branch):
    """ Sends a request to Travis, rebuilding the content
    """
    if not app.config["TRAVIS_REPO_SLUG"] or not app.config["TRAVIS_TOKEN"]:
        return

    t = TravisPy(app.config['TRAVIS_TOKEN'])

    # it doesn't make sense for multiple builds of the same branch to run at the same time
    # so if some are still running for our target branch, lets stop them
    for build in t.builds(slug=app.config["TRAVIS_REPO_SLUG"]):
        if not build.pull_request and build.pending and build.commit.branch == app.config[
                "NAUCSE_BRANCH"]:
            build.cancel()

    # unfortunately, TravisPy doesn't provide a method to trigger a build, so triggering manually:
    requests.post("https://api.travis-ci.org/repo/{}/requests".format(
        urllib.parse.quote_plus(app.config["TRAVIS_REPO_SLUG"])),
                  json={
                      "request": {
                          "branch": app.config["NAUCSE_BRANCH"],
                          "message": f"Triggered by {repo}/{branch}"
                      }
                  },
                  headers={
                      "Authorization": f"token {app.config['TRAVIS_TOKEN']}",
                      "Travis-API-Version": "3"
                  })
예제 #4
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")
예제 #5
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")
예제 #6
0
    def __init__(self,
                 username,
                 password,
                 repo_name,
                 repo_owner,
                 update_travis_commit_msg,
                 tag_commit_message,
                 github_token=None,
                 access_token=None,
                 repo_token=None):
        """A subclass of GitenbergJob that adds travis-ci related functionality

        Keyword arguments:
        username -- GitHub username
        password -- GitHub password
        repo_name -- name of Gitenberg repo (e.g., "Moby-Dick--Or-The-Whale_2701")
        repo_owner -- e.g., 'GITenberg' for https://github.com/gitenberg/At-the-Sign-of-the-Eagle_6218
        update_travis_commit_msg -- the git commit message for the update commit
        tag_commit_message -- the git commit message for the tagging commit
        github_token (optional) -- a GitHub token that is ued to obtain travis access token
        access_token (optional) -- the travis access token corresponding to GitHub account
        repo_token (optional) -- the travis token for building the given repo
        """

        super(GitenbergTravisJob,
              self).__init__(username, password, repo_name, repo_owner,
                             update_travis_commit_msg, tag_commit_message)

        self.username = username
        self.password = password

        self._github_token = github_token
        self._access_token = access_token

        # if access_token is given, use it
        # the access token corresponds to the output of the travis cli operation
        # `travis token`
        if access_token is not None:
            self.travis = TravisPy(access_token)
        # otherwise, we can pass a GitHub token to travis
        else:
            self.travis = TravisPy.github_auth(self.github_token())

        self._repo_token = repo_token
        self._travis_repo_public_key = None

        if self.gh_repo is not None:
            self.travis_repo = self.travis.repo(self.repo_slug)
예제 #7
0
def main():
    travis = TravisPy()
    revision = check_output(["git", "rev-parse", "HEAD"]).strip()
    build_passed = False
    for build in travis.builds(slug="datawire/mdk"):
        if build.commit.sha == revision:
            if build.passed:
                build_passed = True
                break
            else:
                error(
                    "Found the build but it has not passed.\n    Build state: "
                    + build.state +
                    "\n    Build URL: https://travis-ci.org/datawire/mdk/builds/"
                    + str(build.id))

    if not build_passed:
        error("No matching build found on Travis CI.")
예제 #8
0
    parser.add_argument('-n',
                        '--number',
                        type=int,
                        help="Build number. Omit for latest build")
    parser.add_argument(
        '-q',
        '--quiet',
        action='store_true',
        default=False,
        help="Quiet means only print from logs, with no extra build info")
    args = parser.parse_args()

    # Slow to import, no need for --help
    from travispy import TravisPy  # pip install travispy

    t = TravisPy()

    for number in range(args.number - 100, args.number):
        # print(number)

        build = t.builds(slug=args.slug, number=number)[0]

        #         print(build['started_at'])
        #         print(build['finished_at'])
        start_seconds = iso2epoch(build['started_at'])
        finish_seconds = iso2epoch(build['finished_at'])
        #         print(start_seconds)
        #         print(finish_seconds)
        seconds = finish_seconds - start_seconds
        #         print(seconds)
        m, s = divmod(seconds, 60)
def build_passed(repo):
    t = TravisPy()
    r = t.repo(repo)
    return r.last_build_state == 'passed'
예제 #10
0
from travispy import TravisPy
from gpiozero import LED
from signal import pause

red = LED(14)
yellow = LED(15)
green = LED(18)

repository_name = 'gdyrrahitis/pi-commander-mobile'
travis = TravisPy()

try:

    def build_started():
        while True:
            r = travis.repo(repository_name)
            print(f'Started state {r.state}')
            yield r.state == 'started'

    def build_passed():
        while True:
            r = travis.repo(repository_name)
            print(f'Passed state {r.state}')
            yield r.state == 'passed' and r.state != 'started'

    def build_unsuccessful():
        while True:
            r = travis.repo(repository_name)
            print(f'Unsuccessful state {r.state}')
            yield r.state != 'passed' and r.state != 'started'
예제 #11
0
 def setup_method(self, method):
     if GITHUB_ACCESS_TOKEN:
         self._travis = TravisPy.github_auth(GITHUB_ACCESS_TOKEN)
     else:
         self._travis = TravisPy()
예제 #12
0
 def test(self):
   with self.assertRaises(TravisError):
     travis = TravisPy(token='invalid_token')
     travis.repo('some_repo')
예제 #13
0
 def v2client(self):
     """Travis API v2 client."""
     if self._travis_token:
         return TravisPy(token=self._travis_token)
     else:
         return TravisPy.github_auth(self._github_token)
def build_passed(repo):
    t = TravisPy()
    r = t.repo(repo)
    while True:
        yield r.last_build_state == 'passed'
예제 #15
0
def build_passed(repo='RPi-Distro/python-gpiozero', delay=3600):
    t = TravisPy()
    r = t.repo(repo)
    while True:
        yield r.last_build_state == 'passed'
        sleep(delay)  # Sleep an hour before hitting travis again
예제 #16
0
        f.write(token)


if __name__ == '__main__':
    # get the pelican repo and read the configuration
    repo = get_pelican_repo()
    reader = repo.config_reader()

    # build the remote repo name with the github user, ex: vdorsonnens/pelican
    reader.read()
    github_username = reader.get_value('user', 'name')
    remote_repo = '/'.join([github_username, PELICAN])

    # connect to travis-ci
    token = get_travis_token()
    travis_client = TravisPy(token)
    travis_repo = travis_client.repo(remote_repo)

    success = False
    if travis_repo.active:
        print('Repository is already enabled')
        sys.exit(0)

    else:
        print('Enabling repo...')
        success = travis_repo.enable()

    if success:
        print('Operation successful')
        sys.exit(0)
예제 #17
0
def travis():
    return TravisPy()