Ask Your Question
2

Can you provide a roster of recently modified or added files in a Github pull request utilizing a Bash script?

asked 2023-07-14 19:40:47 +0000

plato gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-07-14 19:50:02 +0000

devzero gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-07-14 19:40:47 +0000

Seen: 14 times

Last updated: Jul 14 '23