Skip to content

How to get most recent successful deployment by REST #24484

Discussion options

You must be logged in to vote

Thanks Andrea,

I’ve actually realised it’s much easier to solve with GraphQL. In case it helps anyone in future, the following query does the trick:

query($repo\_owner:String!, $repo\_name:String!, $deployment\_env:String!) {  
 repository(owner: $repo\_owner, name: $repo\_name) {  
 deployments(environments: [$deployment\_env], first: 30) {  
 edges {  
 cursor  
 node {  
 state  
 commit {  
 oid  
 }  
 }  
 }  
 }  
 }  
}

And then it’s just a case of finding the first node in the returned result that has state === ‘ACTIVE’.

Obviously this could also be done with a smaller page size and then load the next page in the unlikely event there’s loads of failed / pending / whatever deploy…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@bel0v
Comment options

Answer selected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants