Label API: Get the date when a label was added to an issue. #24630
-
I am looking for a way to get the date/time a label was added to an issue in order to determine how long something has been labeled “needs review” (for example). It would be great if this endpoint returned the date of the labels added.
Or is there any other way to do this through the API? |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments
-
Hi @dereksmart, Thanks for reaching out! There is a way in v4 using createdAt like in the query below, maybe someone else has found another way but I hope this helps!
|
Beta Was this translation helpful? Give feedback.
-
@andreagriffiths11 Thanks for the reply, but |
Beta Was this translation helpful? Give feedback.
-
Hey @dereksmart! I believe this is possible by using the Timeline APIs (v3, v4 from the timeline connection). Using the REST API, I’m able to query:
This gives me a list of events, including “labeled” events that have a “created_at” property that should indicate when the label was added. Let me know if this helps! |
Beta Was this translation helpful? Give feedback.
-
Hi @nickvanw - thanks for the reply. Yes, Timeline seems to be the best way to go here. Without having to send multiple requests (one per issue/PR), this is the best I’ve come up with so far for getting multiple issue timelines in a single request:
And then whatever is consuming the response will need to do some maual filtering and calculations to see if the label is still applied, and get the date from the last applied instance. Suggestions welcome on how I could simplify this! |
Beta Was this translation helpful? Give feedback.
-
Hey @dereksmart! That looks good to me! If I have one suggestion, it might be to use the pullRequest.timelineItems connection that’s currently in preview: https://developer.github.com/v4/previews/#issues-preview This connection allows filtering the timeline down to a specific list of items, so you could do something like this:
Some manual filtering will still be required, but this means that you’ll get less noise in your query. |
Beta Was this translation helpful? Give feedback.
-
timelineItems is a beautiful suggestion. Thank you! |
Beta Was this translation helpful? Give feedback.
-
Best workaround so far nickvanw@, thank you. I hope they plan to make this easier to query down the road. |
Beta Was this translation helpful? Give feedback.
Hey @dereksmart!
That looks good to me! If I have one suggestion, it might be to use the pullRequest.timelineItems connection that’s currently in preview: https://developer.github.com/v4/previews/#issues-preview
This connection allows filtering the timeline down to a specific list of items, so you could do something like this: