Normally, we fill the `workflow_job` data of the `GithubRunner` object
when the `workflow_job.in_progress` webhook event is delivered. [^1]
We use the `head_branch` value from this data at runtime endpoints to
validate the scope cache.
When this data is missing, we try to retrieve it from the GitHub API.
Since this operation can be costly, it's a good idea to persist the
result if the same job needs the same data before the webhook is
delivered. [^2]
Since the GitHub API doesn't have proper filtering, we fetch all jobs of
the workflow run and try to find the corresponding runner using the
`runner_name` property.
As another improvement, we can update the `workflow_job` column of the
all jobs we've already fetched. We can use code similar to this, but I
need to think more about it. It's not good practice to update resources
other than the prog's subject, so we should also prevent to overwrite
existing data.
```ruby
jobs.each do |job|
GithubRunner.where(id: UBID.to_uuid(job[:runner_name]), workflow_job: nil).update(workflow_job: Sequel.pg_jsonb(job.except("steps")))
end
```
[^1]: d4c19c2bec/routes/webhook/github.rb (L90)
[^2]: d4c19c2bec/routes/runtime/github.rb (L28)