Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
basecamp-cli/scripts/doc_parity.py at main · basecamp/basecamp-cli · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
See all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
basecamp
basecamp-cli
Repository navigation
Code
Issues
35
(35)
Pull requests
15
(15)
Discussions
Actions
Security and quality
Insights
More
items
Files
Expand file tree
main
Breadcrumbs
basecamp-cli
/
scripts
/
doc_parity.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
230 lines (198 loc) · 7.91 KB
main
Breadcrumbs
basecamp-cli
/
scripts
/
doc_parity.py
Copy path
Top
File metadata and controls
Code
Blame
230 lines (198 loc) · 7.91 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#!/usr/bin/env python3
import
argparse
import
os
import
re
import
sys
from
pathlib
import
Path
DOC_ENDPOINT_RE
=
re
.
compile
(
r"\b(GET|POST|PUT|PATCH|DELETE)\s+(/\S+)"
,
re
.
I
)
API_CALL_STR_RE
=
re
.
compile
(
r"api_(get|post|put|patch|delete|upload)\s+(\"([^\"]+)\"|'([^']+)')"
)
API_CALL_VAR_RE
=
re
.
compile
(
r"api_(get|post|put|patch|delete|upload)\s+\"?(\$[A-Za-z_][A-Za-z0-9_]*|\$\{[A-Za-z_][A-Za-z0-9_]*\})\"?"
)
ASSIGN_RE
=
re
.
compile
(
r"^\s*(?:local\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=\s*([\"'])(.+?)\2"
)
SKIP_SECTIONS
=
{
"chatbots.md"
,
"client_approvals.md"
,
"client_correspondences.md"
,
"client_replies.md"
,
}
def
parse_args
()
->
argparse
.
Namespace
:
parser
=
argparse
.
ArgumentParser
(
description
=
"Compare basecamp API usage to bc3-api documentation coverage."
)
parser
.
add_argument
(
"--basecamp-root"
,
default
=
str
(
Path
(
__file__
).
resolve
().
parents
[
1
]),
help
=
"Path to basecamp repo root (default: repo root)."
,
)
parser
.
add_argument
(
"--bc3-api"
,
default
=
os
.
environ
.
get
(
"BC3_API_PATH"
,
""
),
help
=
"Path to bc3-api repo root (default: ../bc3-api)."
,
)
parser
.
add_argument
(
"--show-missing"
,
action
=
"store_true"
,
help
=
"List missing endpoints per partial/zero section."
,
)
return
parser
.
parse_args
()
def
resolve_bc3_api_root
(
basecamp_root
:
Path
,
provided
:
str
)
->
Path
:
if
provided
:
return
Path
(
provided
).
expanduser
().
resolve
()
candidate
=
(
basecamp_root
.
parent
/
"bc3-api"
).
resolve
()
return
candidate
def
load_doc_endpoints
(
sections_dir
:
Path
)
->
dict
[
str
,
list
[
tuple
[
str
,
str
]]]:
sections
:
dict
[
str
,
list
[
tuple
[
str
,
str
]]]
=
{}
if
not
sections_dir
.
is_dir
():
return
sections
for
md_file
in
sorted
(
sections_dir
.
glob
(
"*.md"
)):
text
=
md_file
.
read_text
(
encoding
=
"utf-8"
)
seen
=
set
()
endpoints
:
list
[
tuple
[
str
,
str
]]
=
[]
for
match
in
DOC_ENDPOINT_RE
.
finditer
(
text
):
method
=
match
.
group
(
1
).
upper
()
path
=
match
.
group
(
2
).
rstrip
(
"`,."
)
key
=
(
method
,
path
)
if
key
in
seen
:
continue
seen
.
add
(
key
)
endpoints
.
append
(
key
)
if
endpoints
:
sections
[
md_file
.
name
]
=
endpoints
return
sections
def
load_basecamp_endpoints
(
commands_dir
:
Path
)
->
set
[
tuple
[
str
,
str
]]:
endpoints
:
set
[
tuple
[
str
,
str
]]
=
set
()
if
not
commands_dir
.
is_dir
():
return
endpoints
for
script
in
commands_dir
.
rglob
(
"*.sh"
):
text
=
script
.
read_text
(
encoding
=
"utf-8"
)
assignments
:
dict
[
str
,
set
[
str
]]
=
{}
for
line
in
text
.
splitlines
():
match
=
ASSIGN_RE
.
match
(
line
)
if
not
match
:
continue
var_name
=
match
.
group
(
1
)
value
=
match
.
group
(
3
)
if
not
value
.
startswith
(
"/"
):
continue
assignments
.
setdefault
(
var_name
,
set
()).
add
(
value
)
for
match
in
API_CALL_STR_RE
.
finditer
(
text
):
method
=
match
.
group
(
1
).
upper
()
if
method
==
"UPLOAD"
:
method
=
"POST"
path
=
match
.
group
(
3
)
or
match
.
group
(
4
)
if
re
.
fullmatch
(
r"\$\{?[A-Za-z_][A-Za-z0-9_]*\}?"
,
path
):
continue
endpoints
.
add
((
method
,
path
))
for
match
in
API_CALL_VAR_RE
.
finditer
(
text
):
method
=
match
.
group
(
1
).
upper
()
if
method
==
"UPLOAD"
:
method
=
"POST"
var_token
=
match
.
group
(
2
)
var_name
=
var_token
.
strip
(
"${}"
).
lstrip
(
"$"
)
for
path
in
assignments
.
get
(
var_name
,
set
()):
endpoints
.
add
((
method
,
path
))
return
endpoints
def
segmentize
(
path
:
str
,
wildcard_vars
:
bool
,
wildcard_numbers
:
bool
)
->
list
[
str
]:
path
=
path
.
split
(
"?"
,
1
)[
0
]
path
=
path
.
replace
(
"(.:format)"
,
""
)
path
=
path
.
replace
(
"("
,
""
).
replace
(
")"
,
""
)
segments
:
list
[
str
]
=
[]
for
segment
in
path
.
strip
(
"/"
).
split
(
"/"
):
if
not
segment
:
continue
segment
=
segment
.
replace
(
".json"
,
""
)
is_wildcard
=
False
if
wildcard_vars
and
(
"$"
in
segment
or
segment
.
startswith
(
":"
)
or
segment
.
startswith
(
"{"
)):
is_wildcard
=
True
if
wildcard_numbers
and
segment
.
isdigit
():
is_wildcard
=
True
if
":"
in
segment
:
is_wildcard
=
True
if
is_wildcard
:
segments
.
append
(
"*"
)
else
:
segments
.
append
(
segment
)
return
segments
def
endpoints_match
(
doc_endpoint
:
tuple
[
str
,
str
],
basecamp_endpoint
:
tuple
[
str
,
str
])
->
bool
:
doc_method
,
doc_path
=
doc_endpoint
basecamp_method
,
basecamp_path
=
basecamp_endpoint
if
doc_method
!=
basecamp_method
:
return
False
doc_segs
=
segmentize
(
doc_path
,
wildcard_vars
=
True
,
wildcard_numbers
=
True
)
basecamp_segs
=
segmentize
(
basecamp_path
,
wildcard_vars
=
True
,
wildcard_numbers
=
False
)
if
len
(
doc_segs
)
!=
len
(
basecamp_segs
):
return
False
for
doc_seg
,
basecamp_seg
in
zip
(
doc_segs
,
basecamp_segs
):
if
doc_seg
==
"*"
or
basecamp_seg
==
"*"
:
continue
if
doc_seg
!=
basecamp_seg
:
return
False
return
True
def
main
()
->
int
:
args
=
parse_args
()
basecamp_root
=
Path
(
args
.
basecamp_root
).
resolve
()
if
not
basecamp_root
.
is_dir
():
print
(
f"error: basecamp root not found:
{
basecamp_root
}
"
,
file
=
sys
.
stderr
)
return
1
bc3_api_root
=
resolve_bc3_api_root
(
basecamp_root
,
args
.
bc3_api
)
sections_dir
=
bc3_api_root
/
"sections"
if
not
sections_dir
.
exists
():
print
(
f"error: sections dir not found:
{
sections_dir
}
"
,
file
=
sys
.
stderr
)
return
1
doc_sections
=
load_doc_endpoints
(
sections_dir
)
skipped_sections
=
{
name
:
endpoints
for
name
,
endpoints
in
doc_sections
.
items
()
if
name
in
SKIP_SECTIONS
}
if
skipped_sections
:
doc_sections
=
{
name
:
endpoints
for
name
,
endpoints
in
doc_sections
.
items
()
if
name
not
in
SKIP_SECTIONS
}
basecamp_endpoints
=
load_basecamp_endpoints
(
basecamp_root
/
"lib"
/
"commands"
)
unique_docs
=
[]
doc_seen
=
set
()
for
endpoints
in
doc_sections
.
values
():
for
endpoint
in
endpoints
:
if
endpoint
in
doc_seen
:
continue
doc_seen
.
add
(
endpoint
)
unique_docs
.
append
(
endpoint
)
matched
=
0
section_stats
=
{}
section_missing
=
{}
for
section_name
,
endpoints
in
doc_sections
.
items
():
total
=
len
(
endpoints
)
section_matched
=
0
missing
=
[]
for
endpoint
in
endpoints
:
if
any
(
endpoints_match
(
endpoint
,
basecamp_ep
)
for
basecamp_ep
in
basecamp_endpoints
):
section_matched
+=
1
else
:
missing
.
append
(
f"
{
endpoint
[
0
]
}
{
endpoint
[
1
]
}
"
)
section_stats
[
section_name
]
=
(
section_matched
,
total
)
if
missing
:
section_missing
[
section_name
]
=
missing
for
endpoint
in
unique_docs
:
if
any
(
endpoints_match
(
endpoint
,
basecamp_ep
)
for
basecamp_ep
in
basecamp_endpoints
):
matched
+=
1
total
=
len
(
unique_docs
)
pct
=
(
matched
/
total
*
100
)
if
total
else
0.0
print
(
f"overall:
{
matched
}
/
{
total
}
(
{
pct
:.1f
}
%)"
)
if
skipped_sections
:
skipped_endpoints
=
sum
(
len
(
endpoints
)
for
endpoints
in
skipped_sections
.
values
())
print
(
f"skipped sections:
{
len
(
skipped_sections
)
}
(
{
skipped_endpoints
}
endpoints)"
)
full
=
sorted
([
s
for
s
, (
m
,
t
)
in
section_stats
.
items
()
if
m
==
t
])
partial
=
sorted
([
s
for
s
, (
m
,
t
)
in
section_stats
.
items
()
if
0
<
m
<
t
])
zero
=
sorted
([
s
for
s
, (
m
,
t
)
in
section_stats
.
items
()
if
m
==
0
])
print
(
f"full:
{
len
(
full
)
}
"
)
print
(
f"partial:
{
len
(
partial
)
}
"
)
print
(
f"zero:
{
len
(
zero
)
}
"
)
if
args
.
show_missing
:
for
section
in
partial
+
zero
:
missing
=
section_missing
.
get
(
section
, [])
if
not
missing
:
continue
print
(
f"
\n
{
section
}
"
)
for
item
in
missing
:
print
(
f"
{
item
}
"
)
return
0
if
__name__
==
"__main__"
:
raise
SystemExit
(
main
())
You can’t perform that action at this time.