Skip to content

Commit

Permalink
ci: add commit and PR link to diff (#3816)
Browse files Browse the repository at this point in the history
* ci: add commit msg to diff

* ci: put msg in code block

* ci: put pr link in msg

* ci: update apps bump script

* ci: fix array accessing

* ci: add pr number to diff

* ci: iterate on script

* ci: iterate on script

* ci: iterate on script
  • Loading branch information
krtk6160 authored Jan 11, 2024
1 parent 76b81c7 commit 36435ce
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
18 changes: 14 additions & 4 deletions ci/apps/tasks/open-charts-pr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,23 @@ git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
git checkout ${ref}
app_src_files=($(buck2 uquery 'inputs(deps("'"//apps/${APP}:"'"))' 2>/dev/null))

relevant_commits=()
declare -A relevant_commits
for commit in $(git log --format="%H" ${old_ref}..${ref}); do
changed_files=$(git diff-tree --no-commit-id --name-only -r $commit)

for file in ${changed_files[@]}; do
if printf '%s\n' "${app_src_files[@]}" | grep -Fxq "$file"; then
relevant_commits+=($commit)
commit_message=$(git log --format="%s" -n 1 $commit)
pr_number=$(echo "$commit_message" | grep -oE '#[0-9]+' | grep -oE '[0-9]+')

if [[ -n "$pr_number" ]]; then
pr_link="${github_url}/pull/${pr_number}"
commit_message="${commit_message/ (#$pr_number)/}"
relevant_commits[$commit]="[$commit_message (#$pr_number)]($pr_link)"
else
relevant_commits[$commit]="$commit_message"
fi

break
fi
done
Expand Down Expand Up @@ -84,9 +94,9 @@ EOF
if [[ "${#relevant_commits[@]}" -eq 0 ]]; then
echo "- No relevant commits found" >> ../body.md
else
for commit in "${relevant_commits[@]}"; do
for commit in "${!relevant_commits[@]}"; do
cat <<-EOF >> ../body.md
- ${github_url}/commit/${commit}
- ${github_url}/commit/${commit} - ${relevant_commits[$commit]}
EOF
done
fi
Expand Down
18 changes: 14 additions & 4 deletions ci/core/tasks/open-charts-pr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,23 @@ git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
git checkout ${ref}
app_src_files=($(buck2 uquery 'inputs(deps("'"//core/${COMPONENT}:"'"))' 2>/dev/null))

relevant_commits=()
declare -A relevant_commits
for commit in $(git log --format="%H" ${old_ref}..${ref}); do
changed_files=$(git diff-tree --no-commit-id --name-only -r $commit)

for file in ${changed_files[@]}; do
if printf '%s\n' "${app_src_files[@]}" | grep -Fxq "$file"; then
relevant_commits+=($commit)
commit_message=$(git log --format="%s" -n 1 $commit)
pr_number=$(echo "$commit_message" | grep -oE '#[0-9]+' | grep -oE '[0-9]+')

if [[ -n "$pr_number" ]]; then
pr_link="${github_url}/pull/${pr_number}"
commit_message="${commit_message/ (#$pr_number)/}"
relevant_commits[$commit]="[$commit_message (#$pr_number)]($pr_link)"
else
relevant_commits[$commit]="$commit_message"
fi

break
fi
done
Expand Down Expand Up @@ -84,9 +94,9 @@ EOF
if [[ "${#relevant_commits[@]}" -eq 0 ]]; then
echo "- No relevant commits found" >> ../body.md
else
for commit in "${relevant_commits[@]}"; do
for commit in "${!relevant_commits[@]}"; do
cat <<-EOF >> ../body.md
- ${github_url}/commit/${commit}
- ${github_url}/commit/${commit} - ${relevant_commits[$commit]}
EOF
done
fi
Expand Down

0 comments on commit 36435ce

Please sign in to comment.