From 846bec4c474ccc246845e2ef870face3cfcdd527 Mon Sep 17 00:00:00 2001 From: Adrian Edwards Date: Sun, 28 Jun 2026 17:42:23 -0400 Subject: [PATCH 1/9] start creating a startup function to check for an empty forge_instance table Signed-off-by: Adrian Edwards --- collectoss/util/startup.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/collectoss/util/startup.py b/collectoss/util/startup.py index 8fe5b2374..f864a9dd1 100644 --- a/collectoss/util/startup.py +++ b/collectoss/util/startup.py @@ -219,6 +219,23 @@ def merge_config( config.load_config_from_dict(augmented_config) +def initialize_tables(engine, logger): + """Initialize certain tables with data that is requred for first run + + This includes: + - populating the forge_instances table with the core forges (github, gitlab) + - ensuring default repos are present + + Args: + engine (_type_): the database engine to use + logger (_type_): the logger instance to use + """ + + # Step 1: ensure theres at least one forge in forge_instances + with DatabaseSession(logger, engine=engine) as session: + + + all_instance_count = session.query(ForgeInstance).count() @deprecated("automatic import is deprecated. This is a function to warn users and help them transition") def warn_import_repos(logger): From b0c6dffbe2e11cc6ecbbc86fa19186b7259f60ab Mon Sep 17 00:00:00 2001 From: Adrian Edwards Date: Sun, 28 Jun 2026 18:04:24 -0400 Subject: [PATCH 2/9] ensure tables are populated on startup Signed-off-by: Adrian Edwards --- collectoss/util/startup.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/collectoss/util/startup.py b/collectoss/util/startup.py index f864a9dd1..86e8a22e3 100644 --- a/collectoss/util/startup.py +++ b/collectoss/util/startup.py @@ -9,6 +9,8 @@ import platform import sys +from collectoss.application.db.models.operations import ForgeInstance +from collectoss.util.enums import ForgePlatformType from sqlalchemy.orm.attributes import get_history from collectoss.application.config import SystemConfig from collectoss.application.db.session import DatabaseSession @@ -237,6 +239,29 @@ def initialize_tables(engine, logger): all_instance_count = session.query(ForgeInstance).count() + if all_instance_count == 0: + github_instance = ForgeInstance( + platform_type=ForgePlatformType.GITHUB.value, + name="GitHub (defualt)", + domain_name="github.com" + ) + session.add(github_instance) + session.commit() + + config = SystemConfig(logger, session) + + if config.get_value("Keys", "gitlab_api_key") not in [None, "fake"]: + + gitlab_instance = ForgeInstance( + platform_type=ForgePlatformType.GITLAB.value, + name="GitLab (defualt)", + domain_name="gitlab.com" + ) + session.add(gitlab_instance) + session.commit() + + # TODO: ensure default repos are present + @deprecated("automatic import is deprecated. This is a function to warn users and help them transition") def warn_import_repos(logger): """We are choosing not to auto import repos and repo groups automatically From 25930ccda062c5d26e49179ed0df0156979fc236 Mon Sep 17 00:00:00 2001 From: Adrian Edwards Date: Sun, 28 Jun 2026 18:05:56 -0400 Subject: [PATCH 3/9] call initialize_tables in preflight Signed-off-by: Adrian Edwards --- docker/backend/preflight.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docker/backend/preflight.py b/docker/backend/preflight.py index 4207db8b7..3ae7eb3bd 100755 --- a/docker/backend/preflight.py +++ b/docker/backend/preflight.py @@ -1,4 +1,4 @@ -from collectoss.util.startup import collect_env_variables, check_init_schema, check_update_schema, setup_facade_directory, merge_config, warn_import_repos, print_platform_information +from collectoss.util.startup import collect_env_variables, check_init_schema, check_update_schema, setup_facade_directory, merge_config, initialize_tables, warn_import_repos, print_platform_information from collectoss.application.logs import getFormatter from collectoss.application.cli import DatabaseContext import sys @@ -27,6 +27,8 @@ setup_facade_directory(logger) merge_config(DatabaseContext().engine, logger) + + initialize_tables(DatabaseContext().engine, logger) warn_import_repos(logger) From e976a64ba5399269774e43b457446f713ebe1950 Mon Sep 17 00:00:00 2001 From: Adrian Edwards Date: Mon, 29 Jun 2026 16:35:49 -0400 Subject: [PATCH 4/9] ensure default instances enabled by default Signed-off-by: Adrian Edwards --- collectoss/util/startup.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/collectoss/util/startup.py b/collectoss/util/startup.py index 86e8a22e3..d860251da 100644 --- a/collectoss/util/startup.py +++ b/collectoss/util/startup.py @@ -243,7 +243,8 @@ def initialize_tables(engine, logger): github_instance = ForgeInstance( platform_type=ForgePlatformType.GITHUB.value, name="GitHub (defualt)", - domain_name="github.com" + domain_name="github.com", + enabled=True ) session.add(github_instance) session.commit() @@ -255,7 +256,8 @@ def initialize_tables(engine, logger): gitlab_instance = ForgeInstance( platform_type=ForgePlatformType.GITLAB.value, name="GitLab (defualt)", - domain_name="gitlab.com" + domain_name="gitlab.com", + enabled=True ) session.add(gitlab_instance) session.commit() From 3544e446447c209a041c0029b8c67969e15f6eb6 Mon Sep 17 00:00:00 2001 From: Adrian Edwards Date: Mon, 29 Jun 2026 16:40:34 -0400 Subject: [PATCH 5/9] also unconditionally add gitlab as an option Intelligently detecting it based on key presence at first startup is just too niche a condition/too rare and will make user support more painful. Instead the "whether we queue these tasks" logic should rely on both "is the instance enabled" AND "do we have keys" separately Signed-off-by: Adrian Edwards --- collectoss/util/startup.py | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/collectoss/util/startup.py b/collectoss/util/startup.py index d860251da..aa4555c43 100644 --- a/collectoss/util/startup.py +++ b/collectoss/util/startup.py @@ -249,19 +249,14 @@ def initialize_tables(engine, logger): session.add(github_instance) session.commit() - config = SystemConfig(logger, session) - - if config.get_value("Keys", "gitlab_api_key") not in [None, "fake"]: - - gitlab_instance = ForgeInstance( - platform_type=ForgePlatformType.GITLAB.value, - name="GitLab (defualt)", - domain_name="gitlab.com", - enabled=True - ) - session.add(gitlab_instance) - session.commit() - + gitlab_instance = ForgeInstance( + platform_type=ForgePlatformType.GITLAB.value, + name="GitLab (defualt)", + domain_name="gitlab.com", + enabled=True + ) + session.add(gitlab_instance) + session.commit() # TODO: ensure default repos are present @deprecated("automatic import is deprecated. This is a function to warn users and help them transition") @@ -285,4 +280,4 @@ def warn_import_repos(logger): def print_platform_information(logger): logger.info(f"PATH: {os.environ.get('PATH')}") logger.info(f"Python executable (current): {sys.executable}") - logger.info(f"Python version: {platform.python_version()}") \ No newline at end of file + logger.info(f"Python version: {platform.python_version()}") From 9e8a45d971e7e8a095993633a5881cf4e43a1bfe Mon Sep 17 00:00:00 2001 From: Adrian Edwards Date: Mon, 16 Nov 2026 12:18:32 -0500 Subject: [PATCH 6/9] populate compliance fields for the two default forges on new CollectOSS instances Signed-off-by: Adrian Edwards --- collectoss/util/startup.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/collectoss/util/startup.py b/collectoss/util/startup.py index aa4555c43..ae2a1a598 100644 --- a/collectoss/util/startup.py +++ b/collectoss/util/startup.py @@ -9,6 +9,9 @@ import platform import sys +from datetime import datetime +from zoneinfo import ZoneInfo + from collectoss.application.db.models.operations import ForgeInstance from collectoss.util.enums import ForgePlatformType from sqlalchemy.orm.attributes import get_history @@ -244,6 +247,13 @@ def initialize_tables(engine, logger): platform_type=ForgePlatformType.GITHUB.value, name="GitHub (defualt)", domain_name="github.com", + privacy_url = "https://docs.github.com/en/site-policy/privacy-policies/github-general-privacy-statement", + terms_url = "https://docs.github.com/en/site-policy/github-terms/github-terms-of-service", + policy_reviewed_date = datetime(2026, 10, 12, tzinfo=ZoneInfo("America/New_York")), + policy_reviewed_by = "CollectOSS Maintainers", + policy_review_comments = "CollectOSS primarily accesses public information from GitHub. Terms state: " + "\"Depending on your account settings, we may share Personal Data with other users of the Services " + " and the public. You control what information is made public.\"", enabled=True ) session.add(github_instance) @@ -253,6 +263,13 @@ def initialize_tables(engine, logger): platform_type=ForgePlatformType.GITLAB.value, name="GitLab (defualt)", domain_name="gitlab.com", + privacy_url = "https://about.gitlab.com/privacy/", + terms_url = "https://about.gitlab.com/terms/", + policy_reviewed_date = datetime(2026, 11, 16, tzinfo=ZoneInfo("America/New_York")), + policy_reviewed_by = "CollectOSS Maintainers", + policy_review_comments = "CollectOSS primarily accesses public information from GitLab. Terms state: " + "\"We may share your Personal Data with other users of the Services and with the public if you " + "choose to make your SaaS Profile public. You have control over what information is public;\"", enabled=True ) session.add(gitlab_instance) From b535c2f62d7809638ec3e2b5506d5c831ee54eb7 Mon Sep 17 00:00:00 2001 From: Adrian Edwards Date: Mon, 16 Nov 2026 13:55:26 -0500 Subject: [PATCH 7/9] create migration to add the default instances to the forge_instances table This covers existing instances. Signed-off-by: Adrian Edwards --- .../47_populate_default_data_for_forge_.py | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 collectoss/application/schema/alembic/versions/47_populate_default_data_for_forge_.py diff --git a/collectoss/application/schema/alembic/versions/47_populate_default_data_for_forge_.py b/collectoss/application/schema/alembic/versions/47_populate_default_data_for_forge_.py new file mode 100644 index 000000000..a78aa76c6 --- /dev/null +++ b/collectoss/application/schema/alembic/versions/47_populate_default_data_for_forge_.py @@ -0,0 +1,109 @@ +"""Populate default data for forge_instances table + +Revision ID: 47 +Revises: 46 +Create Date: 2026-11-16 12:19:48.031786 + +""" +from alembic import op +import sqlalchemy as sa + +from sqlalchemy import Column, Integer, String, Boolean, DateTime, func +from sqlalchemy.orm import relationship, DeclarativeBase, Session + +from enum import Enum +from datetime import datetime +from zoneinfo import ZoneInfo + +# revision identifiers, used by Alembic. +revision = '47' +down_revision = '46' +branch_labels = None +depends_on = None + +# Normally we dont allow migrations to create/modify data in a database except as part of structural schema changes +# however, we anticipate a future migration to adjust foreign keys to rely on this table instead, and need to +# effectively gaurantee the data exists prior to that migration existing in a way that is automatic for most instances. + + +# We include a copy of the forge_instance schema definition and other relevant types here because it may change in the future and we need to be accurate +# to what the state of a CollectOSS instance is going to be prior to this migration + + +class ForgePlatformType(Enum): + """Identification values for different known forges. + Intended for helping identify the relevant API endpoints and tasks to use for collection""" + UNRESOLVEABLE = 0 + GITHUB = 1 + GITLAB = 2 + +class Base(DeclarativeBase): + pass + +class ForgeInstance(Base): + __tablename__ = "forge_instance" + __table_args__ = { "schema": "operations" } + + id = Column(Integer, primary_key=True, nullable=False, comment="Internal unique identifier for this forge instance") + # platform_type stores an integer that CollectOSS maps/will map to it's internal platform identifier Enum + # (as used in ContributorUUID) for identifying the API endpoints and tasks to use for collection + platform_type = Column(Integer, nullable=False, comment="Type specifier identifying the relevant platform API interface to CollectOSS") + name = Column(String, nullable=False, comment="User-specified name for this forge instance") + # https://stackoverflow.com/a/54800233 + date_added = Column(DateTime(timezone=True), nullable=False, default=func.now()) + domain_name = Column(String, nullable=False, comment="The base domain name (without the scheme) where this instance is hosted") + enabled = Column(Boolean, default=True, nullable=False, comment="denotes whether collection should run for this instance") + privacy_url = Column(String, nullable=False, comment="The link to the privacy policy for this instance") + terms_url = Column(String, nullable=False, comment="The link to the terms of service for this instance") + policy_reviewed_date = Column(DateTime(timezone=True), nullable=False, default=func.now()) + policy_reviewed_by = Column(String, nullable=False, comment="Who conducted the last review of these policies") + policy_review_comments = Column(String, nullable=True, comment="Reviewer comments from the most recent policy review.") + api_keys = relationship("WorkerOauth") + +# these are the default definitions for forge instance objects in the DB provided by CollectOSS maintainers. +# Future instances will likely be added by instance operators, not via migrations +DEFAULT_FORGES = [ + ForgeInstance( + platform_type=ForgePlatformType.GITHUB.value, + name="GitHub (defualt)", + domain_name="github.com", + privacy_url = "https://docs.github.com/en/site-policy/privacy-policies/github-general-privacy-statement", + terms_url = "https://docs.github.com/en/site-policy/github-terms/github-terms-of-service", + policy_reviewed_date = datetime(2026, 10, 12, tzinfo=ZoneInfo("America/New_York")), + policy_reviewed_by = "CollectOSS Maintainers", + policy_review_comments = "CollectOSS primarily accesses public information from GitHub. Terms state: " + "\"Depending on your account settings, we may share Personal Data with other users of the Services " + " and the public. You control what information is made public.\"", + enabled=True + ), + ForgeInstance( + platform_type=ForgePlatformType.GITLAB.value, + name="GitLab (defualt)", + domain_name="gitlab.com", + privacy_url = "https://about.gitlab.com/privacy/", + terms_url = "https://about.gitlab.com/terms/", + policy_reviewed_date = datetime(2026, 11, 16, tzinfo=ZoneInfo("America/New_York")), + policy_reviewed_by = "CollectOSS Maintainers", + policy_review_comments = "CollectOSS primarily accesses public information from GitLab. Terms state: " + "\"We may share your Personal Data with other users of the Services and with the public if you " + "choose to make your SaaS Profile public. You have control over what information is public;\"", + enabled=True + ) +] + +def upgrade(): + bind = op.get_bind() + session = Session(bind=bind) + + session.add_all(DEFAULT_FORGES) + session.flush() + + +def downgrade(): + bind = op.get_bind() + session = Session(bind=bind) + + # Delete only the rows you seeded (skip this if downgrade drops the whole table) + forge_ids = [forge.id for forge in DEFAULT_FORGES] + session.execute(sa.delete(ForgeInstance).where(ForgeInstance.id.in_(forge_ids))) + session.flush() From cdac57fc6bb3f9c511a6a22958403511099ed32a Mon Sep 17 00:00:00 2001 From: Adrian Edwards Date: Mon, 16 Nov 2026 14:38:46 -0500 Subject: [PATCH 8/9] oauth link hasnt yet been established and doesnt matter here Signed-off-by: Adrian Edwards --- .../alembic/versions/47_populate_default_data_for_forge_.py | 1 - 1 file changed, 1 deletion(-) diff --git a/collectoss/application/schema/alembic/versions/47_populate_default_data_for_forge_.py b/collectoss/application/schema/alembic/versions/47_populate_default_data_for_forge_.py index a78aa76c6..aaad80d97 100644 --- a/collectoss/application/schema/alembic/versions/47_populate_default_data_for_forge_.py +++ b/collectoss/application/schema/alembic/versions/47_populate_default_data_for_forge_.py @@ -58,7 +58,6 @@ class ForgeInstance(Base): policy_reviewed_date = Column(DateTime(timezone=True), nullable=False, default=func.now()) policy_reviewed_by = Column(String, nullable=False, comment="Who conducted the last review of these policies") policy_review_comments = Column(String, nullable=True, comment="Reviewer comments from the most recent policy review.") - api_keys = relationship("WorkerOauth") # these are the default definitions for forge instance objects in the DB provided by CollectOSS maintainers. # Future instances will likely be added by instance operators, not via migrations From e5dfd6e842c05f3c9c1337922a0ffa6b06de4f3f Mon Sep 17 00:00:00 2001 From: Adrian Edwards Date: Mon, 16 Nov 2026 18:05:26 -0500 Subject: [PATCH 9/9] fix typos Signed-off-by: Adrian Edwards --- .../alembic/versions/47_populate_default_data_for_forge_.py | 6 +++--- collectoss/util/startup.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/collectoss/application/schema/alembic/versions/47_populate_default_data_for_forge_.py b/collectoss/application/schema/alembic/versions/47_populate_default_data_for_forge_.py index aaad80d97..28ff8377a 100644 --- a/collectoss/application/schema/alembic/versions/47_populate_default_data_for_forge_.py +++ b/collectoss/application/schema/alembic/versions/47_populate_default_data_for_forge_.py @@ -23,7 +23,7 @@ # Normally we dont allow migrations to create/modify data in a database except as part of structural schema changes # however, we anticipate a future migration to adjust foreign keys to rely on this table instead, and need to -# effectively gaurantee the data exists prior to that migration existing in a way that is automatic for most instances. +# effectively guarantee the data exists prior to that migration existing in a way that is automatic for most instances. # We include a copy of the forge_instance schema definition and other relevant types here because it may change in the future and we need to be accurate @@ -64,7 +64,7 @@ class ForgeInstance(Base): DEFAULT_FORGES = [ ForgeInstance( platform_type=ForgePlatformType.GITHUB.value, - name="GitHub (defualt)", + name="GitHub (default)", domain_name="github.com", privacy_url = "https://docs.github.com/en/site-policy/privacy-policies/github-general-privacy-statement", terms_url = "https://docs.github.com/en/site-policy/github-terms/github-terms-of-service", @@ -77,7 +77,7 @@ class ForgeInstance(Base): ), ForgeInstance( platform_type=ForgePlatformType.GITLAB.value, - name="GitLab (defualt)", + name="GitLab (default)", domain_name="gitlab.com", privacy_url = "https://about.gitlab.com/privacy/", terms_url = "https://about.gitlab.com/terms/", diff --git a/collectoss/util/startup.py b/collectoss/util/startup.py index ae2a1a598..e9f64851e 100644 --- a/collectoss/util/startup.py +++ b/collectoss/util/startup.py @@ -225,7 +225,7 @@ def merge_config( config.load_config_from_dict(augmented_config) def initialize_tables(engine, logger): - """Initialize certain tables with data that is requred for first run + """Initialize certain tables with data that is required for first run This includes: - populating the forge_instances table with the core forges (github, gitlab) @@ -245,7 +245,7 @@ def initialize_tables(engine, logger): if all_instance_count == 0: github_instance = ForgeInstance( platform_type=ForgePlatformType.GITHUB.value, - name="GitHub (defualt)", + name="GitHub (default)", domain_name="github.com", privacy_url = "https://docs.github.com/en/site-policy/privacy-policies/github-general-privacy-statement", terms_url = "https://docs.github.com/en/site-policy/github-terms/github-terms-of-service", @@ -261,7 +261,7 @@ def initialize_tables(engine, logger): gitlab_instance = ForgeInstance( platform_type=ForgePlatformType.GITLAB.value, - name="GitLab (defualt)", + name="GitLab (default)", domain_name="gitlab.com", privacy_url = "https://about.gitlab.com/privacy/", terms_url = "https://about.gitlab.com/terms/",