Add Gitea sync service with full and incremental modes, paged API fetch, upsert logic for users/repos/commits/PRs, and error aggregation. Add migration for git_users, git_repositories, git_commits, git_pull_requests with indexes and unique constraints; add models and sync scripts for full/incremental jobs. Update Gitea UI and dashboard filters (user/repo/date), aggregate commit loading across repositories, and wire routes/controllers/sidebar for dashboard and sync endpoints.
340 lines
7.1 KiB
PHP
340 lines
7.1 KiB
PHP
<?php
|
|
|
|
namespace App\Database\Migrations;
|
|
|
|
use CodeIgniter\Database\Migration;
|
|
|
|
class CreateGitTables extends Migration
|
|
{
|
|
public function up()
|
|
{
|
|
$this->forge->addField([
|
|
'id' => [
|
|
'type' => 'BIGINT',
|
|
'constraint' => 20,
|
|
'unsigned' => true,
|
|
'auto_increment' => true,
|
|
],
|
|
'gitea_user_id' => [
|
|
'type' => 'BIGINT',
|
|
'constraint' => 20,
|
|
'unsigned' => true,
|
|
'null' => false,
|
|
],
|
|
'username' => [
|
|
'type' => 'VARCHAR',
|
|
'constraint' => 100,
|
|
],
|
|
'full_name' => [
|
|
'type' => 'VARCHAR',
|
|
'constraint' => 255,
|
|
'null' => true,
|
|
],
|
|
'email' => [
|
|
'type' => 'VARCHAR',
|
|
'constraint' => 255,
|
|
'null' => true,
|
|
],
|
|
'avatar_url' => [
|
|
'type' => 'TEXT',
|
|
'null' => true,
|
|
],
|
|
'is_active' => [
|
|
'type' => 'TINYINT',
|
|
'constraint' => 1,
|
|
'default' => 1,
|
|
],
|
|
'is_admin' => [
|
|
'type' => 'TINYINT',
|
|
'constraint' => 1,
|
|
'default' => 0,
|
|
],
|
|
'last_synced_at' => [
|
|
'type' => 'DATETIME',
|
|
'null' => true,
|
|
],
|
|
'created_at' => [
|
|
'type' => 'DATETIME',
|
|
'null' => true,
|
|
],
|
|
'updated_at' => [
|
|
'type' => 'DATETIME',
|
|
'null' => true,
|
|
],
|
|
]);
|
|
$this->forge->addKey('id', true);
|
|
$this->forge->addUniqueKey('gitea_user_id');
|
|
$this->forge->addUniqueKey('username');
|
|
$this->forge->createTable('git_users', true);
|
|
|
|
$this->forge->addField([
|
|
'id' => [
|
|
'type' => 'BIGINT',
|
|
'constraint' => 20,
|
|
'unsigned' => true,
|
|
'auto_increment' => true,
|
|
],
|
|
'gitea_repo_id' => [
|
|
'type' => 'BIGINT',
|
|
'constraint' => 20,
|
|
'unsigned' => true,
|
|
'null' => false,
|
|
],
|
|
'owner_user_id' => [
|
|
'type' => 'BIGINT',
|
|
'constraint' => 20,
|
|
'unsigned' => true,
|
|
'null' => true,
|
|
],
|
|
'owner_username' => [
|
|
'type' => 'VARCHAR',
|
|
'constraint' => 100,
|
|
'null' => true,
|
|
],
|
|
'name' => [
|
|
'type' => 'VARCHAR',
|
|
'constraint' => 150,
|
|
],
|
|
'full_name' => [
|
|
'type' => 'VARCHAR',
|
|
'constraint' => 255,
|
|
],
|
|
'description' => [
|
|
'type' => 'TEXT',
|
|
'null' => true,
|
|
],
|
|
'html_url' => [
|
|
'type' => 'TEXT',
|
|
'null' => true,
|
|
],
|
|
'clone_url' => [
|
|
'type' => 'TEXT',
|
|
'null' => true,
|
|
],
|
|
'default_branch' => [
|
|
'type' => 'VARCHAR',
|
|
'constraint' => 100,
|
|
'null' => true,
|
|
],
|
|
'is_private' => [
|
|
'type' => 'TINYINT',
|
|
'constraint' => 1,
|
|
'default' => 0,
|
|
],
|
|
'is_archived' => [
|
|
'type' => 'TINYINT',
|
|
'constraint' => 1,
|
|
'default' => 0,
|
|
],
|
|
'is_fork' => [
|
|
'type' => 'TINYINT',
|
|
'constraint' => 1,
|
|
'default' => 0,
|
|
],
|
|
'open_issues_count' => [
|
|
'type' => 'INT',
|
|
'constraint' => 11,
|
|
'default' => 0,
|
|
],
|
|
'stars_count' => [
|
|
'type' => 'INT',
|
|
'constraint' => 11,
|
|
'default' => 0,
|
|
],
|
|
'forks_count' => [
|
|
'type' => 'INT',
|
|
'constraint' => 11,
|
|
'default' => 0,
|
|
],
|
|
'watchers_count' => [
|
|
'type' => 'INT',
|
|
'constraint' => 11,
|
|
'default' => 0,
|
|
],
|
|
'last_pushed_at' => [
|
|
'type' => 'DATETIME',
|
|
'null' => true,
|
|
],
|
|
'last_synced_at' => [
|
|
'type' => 'DATETIME',
|
|
'null' => true,
|
|
],
|
|
'created_at' => [
|
|
'type' => 'DATETIME',
|
|
'null' => true,
|
|
],
|
|
'updated_at' => [
|
|
'type' => 'DATETIME',
|
|
'null' => true,
|
|
],
|
|
]);
|
|
$this->forge->addKey('id', true);
|
|
$this->forge->addUniqueKey('gitea_repo_id');
|
|
$this->forge->addUniqueKey('full_name');
|
|
$this->forge->addKey('owner_user_id');
|
|
$this->forge->createTable('git_repositories', true);
|
|
|
|
$this->forge->addField([
|
|
'id' => [
|
|
'type' => 'BIGINT',
|
|
'constraint' => 20,
|
|
'unsigned' => true,
|
|
'auto_increment' => true,
|
|
],
|
|
'repository_id' => [
|
|
'type' => 'BIGINT',
|
|
'constraint' => 20,
|
|
'unsigned' => true,
|
|
'null' => false,
|
|
],
|
|
'author_user_id' => [
|
|
'type' => 'BIGINT',
|
|
'constraint' => 20,
|
|
'unsigned' => true,
|
|
'null' => true,
|
|
],
|
|
'sha' => [
|
|
'type' => 'VARCHAR',
|
|
'constraint' => 64,
|
|
],
|
|
'short_sha' => [
|
|
'type' => 'VARCHAR',
|
|
'constraint' => 12,
|
|
'null' => true,
|
|
],
|
|
'message' => [
|
|
'type' => 'LONGTEXT',
|
|
'null' => true,
|
|
],
|
|
'author_name' => [
|
|
'type' => 'VARCHAR',
|
|
'constraint' => 255,
|
|
'null' => true,
|
|
],
|
|
'author_email' => [
|
|
'type' => 'VARCHAR',
|
|
'constraint' => 255,
|
|
'null' => true,
|
|
],
|
|
'committed_at' => [
|
|
'type' => 'DATETIME',
|
|
'null' => true,
|
|
],
|
|
'html_url' => [
|
|
'type' => 'TEXT',
|
|
'null' => true,
|
|
],
|
|
'created_at' => [
|
|
'type' => 'DATETIME',
|
|
'null' => true,
|
|
],
|
|
'updated_at' => [
|
|
'type' => 'DATETIME',
|
|
'null' => true,
|
|
],
|
|
]);
|
|
$this->forge->addKey('id', true);
|
|
$this->forge->addUniqueKey(['repository_id', 'sha']);
|
|
$this->forge->addKey('repository_id');
|
|
$this->forge->addKey('author_user_id');
|
|
$this->forge->addKey('committed_at');
|
|
$this->forge->createTable('git_commits', true);
|
|
|
|
$this->forge->addField([
|
|
'id' => [
|
|
'type' => 'BIGINT',
|
|
'constraint' => 20,
|
|
'unsigned' => true,
|
|
'auto_increment' => true,
|
|
],
|
|
'gitea_pr_id' => [
|
|
'type' => 'BIGINT',
|
|
'constraint' => 20,
|
|
'unsigned' => true,
|
|
'null' => false,
|
|
],
|
|
'repository_id' => [
|
|
'type' => 'BIGINT',
|
|
'constraint' => 20,
|
|
'unsigned' => true,
|
|
'null' => false,
|
|
],
|
|
'author_user_id' => [
|
|
'type' => 'BIGINT',
|
|
'constraint' => 20,
|
|
'unsigned' => true,
|
|
'null' => true,
|
|
],
|
|
'number' => [
|
|
'type' => 'INT',
|
|
'constraint' => 11,
|
|
],
|
|
'title' => [
|
|
'type' => 'TEXT',
|
|
],
|
|
'body' => [
|
|
'type' => 'LONGTEXT',
|
|
'null' => true,
|
|
],
|
|
'state' => [
|
|
'type' => 'VARCHAR',
|
|
'constraint' => 30,
|
|
'default' => 'open',
|
|
],
|
|
'is_draft' => [
|
|
'type' => 'TINYINT',
|
|
'constraint' => 1,
|
|
'default' => 0,
|
|
],
|
|
'is_merged' => [
|
|
'type' => 'TINYINT',
|
|
'constraint' => 1,
|
|
'default' => 0,
|
|
],
|
|
'merged_at' => [
|
|
'type' => 'DATETIME',
|
|
'null' => true,
|
|
],
|
|
'closed_at' => [
|
|
'type' => 'DATETIME',
|
|
'null' => true,
|
|
],
|
|
'created_at_gitea' => [
|
|
'type' => 'DATETIME',
|
|
'null' => true,
|
|
],
|
|
'updated_at_gitea' => [
|
|
'type' => 'DATETIME',
|
|
'null' => true,
|
|
],
|
|
'html_url' => [
|
|
'type' => 'TEXT',
|
|
'null' => true,
|
|
],
|
|
'created_at' => [
|
|
'type' => 'DATETIME',
|
|
'null' => true,
|
|
],
|
|
'updated_at' => [
|
|
'type' => 'DATETIME',
|
|
'null' => true,
|
|
],
|
|
]);
|
|
$this->forge->addKey('id', true);
|
|
$this->forge->addUniqueKey('gitea_pr_id');
|
|
$this->forge->addKey('repository_id');
|
|
$this->forge->addKey('author_user_id');
|
|
$this->forge->addKey('state');
|
|
$this->forge->addKey('updated_at_gitea');
|
|
$this->forge->createTable('git_pull_requests', true);
|
|
}
|
|
|
|
public function down()
|
|
{
|
|
$this->forge->dropTable('git_pull_requests', true);
|
|
$this->forge->dropTable('git_commits', true);
|
|
$this->forge->dropTable('git_repositories', true);
|
|
$this->forge->dropTable('git_users', true);
|
|
}
|
|
}
|