-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_analysis.sh
More file actions
executable file
·185 lines (155 loc) · 5.57 KB
/
setup_analysis.sh
File metadata and controls
executable file
·185 lines (155 loc) · 5.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/bin/bash
# GitHub Repository Analysis Setup Script
# This script helps set up and run PR analysis for organizations or users
set -e
# Colors for output
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
RED='\033[0;31m'
NC='\033[0m' # No Color
print_header() {
echo -e "${BLUE}"
echo "================================================================="
echo " GitHub Repository Analysis - Setup & Usage Guide"
echo "================================================================="
echo -e "${NC}"
}
check_authentication() {
echo -e "${YELLOW}Checking GitHub CLI authentication...${NC}"
if gh auth status >/dev/null 2>&1; then
echo -e "${GREEN}✓ GitHub CLI is authenticated${NC}"
# Show current user info
USER_INFO=$(gh api user --jq '.login' 2>/dev/null || echo "unknown")
echo -e "${BLUE}Authenticated as: ${USER_INFO}${NC}"
return 0
else
echo -e "${RED}✗ GitHub CLI not authenticated${NC}"
return 1
fi
}
setup_authentication() {
echo -e "${YELLOW}Setting up GitHub authentication...${NC}"
echo ""
echo "You'll need to authenticate with GitHub to access private repositories."
echo "This will open a web browser for authentication."
echo ""
read -p "Continue with authentication? (y/n): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
gh auth login --scopes "repo,read:org"
if [[ $? -eq 0 ]]; then
echo -e "${GREEN}✓ Authentication successful!${NC}"
else
echo -e "${RED}✗ Authentication failed${NC}"
exit 1
fi
else
echo "Authentication cancelled. You can run 'gh auth login' manually later."
exit 1
fi
}
show_usage() {
echo -e "${BLUE}Usage Examples:${NC}"
echo ""
echo "1. Analyze all repositories for an organization:"
echo " python3 analyze_repos.py mycompany"
echo ""
echo "2. Analyze all repositories for a user:"
echo " python3 analyze_repos.py johndoe"
echo ""
echo "3. Analyze only private repositories:"
echo " python3 analyze_repos.py mycompany --private-only"
echo ""
echo "4. Export results to CSV:"
echo " python3 analyze_repos.py johndoe --export-csv results.csv"
echo ""
echo "5. Quick test (first 5 repos only):"
echo " python3 analyze_repos.py mycompany --repo-limit 5"
echo ""
echo "6. Just list repositories without analyzing:"
echo " python3 analyze_repos.py johndoe --skip-analysis"
echo ""
echo -e "${YELLOW}Options:${NC}"
echo " --private-only Only analyze private repositories"
echo " --public-only Only analyze public repositories"
echo " --limit N Limit PRs per repository (default: 100)"
echo " --repo-limit N Limit number of repositories to analyze"
echo " --export-csv FILE Export results to CSV file"
echo " --skip-analysis Only list repositories, don't analyze"
}
test_account_access() {
if [[ -z "$1" ]]; then
echo -e "${RED}Please provide an organization or username to test${NC}"
return 1
fi
local ACCOUNT="$1"
echo -e "${YELLOW}Testing access to account: ${ACCOUNT}${NC}"
# Try organization first
if gh api "orgs/${ACCOUNT}" >/dev/null 2>&1; then
echo -e "${GREEN}✓ Can access organization '${ACCOUNT}'${NC}"
ACCOUNT_TYPE="organization"
elif gh api "users/${ACCOUNT}" >/dev/null 2>&1; then
echo -e "${GREEN}✓ Can access user '${ACCOUNT}'${NC}"
ACCOUNT_TYPE="user"
else
echo -e "${RED}✗ Cannot access account '${ACCOUNT}'${NC}"
echo "This could be because:"
echo " - Account name is incorrect"
echo " - Account doesn't exist"
echo " - Your token doesn't have the necessary permissions"
return 1
fi
# Count repos
REPO_COUNT=$(gh repo list "$ACCOUNT" --limit 1000 --json name | jq length 2>/dev/null || echo "unknown")
echo -e "${BLUE}Account type: ${ACCOUNT_TYPE}${NC}"
echo -e "${BLUE}Accessible repositories: ${REPO_COUNT}${NC}"
return 0
}
main() {
print_header
# Check if organization is provided
if [[ $# -eq 0 ]]; then
echo "This script helps you set up and run PR analysis across all repositories"
echo "for a GitHub organization or user."
echo ""
if ! check_authentication; then
echo ""
setup_authentication
fi
echo ""
echo -e "${YELLOW}Please provide an organization or username to get started:${NC}"
read -p "Organization or username: " ACCOUNT_NAME
if [[ -n "$ACCOUNT_NAME" ]]; then
echo ""
test_account_access "$ACCOUNT_NAME"
echo ""
show_usage
fi
elif [[ "$1" == "--help" || "$1" == "-h" ]]; then
show_usage
elif [[ "$1" == "--test" ]]; then
if ! check_authentication; then
setup_authentication
fi
shift
test_account_access "$1"
elif [[ "$1" == "--setup" ]]; then
setup_authentication
else
# Run the analysis
ACCOUNT_NAME="$1"
shift
if ! check_authentication; then
echo ""
setup_authentication
fi
echo ""
echo -e "${GREEN}Running analysis for account: ${ACCOUNT_NAME}${NC}"
echo ""
python3 "./analyze_repos.py" "$ACCOUNT_NAME" "$@"
fi
}
# Make the main script executable
chmod +x "./analyze_repos.py" 2>/dev/null || true
main "$@"