microsoft/hve-core

Public

mirrored fromhttps://github.com/microsoft/hve-coreAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
docs/227-add-governance

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

scripts/dev-tools/pr-ref-gen.sh

108lines · modecode

1#!/usr/bin/env bash
2
3# Script to generate a PR reference file with commit history and full diff
4# This file will be used by GitHub Copilot to generate accurate PR descriptions
5#
6# The script compares the current branch with a specified base branch (default: main)
7# and generates an XML file with commit history and diff information
8
9# Display usage information
10function show_usage {
11 echo "Usage: $0 [--no-md-diff] [--base-branch BRANCH] [--output FILE]"
12 echo ""
13 echo "Options:"
14 echo " --no-md-diff Exclude markdown files (*.md) from the diff output"
15 echo " --base-branch Specify the base branch to compare against (default: main)"
16 echo " --output Specify output file path (default: .copilot-tracking/pr/pr-reference.xml)"
17 exit 1
18}
19
20# Get the repository root directory
21REPO_ROOT=$(git rev-parse --show-toplevel)
22
23# Process command line arguments
24NO_MD_DIFF=false
25BASE_BRANCH="origin/main"
26OUTPUT_FILE="${REPO_ROOT}/.copilot-tracking/pr/pr-reference.xml"
27while [[ $# -gt 0 ]]; do
28 case "$1" in
29 --no-md-diff)
30 NO_MD_DIFF=true
31 shift
32 ;;
33 --base-branch)
34 if [[ -z $2 || $2 == --* ]]; then
35 echo "Error: --base-branch requires an argument"
36 show_usage
37 fi
38 BASE_BRANCH="$2"
39 shift 2
40 ;;
41 --output)
42 if [[ -z $2 || $2 == --* ]]; then
43 echo "Error: --output requires an argument"
44 show_usage
45 fi
46 OUTPUT_FILE="$2"
47 shift 2
48 ;;
49 --help | -h)
50 show_usage
51 ;;
52 *)
53 echo "Unknown option: $1"
54 show_usage
55 ;;
56 esac
57done
58
59# Verify the base branch exists
60if ! git rev-parse --verify "${BASE_BRANCH}" &>/dev/null; then
61 echo "Error: Branch '${BASE_BRANCH}' does not exist or is not accessible"
62 exit 1
63fi
64
65# Set output file path
66PR_REF_FILE="${OUTPUT_FILE}"
67mkdir -p "$(dirname "$PR_REF_FILE")"
68
69# Create the reference file with commit history using XML tags
70{
71 echo "<commit_history>"
72 echo " <current_branch>"
73 git --no-pager branch --show-current
74 echo " </current_branch>"
75 echo ""
76
77 echo " <base_branch>"
78 echo " ${BASE_BRANCH}"
79 echo " </base_branch>"
80 echo ""
81
82 echo " <commits>"
83 # Output commit information including subject and body
84 git --no-pager log --pretty=format:"<commit hash=\"%h\" date=\"%cd\"><message><subject><\![CDATA[%s]]></subject><body><\![CDATA[%b]]></body></message></commit>" --date=short "${BASE_BRANCH}"..HEAD
85 echo " </commits>"
86 echo ""
87
88 # Add the full diff, excluding specified files
89 echo " <full_diff>"
90 # Exclude prompts and this file from diff history
91 if [ "$NO_MD_DIFF" = true ]; then
92 git --no-pager diff "${BASE_BRANCH}" -- ':!*.md'
93 else
94 git --no-pager diff "${BASE_BRANCH}"
95 fi
96 echo " </full_diff>"
97 echo "</commit_history>"
98} >"${PR_REF_FILE}"
99
100LINE_COUNT=$(wc -l <"${PR_REF_FILE}" | awk '{print $1}')
101
102echo "Created ${PR_REF_FILE}"
103if [ "$NO_MD_DIFF" = true ]; then
104 echo "Note: Markdown files were excluded from diff output"
105fi
106echo "Lines: $LINE_COUNT"
107echo "Base branch: $BASE_BRANCH"
108echo "File name: $PR_REF_FILE"