I am new in azure devops and scripting. I want to auto abandon azure pull request after 2 weeks with no updates. I am able to list pull request, and do the status update. But looking for a powershell or bash script which can read the list command output, find out the date, and abandon pull request if no update for two week.
az repos pr list --repository "myrepo" --status "active"
az repos pr update --id "16729" --status "abandoned"
2
Answers
@Bowman Zhu-MSFT Helped me to resolve this issue, Thanks for guidance, and as he said "As long as you have ideas about how to deal with the problem, you can write code in any language you can to achieve your requirements. "I only tweaked some of the code, Like for header I am using different code, using az cli for abandon PR.
The below code can achieve your requirements.
The official REST API documents don’t have such data ‘last update time’ of Pull requests. The above code is based on network traffic interception and analysis. The above code has been tested by me and works very well on my side.
There may be a lot of code, I will share with you the ideas of how I code those here. These will help you understand the above code.
Steps:
1, get all of the pull requests information, especially the ‘id’.
https://learn.microsoft.com/en-us/rest/api/azure/devops/git/pull-requests/get-pull-requests?view=azure-devops-rest-6.0&tabs=HTTP
ID and Name in this REST API is equivalent.
2, Go to the pull request page and analyze.
Please notice that if you only create pull request but do nothing, last updated time in this place will be ‘null’, you need to use pull request ‘creation time’ in this situation.
3, calculate the difference between the last update time and the now time.
The most important is the second step, because only this place has the relevant information of last updated time of pull request.
As long as you have ideas about how to deal with the problem, you can write code in any language you can to achieve your requirements.