Пример #1
0
def home():
    """Homepage for linking a Gitlab project to a Trello board."""
    if request.method == 'POST':
        project_id = request.form['project-id']
        board_id = request.form['board-id']

        # check if project is already linked with a board
        try:
            project = ProjectHasBoard.by_project(project_id)
            project.update({'board_id': board_id})
        except Exception:
            app.logger.info('Linking project %s with board %s'
                            % (project_id, board_id))
            link, created = get_or_create(
                db.session, ProjectHasBoard, project_id=project_id,
                board_id=board_id)
            if not created:
                app.logger.info('Already linked')
        db.session.commit()

    # Check for Trello App Token
    if app.config['TRELLO_TOKEN'] in (None, ''):
        token_url = trello.get_token_url(
            'Gitlab To Trello', expires='never', write_access=True)
        return redirect(token_url)

    # Get all gitlab projects
    projects = git.getprojects()

    if not projects:
        return render_template('index.html')

    # Check for package.json at project root
    for project in projects:
        # Add flag to project dict to show project type
        if (git.getfile(project['id'], 'package.json',
                        project['default_branch'])):
            # Node.js project
            project['project_type'] = 'nodejs'
        elif (git.getfile(project['id'], 'setup.py',
                          project['default_branch'])):
            # Python project
            project['project_type'] = 'python'

        # Check if project is already linked to a board
        try:
            phb = ProjectHasBoard.by_project(project['id'])
            project['board_id'] = phb.board_id
        except NoResultFound:
            app.logger.warn('Project %s has no board linked' % project['id'])

        # Check if project is already monitored
        if project.get('project_type'):
            try:
                is_monitored = ProjectDependency.is_monitored(project['id'])
                if is_monitored:
                    project['is_monitored'] = 'True'
            except Exception, e:
                app.logger.error(e)
Пример #2
0
def nodeLatestVersion(dependency, project_id):
    r = requests.get('%s%s/latest' % (app.config['NPM_REGISTRY'], dependency))
    latestVersion = r.json().get('version')

    try:
        dep = ProjectDependency.by_project(project_id, dependency)
        dep.latest_version = latestVersion
        if LooseVersion(dep.actual_version) < LooseVersion(latestVersion):
            dep.status = 'ko'
        else:
            dep.status = 'ok'
        db.session.commit()
    except Exception, e:
        app.logger.error(e)
        db.session.rollback()
Пример #3
0
def nodeLatestVersion(dependency, project_id):
    r = requests.get('%s%s/latest' % (app.config['NPM_REGISTRY'], dependency))
    latestVersion = r.json().get('version')

    try:
        dep = ProjectDependency.by_project(project_id, dependency)
        dep.latest_version = latestVersion
        if LooseVersion(dep.actual_version) < LooseVersion(latestVersion):
            dep.status = 'ko'
        else:
            dep.status = 'ok'
        db.session.commit()
    except Exception, e:
        app.logger.error(e)
        db.session.rollback()
Пример #4
0
def dependencies(project_id):
    """Page showing status of a project dependencies."""
    dependencies = ProjectDependency.by_project(project_id)

    return render_template('dependencies.html', dependencies=dependencies)