diff --git a/documents/overview.md b/documents/overview.md index e586627..998507f 100644 --- a/documents/overview.md +++ b/documents/overview.md @@ -75,6 +75,6 @@ PMAC will become the foundation of: ## Get Involved -- GitHub: TBD +- GitHub: Jira Tools are going here: https://github.com/schneidergithub/pmac-tools/blob/master/jira-import-readme.md - Email: TBD - License: MIT + CC BY 4.0 \ No newline at end of file diff --git a/json_experiments/chatgpt4o_generated_result.sh b/json_experiments/chatgpt4o_generated_result.sh new file mode 100644 index 0000000..2e14bfd --- /dev/null +++ b/json_experiments/chatgpt4o_generated_result.sh @@ -0,0 +1,89 @@ +#!/bin/bash + +set -e + +# === Color Constants === +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +NC='\033[0m' # No Color + +# === Logging Helpers === +log_success() { echo -e "${GREEN}[✔] $1${NC}"; } +log_error() { echo -e "${RED}[✖] $1${NC}"; } +log_info() { echo -e "${YELLOW}[➤] $1${NC}"; } + +# === Check prerequisites === +check_prerequisites() { + log_info "Checking prerequisites..." + command -v git >/dev/null 2>&1 || { log_error "Git is not installed"; exit 1; } + command -v gh >/dev/null 2>&1 || { log_error "GitHub CLI is not installed"; exit 1; } + log_success "All prerequisites met" +} + +# === Create GitHub repository === +create_repository() { + local REPO_NAME="$1" + local REPO_DESC="$2" + local VISIBILITY="$3" # public or private + + log_info "Creating GitHub repository: $REPO_NAME" + + if gh repo view "$REPO_NAME" >/dev/null 2>&1; then + log_error "Repository $REPO_NAME already exists." + exit 2 + fi + + gh repo create "$REPO_NAME" --$VISIBILITY --description "$REPO_DESC" --confirm || { + log_error "Failed to create repository" + exit 3 + } + log_success "Repository created successfully" + + git clone "https://github.com/$(gh api user | jq -r '.login')/$REPO_NAME.git" || { + log_error "Failed to clone repository" + exit 4 + } + cd "$REPO_NAME" + log_success "Repository cloned and switched to directory: $REPO_NAME" +} + +# === Initialize README and LICENSE === +initialize_docs() { + local PROJECT_NAME="$1" + local DESCRIPTION="$2" + + log_info "Initializing documentation files..." + + echo "# $PROJECT_NAME" > README.md + echo "$DESCRIPTION" >> README.md + + YEAR=$(date +%Y) + echo "MIT License" > LICENSE + echo "Copyright (c) $YEAR $(gh api user | jq -r '.name')" >> LICENSE + + git add README.md LICENSE + git commit -m "Add README and LICENSE" + git push origin main + + log_success "Documentation initialized and pushed" +} + +# === MAIN EXECUTION === +main() { + check_prerequisites + + REPO_NAME="$1" + REPO_DESC="$2" + VISIBILITY="$3" + + if [[ -z "$REPO_NAME" || -z "$REPO_DESC" || -z "$VISIBILITY" ]]; then + log_error "Usage: $0 " + exit 9 + fi + + create_repository "$REPO_NAME" "$REPO_DESC" "$VISIBILITY" + initialize_docs "$REPO_NAME" "$REPO_DESC" +} + +main "$@" diff --git a/json_experiments/chatgptreo b/json_experiments/chatgptreo new file mode 160000 index 0000000..b57dfe5 --- /dev/null +++ b/json_experiments/chatgptreo @@ -0,0 +1 @@ +Subproject commit b57dfe513cddeffc747b88edc7cfef15e2ec7031 diff --git a/json_experiments/claude3.7_generated_result.sh b/json_experiments/claude3.7_generated_result.sh new file mode 100644 index 0000000..eff4ae5 --- /dev/null +++ b/json_experiments/claude3.7_generated_result.sh @@ -0,0 +1,1213 @@ +#!/bin/bash +# +# GitFlow Security Automation Script +# A robust bash script to automate the creation and configuration of GitHub repositories +# with GitFlow branching model and comprehensive security best practices. +# + +# Colors for console output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[0;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +# Script configuration +DEBUG=false +SCRIPT_VERSION="1.0.0" + +# Default values +DEFAULT_LICENSE="MIT" +DEFAULT_BRANCH="main" +GIT_FLOW_INSTALLED=false + +# Function to display help information +show_help() { + echo -e "${BLUE}GitFlow Security Automation${NC} v${SCRIPT_VERSION}" + echo + echo "Usage: $0 [options]" + echo + echo "Options:" + echo " -h, --help Show this help message" + echo " -n, --name REPO_NAME Specify repository name (required)" + echo " -d, --description DESC Specify repository description (optional)" + echo " -p, --private Create a private repository (default: public)" + echo " -c, --collaborators LIST Add collaborators (comma-separated)" + echo " -t, --teams LIST Add teams (comma-separated)" + echo " -v, --verbose Enable verbose output" + echo + echo "Example:" + echo " $0 --name my-new-repo --description \"My new project\" --private --collaborators user1,user2 --teams dev-team,security-team" + echo +} + +# Function to log messages +log() { + local level=$1 + local message=$2 + + case $level in + "info") + echo -e "${GREEN}[INFO]${NC} $message" + ;; + "warn") + echo -e "${YELLOW}[WARNING]${NC} $message" + ;; + "error") + echo -e "${RED}[ERROR]${NC} $message" + ;; + "debug") + if [ "$DEBUG" = true ]; then + echo -e "${BLUE}[DEBUG]${NC} $message" + fi + ;; + *) + echo -e "$message" + ;; + esac +} + +# Function to check for prerequisites +check_prerequisites() { + log "info" "Checking prerequisites..." + + # Check for git + if ! command -v git &> /dev/null; then + log "error" "git is not installed. Please install git and try again." + exit 1 + else + log "debug" "git is installed: $(git --version)" + fi + + # Check for GitHub CLI + if ! command -v gh &> /dev/null; then + log "error" "GitHub CLI is not installed. Please install GitHub CLI (gh) and try again." + log "info" "Visit https://cli.github.com/ for installation instructions." + exit 1 + else + log "debug" "GitHub CLI is installed: $(gh --version | head -n 1)" + fi + + # Check if authenticated with GitHub + if ! gh auth status &> /dev/null; then + log "error" "Not authenticated with GitHub. Please run 'gh auth login' first." + exit 1 + else + log "debug" "Authenticated with GitHub" + fi + + # Check for git-flow (optional) + if command -v git flow &> /dev/null; then + GIT_FLOW_INSTALLED=true + log "debug" "git-flow is installed: $(git flow version)" + else + log "warn" "git-flow is not installed. Will use native git commands instead." + fi + + log "info" "All required prerequisites are satisfied." + return 0 +} + +# Function to create a new GitHub repository +create_repository() { + local repo_name=$1 + local description=$2 + local visibility=$3 + + log "info" "Creating GitHub repository: ${repo_name}..." + + # Create repository using GitHub CLI + if [ "$visibility" = "private" ]; then + gh repo create "$repo_name" --private --description "$description" --clone + else + gh repo create "$repo_name" --public --description "$description" --clone + fi + + if [ $? -ne 0 ]; then + log "error" "Failed to create repository: ${repo_name}" + exit 1 + fi + + # Navigate to the repository directory + if [ -d "$repo_name" ]; then + cd "$repo_name" || { + log "error" "Failed to navigate to directory: ${repo_name}" + exit 1 + } + log "info" "Repository created successfully and cloned locally." + return 0 + else + log "error" "Repository directory not found: ${repo_name}" + exit 1 + fi +} + +# Function to verify repository exists remotely +verify_repository() { + local repo_name=$1 + + log "debug" "Verifying repository exists remotely: ${repo_name}..." + + if gh repo view "$repo_name" &> /dev/null; then + log "debug" "Repository verified: ${repo_name}" + return 0 + else + log "error" "Repository verification failed: ${repo_name}" + return 1 + fi +} + +# Function to add collaborators +add_collaborators() { + local repo_name=$1 + local collaborators=$2 + + if [ -z "$collaborators" ]; then + log "debug" "No collaborators specified. Skipping." + return 0 + fi + + log "info" "Adding collaborators to repository..." + + IFS=',' read -ra COLLAB_ARRAY <<< "$collaborators" + for collab in "${COLLAB_ARRAY[@]}"; do + log "debug" "Adding collaborator: ${collab}" + gh repo add-collaborator "$repo_name" "$collab" --permission push + + if [ $? -eq 0 ]; then + log "info" "Added collaborator: ${collab}" + else + log "warn" "Failed to add collaborator: ${collab}" + fi + done + + return 0 +} + +# Function to add teams +add_teams() { + local repo_name=$1 + local teams=$2 + + if [ -z "$teams" ]; then + log "debug" "No teams specified. Skipping." + return 0 + fi + + log "info" "Adding teams to repository..." + + # Get the GitHub username/organization from the repository name + local org_name + org_name=$(gh repo view "$repo_name" --json owner -q '.owner.login') + + IFS=',' read -ra TEAM_ARRAY <<< "$teams" + for team in "${TEAM_ARRAY[@]}"; do + log "debug" "Adding team: ${team}" + gh api -X PUT "repos/${org_name}/${repo_name}/teams/${team}" --input - <<< '{"permission":"push"}' + + if [ $? -eq 0 ]; then + log "info" "Added team: ${team}" + else + log "warn" "Failed to add team: ${team}. Make sure the team exists and you have proper permissions." + fi + done + + return 0 +} + +# Function to create LICENSE file +create_license() { + local license_type=$1 + + log "info" "Creating LICENSE file (${license_type})..." + + local current_year + current_year=$(date +"%Y") + local github_user + github_user=$(gh api user -q '.name') + + if [ -z "$github_user" ]; then + github_user=$(gh api user -q '.login') + fi + + case $license_type in + "MIT") + cat > LICENSE < README.md < DEVELOPMENT.md + git add DEVELOPMENT.md + git commit -m "Initialize develop branch" --quiet + git push -u origin develop --quiet + + # Verify branches were created + verify_branch "$DEFAULT_BRANCH" + verify_branch "develop" + + # Create an example feature branch + log "debug" "Creating example feature branch..." + if [ "$GIT_FLOW_INSTALLED" = true ]; then + git flow feature start example-feature + else + git checkout -b feature/example-feature develop --quiet + fi + + echo "# Example Feature" > FEATURE.md + git add FEATURE.md + git commit -m "Add example feature" --quiet + git push -u origin feature/example-feature --quiet + + # Create an example release branch + log "debug" "Creating example release branch..." + if [ "$GIT_FLOW_INSTALLED" = true ]; then + git flow release start 0.1.0 + else + git checkout -b release/0.1.0 develop --quiet + fi + + echo "# Example Release" > RELEASE.md + git add RELEASE.md + git commit -m "Prepare for release 0.1.0" --quiet + git push -u origin release/0.1.0 --quiet + + # Create an example hotfix branch + log "debug" "Creating example hotfix branch..." + if [ "$GIT_FLOW_INSTALLED" = true ]; then + git checkout "$DEFAULT_BRANCH" --quiet + git flow hotfix start 0.1.1 + else + git checkout -b hotfix/0.1.1 "$DEFAULT_BRANCH" --quiet + fi + + echo "# Example Hotfix" > HOTFIX.md + git add HOTFIX.md + git commit -m "Fix critical issue" --quiet + git push -u origin hotfix/0.1.1 --quiet + + # Return to develop branch + git checkout develop --quiet + + log "info" "GitFlow branch structure initialized successfully." + return 0 +} + +# Function to verify a branch exists both locally and remotely +verify_branch() { + local branch_name=$1 + + # Check if branch exists locally + if git branch --list "$branch_name" | grep -q "$branch_name"; then + log "debug" "Branch exists locally: ${branch_name}" + else + log "error" "Branch does not exist locally: ${branch_name}" + return 1 + fi + + # Check if branch exists remotely + if git ls-remote --heads origin "$branch_name" | grep -q "$branch_name"; then + log "debug" "Branch exists remotely: ${branch_name}" + else + log "error" "Branch does not exist remotely: ${branch_name}" + return 1 + fi + + log "debug" "Branch verified: ${branch_name}" + return 0 +} + +# Function to set up branch protection rules +setup_branch_protection() { + local repo_name=$1 + + log "info" "Setting up branch protection rules..." + + # Get repository full name + local repo_full_name + repo_full_name=$(gh repo view --json nameWithOwner -q .nameWithOwner) + + # Try to set up branch protection rules for main branch + log "debug" "Setting up protection for $DEFAULT_BRANCH branch..." + gh api -X PUT "repos/${repo_full_name}/branches/${DEFAULT_BRANCH}/protection" \ + -f required_status_checks='{"strict":true,"contexts":[]}' \ + -f enforce_admins=false \ + -f required_pull_request_reviews='{"dismissal_restrictions":{},"dismiss_stale_reviews":true,"require_code_owner_reviews":true,"required_approving_review_count":1}' \ + -f restrictions=null 2>/dev/null + + if [ $? -eq 0 ]; then + log "info" "Branch protection rules set for ${DEFAULT_BRANCH} branch." + else + log "warn" "Failed to set branch protection rules for ${DEFAULT_BRANCH} branch. This might be due to using a free GitHub account which has limited branch protection features." + log "warn" "You can still manually set up branch protection rules in the GitHub repository settings." + fi + + # Try to set up branch protection rules for develop branch + log "debug" "Setting up protection for develop branch..." + gh api -X PUT "repos/${repo_full_name}/branches/develop/protection" \ + -f required_status_checks='{"strict":true,"contexts":[]}' \ + -f enforce_admins=false \ + -f required_pull_request_reviews='{"dismissal_restrictions":{},"dismiss_stale_reviews":true,"require_code_owner_reviews":true,"required_approving_review_count":1}' \ + -f restrictions=null 2>/dev/null + + if [ $? -eq 0 ]; then + log "info" "Branch protection rules set for develop branch." + else + log "warn" "Failed to set branch protection rules for develop branch. This might be due to using a free GitHub account which has limited branch protection features." + log "warn" "You can still manually set up branch protection rules in the GitHub repository settings." + fi + + return 0 +} + +# Function to create security documentation +create_security_documentation() { + log "info" "Creating security documentation..." + + # Create .github directory if it doesn't exist + mkdir -p .github + + # Create SECURITY.md + log "debug" "Creating SECURITY.md..." + cat > SECURITY.md < .github/CODEOWNERS < .github/ISSUE_TEMPLATE/security_vulnerability.yml < .github/ISSUE_TEMPLATE/config.yml < .github/workflows/codeql-analysis.yml < .github/workflows/trivy-scan.yml < .github/workflows/gitleaks.yml < .github/workflows/dependency-review.yml < .github/codeql/codeql-config.yml < .github/dependabot.yml < .github/workflows/ci.yml < .github/workflows/release.yml < .gitignore < .editorconfig <