Files
ubicloud/prog/github/destroy_github_installation.rb
Jeremy Evans 4b819d3cb2 Change all create_with_id to create
It hasn't been necessary to use create_with_id since
ebc79622df, in December 2024.

I have plans to introduce:

```ruby
def create_with_id(id, values)
  obj = new(values)
  obj.id = id
  obj.save_changes
end
```

This will make it easier to use the same id when creating
multiple objects.  The first step is removing the existing
uses of create_with_id.
2025-08-06 01:55:51 +09:00

52 lines
1.2 KiB
Ruby

# frozen_string_literal: true
require_relative "../../lib/util"
class Prog::Github::DestroyGithubInstallation < Prog::Base
subject_is :github_installation
def self.assemble(installation)
Strand.create(
prog: "Github::DestroyGithubInstallation",
label: "start",
stack: [{"subject_id" => installation.id}]
)
end
label def before_run
pop "github installation is destroyed" unless github_installation
end
label def start
register_deadline(nil, 10 * 60)
hop_delete_installation
end
label def delete_installation
begin
Github.app_client.delete_installation(github_installation.installation_id)
rescue Octokit::NotFound
end
hop_destroy_resources
end
label def destroy_resources
github_installation.repositories.map(&:incr_destroy)
github_installation.runners.map do |runner|
runner.incr_skip_deregistration
runner.incr_destroy
end
hop_destroy
end
label def destroy
nap 10 unless github_installation.runners_dataset.empty?
nap 10 unless github_installation.repositories_dataset.empty?
github_installation.destroy
Clog.emit("GithubInstallation is deleted.") { github_installation }
pop "github installation destroyed"
end
end