Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Yes, here's an example Bash script that retrieves the list of modified or added files in a Github pull request using the Github API and the jq command-line JSON processor:

#!/bin/bash

# Set your Github username and API token
username="your_github_username"
token="your_github_api_token"

# Set the Github repository owner and name
owner="repo_owner"
repo="repo_name"

# Set the pull request number
pull_request_number="123"

# Retrieve the list of modified or added files in the pull request
response=$(curl -s -H "Authorization: token $token" "https://api.github.com/repos/$owner/$repo/pulls/$pull_request_number/files")
files=$(echo $response | jq -r '.[] | select(.status == "modified" or .status == "added") | .filename')

# Print the list of files
echo $files

Replace the placeholders your_github_username, your_github_api_token, repo_owner, repo_name, and 123 with your own values. You can obtain a Github API token by going to your Github settings and creating a new token with the repo scope.

The script first uses the curl command to retrieve the list of files in the pull request using the Github API. The -s flag tells curl to run silently and not display progress or error messages. The -H flag sets the Authorization header to include the Github API token. The response is then piped to jq which filters the list of files to only include those with a status of modified or added, and extracts the filename field.

Finally, the script prints the list of files using the echo command. You can modify the script to perform additional actions on these files, such as running tests or performing linting.