~cedric/freshermeat

e24d5a3b7fa9e89e65e8bd576777b9ab999521ff — C├ędric Bonhomme 27 days ago e214458
reformatted files with black
M freshermeat/models/code.py => freshermeat/models/code.py +1 -2
@@ 3,8 3,7 @@ from freshermeat.bootstrap import db


class Code(db.Model):
    """Represent a source code (a repository).
    """
    """Represent a source code (a repository)."""

    id = db.Column(db.Integer(), primary_key=True)
    repository_url = db.Column(db.String(), nullable=False)

M freshermeat/models/cve.py => freshermeat/models/cve.py +1 -2
@@ 3,8 3,7 @@ from freshermeat.bootstrap import db


class CVE(db.Model):
    """Represent a CVE.
    """
    """Represent a CVE."""

    id = db.Column(db.Integer, primary_key=True)
    cve_id = db.Column(db.String(), nullable=False)

M freshermeat/models/language.py => freshermeat/models/language.py +1 -2
@@ 3,8 3,7 @@ from freshermeat.bootstrap import db


class Language(db.Model):
    """Represent a language.
    """
    """Represent a language."""

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(), default="", nullable=False, unique=True)

M freshermeat/models/organization.py => freshermeat/models/organization.py +1 -2
@@ 7,8 7,7 @@ from freshermeat.bootstrap import db


class Organization(db.Model):
    """Represent an organization.
    """
    """Represent an organization."""

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), unique=True)

M freshermeat/models/project.py => freshermeat/models/project.py +1 -2
@@ 29,8 29,7 @@ association_table_project = db.Table(


class Project(db.Model):
    """Represent a project.
    """
    """Represent a project."""

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), unique=True)

M freshermeat/models/release.py => freshermeat/models/release.py +1 -2
@@ 5,8 5,7 @@ from freshermeat.models import Project


class Release(db.Model):
    """Represent a release.
    """
    """Represent a release."""

    id = db.Column(db.Integer, primary_key=True)
    version = db.Column(db.String(), default="", nullable=False)

