github webhooks

This commit is contained in:
Andras Bacsai
2023-05-09 14:42:10 +02:00
parent 19ad184cd6
commit 76bf601e1b
18 changed files with 217 additions and 20 deletions

View File

@@ -72,7 +72,7 @@ class GithubPrivateRepository extends Component
$this->repositories = collect();
$this->page = 1;
$this->github_app = GithubApp::where('id', $github_app_id)->first();
$this->token = generate_github_token($this->github_app);
$this->token = generate_github_installation_token($this->github_app);
$this->loadRepositoryByPage();
if ($this->repositories->count() < $this->total_repositories_count) {
while ($this->repositories->count() < $this->total_repositories_count) {
@@ -123,6 +123,7 @@ class GithubPrivateRepository extends Component
}
$application = Application::create([
'name' => "{$this->selected_repository_owner}/{$this->selected_repository_repo}:{$this->selected_branch_name}",
'project_id' => $this->selected_repository_id,
'git_repository' => "{$this->selected_repository_owner}/{$this->selected_repository_repo}",
'git_branch' => $this->selected_branch_name,
'build_pack' => 'nixpacks',

View File

@@ -469,7 +469,7 @@ COPY --from={$this->application->uuid}:{$this->git_commit}-build /app/{$this->ap
$this->execute_in_builder($git_clone_command)
];
} else {
$github_access_token = generate_github_token($this->source);
$github_access_token = generate_github_installation_token($this->source);
return [
$this->execute_in_builder("git clone -q -b {$this->application->git_branch} $source_html_url_scheme://x-access-token:$github_access_token@$source_html_url_host/{$this->application->git_repository}.git {$this->workdir}")
];

View File

@@ -24,6 +24,7 @@ class Application extends BaseModel
protected $fillable = [
'name',
'project_id',
'description',
'git_repository',
'git_branch',

View File

@@ -12,7 +12,10 @@ abstract class BaseModel extends Model
parent::boot();
static::creating(function (Model $model) {
$model->uuid = (string) new Cuid2(7);
// Generate a UUID if one isn't set
if (!$model->uuid) {
$model->uuid = (string) new Cuid2(7);
}
});
}
}

View File

@@ -4,7 +4,7 @@ namespace App\Models;
class GithubApp extends BaseModel
{
protected $fillable = ['name', 'organization', 'api_url', 'html_url', 'custom_user', 'custom_port', 'team_id'];
protected $fillable = ['name', 'uuid', 'organization', 'api_url', 'html_url', 'custom_user', 'custom_port', 'team_id'];
protected $casts = [
'is_public' => 'boolean',
];

View File

@@ -0,0 +1,14 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class GithubEventsApplications extends Model
{
protected $fillable = [
'delivery_guid',
'application_id',
];
}