SIGN IN SIGN UP

Make `TimingData.run_duration_ms` optional (#3268)

This PR aims to fix a bug that occurs when a user tries to request the
timing of a workflow run, the issue occurs because if the run failed
because of a badly formatted ci.yml file the field `run_duration_ms` is
not sent in the response of the API call.

As per the documentation
[here](https://docs.github.com/en/rest/actions/workflow-runs?apiVersion=2022-11-28#get-workflow-run-usage)
in the response body the field `run_duration_ms` is not required, see
the response schema below. This field is not present in the case for
example that the ci file for a workflow was badly formatted.

In the current implementation since it is accessing the dict that is the
data object returned from the request to the api using square brackets
if the key is not present it raises a key error.
The implementation on this branch fixes it by using `.get()` and setting
the default to None if it does not exist in the returned dict.

The PR includes a test to simulate this behaviour

```json
{
  "title": "Workflow Run Usage",
  "description": "Workflow Run Usage",
  "type": "object",
  "properties": {
    "billable": {
      "type": "object",
      ...
    },
    "run_duration_ms": {
      "type": "integer"
    }
  },
  "required": [
    "billable"
  ]
}
```

---------

Co-authored-by: Enrico Minack <github@enrico.minack.dev>
A
Alejandro Perez Gancedo committed
131949b3c12a89534874526bb812acdcd75c9db7
Parent: 0378cce
Committed by GitHub <noreply@github.com> on 7/30/2025, 4:45:52 PM