microsoft/hve-core

Public

mirrored from https://github.com/microsoft/hve-coreAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
hve-core-v2.3.6

Branches

Tags

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

Clone

HTTPS

Download ZIP

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

110lines · modeblame

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