0

How do I modify this API call to get the list of runs for the last 30 days?

Endpoint:

https://api.github.com/repos/[OWNER]/[REPO]/actions/runs

I tried:

https://github.infra.cloudera.com/api/v3/repos/[OWNER]/[REPO]/actions/runs?created=datetime.today() - timedelta(days=30)

and it didn't work.

Azeem
  • 11,148
  • 4
  • 27
  • 40
Swathi DA
  • 51
  • 4
  • Are you using Python to generate the date range? – Azeem Mar 06 '23 at 07:12
  • nope, I'm doing postman call – Swathi DA Mar 06 '23 at 07:23
  • These are Python APIs: `datetime.today() - timedelta(days=30)`. – Azeem Mar 06 '23 at 07:25
  • The date range should be like this `created=START..END`. See https://docs.github.com/en/search-github/getting-started-with-searching-on-github/understanding-the-search-syntax#query-for-values-between-a-range. – Azeem Mar 06 '23 at 07:26
  • what should start and end date to get API result for last 30 days – Swathi DA Mar 06 '23 at 07:35
  • That should be `?created=2023-02-04..2023-03-06`. Python example: https://godbolt.org/z/5hEGd9EMh – Azeem Mar 06 '23 at 08:21
  • According to [Query for values between a range](https://docs.github.com/en/search-github/getting-started-with-searching-on-github/understanding-the-search-syntax#query-for-values-between-a-range), "**You can use the range syntax `n..n` to search for values within a range, where the first number `n` is the lowest value and the second is the highest value.**" i.e. `range=lowest..highest`. – Azeem Mar 06 '23 at 08:23
  • Either `?created=2023-02-04..2023-03-06` or `?created=2023-02-04..*` should work. Please include any errors that you are getting in your question under an **UPDATE** section. Thanks! – Azeem Mar 06 '23 at 08:47

2 Answers2

1

With gh cli search for failed actions from the last 30 days and list the ids:

gh run list --jq ' .[]| select(.conclusion| contains("failure"))|

            select(.createdAt > (now-( 30 * 86400) | strftime("%Y-%m-%dT%H-%M-%SZ") ))|

            .databaseId' --json conclusion,databaseId,createdAt -R  <[OWNER]/[REPO]>

Check the output with:

gh run view <id> -R <[OWNER]/[REPO]>

Refine fields and conditions for purpose.

Gábor
  • 26
  • 2
0

You might be looking for "Workflow runs":

GET /repos/{owner}/{repo}/actions/workflows/{workflow_id}/runs

With created parameter and >=YYYY-MM-DD query

For example, you'd run

GET /repos/{owner}/{repo}/actions/workflows/{workflow_id}/runs?created=>=YYYY-MM-DD

And replace YYYY-MM-DD with your datetime output in this format

Fcmam5
  • 4,888
  • 1
  • 16
  • 33