M freshermeat/models/submission.py => freshermeat/models/submission.py +1 -2
@@ 11,8 11,7 @@ association_table_license = db.Table(


class Submission(db.Model):
    """Represent a submission.
    """
    """Represent a submission."""

    id = db.Column(db.Integer, primary_key=True)
    project_name = db.Column(db.String(100), unique=True)

M freshermeat/notifications/notifications.py => freshermeat/notifications/notifications.py +1 -2
@@ 11,8 11,7 @@ from bootstrap import mail, application, instance_domain_name


def new_request_notification(request):
    """New request notification.
    """
    """New request notification."""
    subject = "[{service}] New request".format(service=request.service.name)
    platform_url = urllib.parse.urljoin(
        instance_domain_name(), url_for("admin_bp.view_request", request_id=request.id)

M freshermeat/scripts/import_github.py => freshermeat/scripts/import_github.py +2 -4
@@ 9,8 9,7 @@ from freshermeat.bootstrap import db, application


def import_project_from_github(owner, repo, submitter_id):
    """Imports a project hosted from GitHub.
    """
    """Imports a project hosted from GitHub."""
    url = "https://api.github.com/repos/{owner}/{repo}".format(owner=owner, repo=repo)
    url = "{api_url}?client_id={client_id}&client_secret={client_secret}".format(
        api_url=url,


@@ 73,8 72,7 @@ def import_project_from_github(owner, repo, submitter_id):


def import_starred_projects_from_github(user, link=""):
    """Imports the starred projects of a GitHub user.
    """
    """Imports the starred projects of a GitHub user."""
    if link != "":
        url = link
    else:

M freshermeat/scripts/import_gitlab.py => freshermeat/scripts/import_gitlab.py +1 -2
@@ 10,8 10,7 @@ from freshermeat.bootstrap import db, application


def import_project_from_gitlab(repository, submitter_id):
    """Imports a project hosted from GitLab.
    """
    """Imports a project hosted from GitLab."""
    url_parts = urlparse(repository)
    gitlab_instance = url_parts.netloc
    owner, repo = url_parts.path.strip("/").split("/")

M freshermeat/scripts/import_languages.py => freshermeat/scripts/import_languages.py +1 -2
@@ 8,8 8,7 @@ from freshermeat.bootstrap import db


def import_languages(json_file):
    """Imports a list of languages from a JSON file.
    """
    """Imports a list of languages from a JSON file."""
    with open(json_file) as json_file:
        languages = json.loads(json_file.read())
        for language in languages:

M freshermeat/web/views/api/v2/__init__.py => freshermeat/web/views/api/v2/__init__.py +6 -2
@@ 9,7 9,11 @@ api_blueprint = Blueprint("apiv2", __name__, url_prefix="/api/v2")

def setup_api(application):
    authorizations = {
        "apikey": {"type": "apiKey", "in": "header", "name": "X-API-KEY",}
        "apikey": {
            "type": "apiKey",
            "in": "header",
            "name": "X-API-KEY",
        }
    }

    api = Api(


@@ 21,7 25,7 @@ def setup_api(application):
        license_url="https://www.gnu.org/licenses/agpl-3.0.html",
        doc="/",
        security="apikey",
        authorizations=authorizations
        authorizations=authorizations,
    )

    @api.documentation

M freshermeat/web/views/api/v2/cve.py => freshermeat/web/views/api/v2/cve.py +16 -7
@@ 6,16 6,18 @@ from flask_restx import Namespace, Resource, fields, reqparse
from freshermeat.models import CVE


cve_ns = Namespace(
    "cve", description="CVE related operations"
)
cve_ns = Namespace("cve", description="CVE related operations")

# Argument Parsing
parser = reqparse.RequestParser()
parser.add_argument("cve_id", type=str, help="The id of the CVE.")
parser.add_argument("summary", type=str, help="The summary of the CVE.")
parser.add_argument("project_id", type=str, help="Id of the project related to the CVE.")
parser.add_argument("project_name", type=str, help="Name of the project related to the CVE.")
parser.add_argument(
    "project_id", type=str, help="Id of the project related to the CVE."
)
parser.add_argument(
    "project_name", type=str, help="Name of the project related to the CVE."
)
parser.add_argument("page", type=int, default=1, location="args")
parser.add_argument("per_page", type=int, location="args")



@@ 24,7 26,9 @@ parser.add_argument("per_page", type=int, location="args")
cve = cve_ns.model(
    "CVE",
    {
        "cve_id": fields.String(description="The id of the CVE.",),
        "cve_id": fields.String(
            description="The id of the CVE.",
        ),
        "summary": fields.String(description="The summary of the CVE."),
        "published_at": fields.DateTime(description="Date of publication of the CVE."),
    },


@@ 58,7 62,12 @@ class CVEsList(Resource):

        result = {
            "data": [],
            "metadata": {"total": 0, "count": 0, "page": page, "per_page": per_page,},
            "metadata": {
                "total": 0,
                "count": 0,
                "page": page,
                "per_page": per_page,
            },
        }

        try:

M freshermeat/web/views/api/v2/organization.py => freshermeat/web/views/api/v2/organization.py +18 -6
@@ 23,7 23,6 @@ parser.add_argument("page", type=int, default=1, location="args")
parser.add_argument("per_page", type=int, location="args")



# Response marshalling
organization = organization_ns.model(
    "Organization",


@@ 31,14 30,20 @@ organization = organization_ns.model(
        "id": fields.Integer(
            readonly=True, description="The organization unique identifier"
        ),
        "name": fields.String(description="Name of the organization.",),
        "description": fields.String(description="The description of the organization."),
        "name": fields.String(
            description="Name of the organization.",
        ),
        "description": fields.String(
            description="The description of the organization."
        ),
        "short_description": fields.String(
            description="The short descripton of the organization."
        ),
        "website": fields.String(description="The website of the organization."),
        "cve_vendor": fields.String(description="CVE vendor of the organization."),
        "last_updated": fields.DateTime(description="Last update time of the organization."),
        "last_updated": fields.DateTime(
            description="Last update time of the organization."
        ),
    },
)



@@ 48,7 53,9 @@ organization_list_fields = organization_ns.model(
        "metadata": fields.Raw(
            description="Metada related to the result (number of page, current page, total number of objects)."
        ),
        "data": fields.List(fields.Nested(organization), description="List of organizations"),
        "data": fields.List(
            fields.Nested(organization), description="List of organizations"
        ),
    },
)



@@ 70,7 77,12 @@ class OrganizationsList(Resource):

        result = {
            "data": [],
            "metadata": {"total": 0, "count": 0, "page": page, "per_page": per_page,},
            "metadata": {
                "total": 0,
                "count": 0,
                "page": page,
                "per_page": per_page,
            },
        }

        try:

M freshermeat/web/views/api/v2/project.py => freshermeat/web/views/api/v2/project.py +12 -5
@@ 29,7 29,9 @@ project = project_ns.model(
        "id": fields.Integer(
            readonly=True, description="The project unique identifier"
        ),
        "name": fields.String(description="Name of the project.",),
        "name": fields.String(
            description="Name of the project.",
        ),
        "description": fields.String(description="The description of the project."),
        "short_description": fields.String(
            description="The short descripton of the project."


@@ 71,7 73,12 @@ class ProjectsList(Resource):

        result = {
            "data": [],
            "metadata": {"total": 0, "count": 0, "page": page, "per_page": per_page,},
            "metadata": {
                "total": 0,
                "count": 0,
                "page": page,
                "per_page": per_page,
            },
        }

        try:


@@ 97,7 104,7 @@ class ProjectsList(Resource):
    @project_ns.doc("create_project")
    @project_ns.expect(project)
    @project_ns.marshal_with(project, code=201)
    @project_ns.doc(security='apikey')
    @project_ns.doc(security="apikey")
    @auth_func
    def post(self):
        """Create a new project"""


@@ 122,7 129,7 @@ class projectItem(Resource):

    @project_ns.doc("delete_project")
    @project_ns.response(204, "Project deleted")
    @project_ns.doc(security='apikey')
    @project_ns.doc(security="apikey")
    @auth_func
    def delete(self, id):
        """Delete a project given its identifier"""


@@ 131,7 138,7 @@ class projectItem(Resource):

    @project_ns.expect(project)
    @project_ns.marshal_with(project)
    @project_ns.doc(security='apikey')
    @project_ns.doc(security="apikey")
    @auth_func
    def put(self, id):
        """Update a project given its identifier"""

M freshermeat/web/views/organization.py => freshermeat/web/views/organization.py +7 -1
@@ 65,7 65,13 @@ def recent_releases(organization_name=None):
    if organization is None:
        abort(404)
    fg = FeedGenerator()
    fg.id(url_for("organization_bp.recent_releases", organization_name=organization.name, _external=True))
    fg.id(
        url_for(
            "organization_bp.recent_releases",
            organization_name=organization.name,
            _external=True,
        )
    )
    fg.title("Recent releases for {}".format(organization.name))
    fg.link(href=request.url, rel="self")
    for project in organization.projects:

M freshermeat/web/views/project.py => freshermeat/web/views/project.py +3 -1
@@ 167,7 167,9 @@ def recent_releases(project_name=None):
    if project is None:
        abort(404)
    fg = FeedGenerator()
    fg.id(url_for("project_bp.recent_releases", project_name=project.name, _external=True))
    fg.id(
        url_for("project_bp.recent_releases", project_name=project.name, _external=True)
    )
    fg.title("Recent releases for {}".format(project.name))
    fg.link(href=request.url, rel="self")
    for release in project.releases: