Get list of files on pull request merge #26604
-
If I have the following workflow to trigger on a pull request merge:
What is the best way to get a list of files in the PR? |
Beta Was this translation helpful? Give feedback.
Replies: 9 comments
-
You can use rest api to get the file list of pull request. Please refer to the link for more details. Code sample as below, use jq to filter the filename.
|
Beta Was this translation helpful? Give feedback.
-
Hi @weide-zhou. Your snippet was very helpful, but I’m having some trouble and I don’t understand why, could you help me? |
Beta Was this translation helpful? Give feedback.
-
Hi @luchiago , The error is due to no json file changes in your pull request, which caused command ’FILES=$(curl … | | grep -E ‘.(json)$’)‘ to be failed. You can check in this way:
Thanks. |
Beta Was this translation helpful? Give feedback.
-
Thanks @weide-zhou. It worked |
Beta Was this translation helpful? Give feedback.
-
weide-zhou:
Hi @weide-zhou Thanks for your reply. It’s very helpful but I’m getting error like Thanks |
Beta Was this translation helpful? Give feedback.
-
I notice you parsed ‘.json’ in your jq filter, it should be ‘.filename’ from the curl command. I confirmed the script works on my side. Basically you can check the curl command without jq, check the response body, and then use jq to filter the file. If i checked the incorrect workflow, please let me know. Thanks |
Beta Was this translation helpful? Give feedback.
-
Hi @weide-zhou , I am seeing the same error, below is the command I am running. I am using a private repo, do we have to include some sort of authentication in the curl command so it takes the GITHUB_TOKEN?
Can you please help me figure out what I am doing wrong? Thanks, |
Beta Was this translation helpful? Give feedback.
-
ksrisurapaneni:
Yes, you’ll need to pass
|
Beta Was this translation helpful? Give feedback.
-
Hi @mattt , thank you for responding. Your command works perfectly for pull events since the URL is taking info from a pull API. But it fails for push events or when we merge the PR. So, I am using the below instead which works for both pull and push events: github.comjitterbit/get-changed-filesGet all of the files changed/modified in a pull request or push's commits. Thank you, |
Beta Was this translation helpful? Give feedback.
Hi @luchiago ,
The error is due to no json file changes in your pull request, which caused command ’FILES=$(curl … | | grep -E ‘.(json)$’)‘ to be failed.
You can check in this way:
Thanks.