Skip to content

Commit ff4d99c

Browse files
Merge pull request #4755 from linuxfoundation/dev
Add API calls logging
2 parents 2dc2537 + e022325 commit ff4d99c

File tree

8 files changed

+226
-13
lines changed

8 files changed

+226
-13
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,5 @@ cover.out
255255

256256
# Local env vars
257257
.env
258+
src.txt
259+
src.txt.*

CO_AUTHORS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ When a commit is made to a repository that has co-authors support enabled, the b
151151

152152
If it does, the backend will process the co-authors as follows, assume trailer value is `name <email>` like `Lukasz Gryglicki <[email protected]>`:
153153

154-
- First we check if email is in format `nuber[email protected]`. If it is we use number part as GitHub user ID and fetch the user from GitHub API. If the user is found, we use that user as co-author.
154+
- First we check if email is in format `number[email protected]`. If it is we use number part as GitHub user ID and fetch the user from GitHub API. If the user is found, we use that user as co-author.
155155

156156
- Second we check if email is in format `[email protected]`. If it is we use username part as GitHub username/login and fetch the user from GitHub API. If the user is found, we use that user as co-author.
157157

cla-backend-go/cmd/server.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,14 @@ type combinedRepo struct {
144144
projects_cla_groups.Repository
145145
}
146146

147+
// in cmd/server.go (top-level imports already use logrus)
148+
func apiPathLogger(next http.Handler) http.Handler {
149+
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
150+
log.Infof("LG:api-request-path:%s", r.URL.Path)
151+
next.ServeHTTP(w, r)
152+
})
153+
}
154+
147155
// server function called by environment specific server functions
148156
func server(localMode bool) http.Handler {
149157
f := logrus.Fields{
@@ -398,7 +406,7 @@ func server(localMode bool) http.Handler {
398406
// The middleware configuration is for the handler executors. These do not apply to the swagger.json document.
399407
// The middleware executes after routing but before authentication, binding and validation
400408
middlewareSetupfunc := func(handler http.Handler) http.Handler {
401-
return setRequestIDHandler(responseLoggingMiddleware(userCreaterMiddleware(handler)))
409+
return apiPathLogger(setRequestIDHandler(responseLoggingMiddleware(userCreaterMiddleware(handler))))
402410
}
403411

404412
v2API.CsvProducer = openapi_runtime.ProducerFunc(func(w io.Writer, data interface{}) error {

cla-backend-go/go.mod

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,17 @@ require (
6666
)
6767

6868
require (
69+
github.com/aws/aws-sdk-go-v2/service/s3 v1.53.1
6970
github.com/bradleyfalzon/ghinstallation/v2 v2.2.0
71+
github.com/golang-jwt/jwt v3.2.2+incompatible
7072
github.com/golang-jwt/jwt/v4 v4.5.0
7173
)
7274

7375
require (
7476
github.com/ProtonMail/go-crypto v0.0.0-20230321155629-9a39f2531310 // indirect
7577
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect
76-
github.com/aws/aws-sdk-go-v2/service/s3 v1.53.1 // indirect
7778
github.com/aws/smithy-go v1.20.2 // indirect
7879
github.com/cloudflare/circl v1.3.2 // indirect
79-
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
8080
github.com/docker/go-units v0.4.0 // indirect
8181
github.com/fatih/color v1.15.0 // indirect
8282
github.com/fsnotify/fsnotify v1.5.4 // indirect
@@ -86,7 +86,6 @@ require (
8686
github.com/go-openapi/jsonreference v0.20.0 // indirect
8787
github.com/go-playground/locales v0.13.0 // indirect
8888
github.com/go-playground/universal-translator v0.17.0 // indirect
89-
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
9089
github.com/golang/protobuf v1.5.3 // indirect
9190
github.com/google/go-github/v50 v50.2.0 // indirect
9291
github.com/google/go-querystring v1.1.0 // indirect

cla-backend-go/go.sum

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
4141
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
4242
github.com/LF-Engineering/aws-lambda-go-api-proxy v0.3.2 h1:ZLAgTj9+H3RTmjbRpUamMO8SWS1m4ZKJGGeh9lT985U=
4343
github.com/LF-Engineering/aws-lambda-go-api-proxy v0.3.2/go.mod h1:LQj48zwkRwdjVmDCqtPlviW/7IFaSKzz2gDhxRwVrA4=
44-
github.com/LF-Engineering/lfx-kit v0.1.33 h1:UI0vP7zFqolFdF68N0LDB1cKTU1Y16DbqjEiDt9rNKo=
45-
github.com/LF-Engineering/lfx-kit v0.1.33/go.mod h1:e2dnnqQtojsnFX5rmZpWcZNfHirnLrAys0Jak9pdijM=
4644
github.com/LF-Engineering/lfx-kit v0.1.39 h1:mVLXRX7m6ytkLLt+Gf9T4Fhg8PKHcPzUic7OomefuiM=
4745
github.com/LF-Engineering/lfx-kit v0.1.39/go.mod h1:TT7IqcXmeD63smE3ieHemt+J032MJObsxWJhF1GP4HQ=
4846
github.com/LF-Engineering/lfx-models v0.7.9 h1:xuEvRk9b3Nc57i3Hl5mpH3wKG59z38H4rdWd/TXmNmk=
@@ -70,7 +68,6 @@ github.com/aws/aws-lambda-go v1.22.0/go.mod h1:jJmlefzPfGnckuHdXX7/80O3BvUUi12XO
7068
github.com/aws/aws-sdk-go v1.34.28/go.mod h1:H7NKnBqNVzoTJpGfLrQkkD+ytBA93eiDYi/+8rV9s48=
7169
github.com/aws/aws-sdk-go v1.36.27 h1:wc3xLJJHog2SwiqlLnrLUuct/n+dBjB45QhuZw2psVE=
7270
github.com/aws/aws-sdk-go v1.36.27/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
73-
github.com/aws/aws-sdk-go-v2 v1.26.1 h1:5554eUqIYVWpU0YmeeYZ0wU64H2VLBs8TlhRB2L+EkA=
7471
github.com/aws/aws-sdk-go-v2/service/s3 v1.53.1 h1:6cnno47Me9bRykw9AEv9zkXE+5or7jz8TsskTTccbgc=
7572
github.com/aws/aws-sdk-go-v2/service/s3 v1.53.1/go.mod h1:qmdkIIAC+GCLASF7R2whgNrJADz0QZPX+Seiw/i4S3o=
7673
github.com/aws/smithy-go v1.20.2 h1:tbp628ireGtzcHDDmLT/6ADHidqnwgF57XOXZe6tp4Q=
@@ -105,8 +102,6 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
105102
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
106103
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
107104
github.com/dchest/safefile v0.0.0-20151022103144-855e8d98f185/go.mod h1:cFRxtTwTOJkz2x3rQUNCYKWC93yP1VKjR8NUhqFxZNU=
108-
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
109-
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
110105
github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
111106
github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw=
112107
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
@@ -119,6 +114,7 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7
119114
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
120115
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
121116
github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE=
117+
github.com/frankban/quicktest v1.14.3/go.mod h1:mgiwOwqx65TmIk1wJ6Q7wvnVMocbUorkibMOrVTHZps=
122118
github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI=
123119
github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
124120
github.com/gin-contrib/sse v0.0.0-20170109093832-22d885f9ecc7/go.mod h1:VJ0WA2NBN22VlZ2dKZQPAPnyWw5XTlK1KymzLKsr59s=
@@ -363,6 +359,7 @@ github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+
363359
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
364360
github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g=
365361
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
362+
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
366363
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
367364
github.com/gorilla/mux v0.0.0-20180120075819-c0091a029979/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
368365
github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ=
@@ -374,6 +371,7 @@ github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9n
374371
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
375372
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
376373
github.com/hashicorp/go-hclog v1.2.0 h1:La19f8d7WIlm4ogzNHB0JGqs5AUDAZ2UfCY4sJXcJdM=
374+
github.com/hashicorp/go-hclog v1.2.0/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ=
377375
github.com/hashicorp/go-retryablehttp v0.6.8 h1:92lWxgpa+fF3FozM4B3UZtHZMJX8T5XT+TFdCxsPyWs=
378376
github.com/hashicorp/go-retryablehttp v0.6.8/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
379377
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
@@ -413,6 +411,7 @@ github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHm
413411
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
414412
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
415413
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
414+
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
416415
github.com/juju/mempool v0.0.0-20160205104927-24974d6c264f h1:a3Vd00a20dTKLpyS2hdUafNG5zxQdTw5KhDMK5C0a8U=
417416
github.com/juju/mempool v0.0.0-20160205104927-24974d6c264f/go.mod h1:+7K7MqWi5xWI+s1LyB2g0Di71jZo27y+XOlmhNtV1Y0=
418417
github.com/juju/zip v0.0.0-20160205105221-f6b1e93fa2e2 h1:McU3wXjBrKfJcOt2Pali5qEir9NLrqOh4EECzdWHknM=
@@ -532,7 +531,9 @@ github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6Mwd
532531
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
533532
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
534533
github.com/smartystreets/assertions v1.2.0 h1:42S6lae5dvLc7BrLu/0ugRtcFVjoJNMC/N3yZFZkDFs=
534+
github.com/smartystreets/assertions v1.2.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo=
535535
github.com/smartystreets/goconvey v1.7.2 h1:9RBaZCeXEQ3UselpuwUQHltGVXvdwm6cv1hgR6gDIPg=
536+
github.com/smartystreets/goconvey v1.7.2/go.mod h1:Vw0tHAZW6lzCRk3xgdin6fKYcG+G3Pg9vgXWeJpQFMM=
536537
github.com/spf13/afero v1.9.5 h1:stMpOSZFs//0Lv29HduCmli3GUfpFoF3Y1Q/aXj/wVM=
537538
github.com/spf13/afero v1.9.5/go.mod h1:UBogFpq8E9Hx+xc5CNTTEpTnuHVmXDwZcZcE1eb/UhQ=
538539
github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w=
@@ -613,6 +614,7 @@ go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
613614
go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
614615
go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk=
615616
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
617+
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
616618
go.uber.org/ratelimit v0.1.0 h1:U2AruXqeTb4Eh9sYQSTrMhH8Cb7M0Ian2ibBOnBcnAw=
617619
go.uber.org/ratelimit v0.1.0/go.mod h1:2X8KaoNd1J0lZV+PxJk/5+DGbO/tpwLR1m++a7FnB/Y=
618620
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
@@ -805,8 +807,6 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc
805807
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
806808
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
807809
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
808-
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
809-
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
810810
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
811811
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
812812
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=

utils/dump_repo.py

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
#!/usr/bin/env python3
2+
import argparse, os, sys, pathlib, io, subprocess, shutil
3+
4+
DEFAULT_EXCLUDE_DIRS = {".git", ".hg", ".svn", ".idea", ".vscode", "dist", "build", "out", "target", ".next", ".nuxt", ".tox", "__pycache__"}
5+
DEFAULT_EXCLUDE_GLOBS = {"*.min.js", "*.map", "*.lock", "*.jar", "*.zip", "*.gz", "*.tgz", "*.bz2", "*.7z", "*.png",
6+
"*.jpg", "*.jpeg", "*.gif", "*.webp", "*.ico", "*.pdf", "*.woff", "*.woff2", "*.ttf", "*.otf",
7+
"*.mp4", "*.mov", "*.avi", "*.mp3", "*.flac", "*.wav", "*.iso", "*.bin", "*.secret"}
8+
DEFAULT_INCLUDE_EXTS = {
9+
".go",".ts",".tsx",".js",".jsx",".json",".yml",".yaml",".toml",".ini",".env",".md",".txt",
10+
".proto",".graphql",".sql",".py",".rs",".java",".c",".h",".cpp",".hpp",".cc",".m",".mm",
11+
".rb",".php",".pl",".sh",".bash",".zsh",".fish",".ps1",".bat",".dockerfile",".gradle",".properties"
12+
}
13+
ALSO_ALLOW_NAME = {"dockerfile", "makefile", "makefile.win"}
14+
15+
def is_text_file(path: str, max_probe=65536) -> bool:
16+
try:
17+
with open(path, "rb") as f:
18+
chunk = f.read(max_probe)
19+
if b"\x00" in chunk:
20+
return False
21+
chunk.decode("utf-8", errors="strict")
22+
return True
23+
except Exception:
24+
return False
25+
26+
def should_keep_by_ext(p: pathlib.Path, include_exts) -> bool:
27+
if include_exts and p.suffix.lower() not in include_exts:
28+
if p.name.lower() not in ALSO_ALLOW_NAME:
29+
return False
30+
return True
31+
32+
def should_exclude_by_glob(rel: str) -> bool:
33+
from pathlib import PurePath
34+
pp = PurePath(rel)
35+
for g in DEFAULT_EXCLUDE_GLOBS:
36+
if pp.match(g):
37+
return True
38+
return False
39+
40+
def git_available() -> bool:
41+
return shutil.which("git") is not None
42+
43+
def iter_files_git(repo_root: pathlib.Path):
44+
"""
45+
Yields repo files not ignored by .gitignore/.git/info/exclude/global ignores.
46+
Uses: git ls-files --cached --others --exclude-standard
47+
"""
48+
cmd = ["git", "-C", str(repo_root), "ls-files", "-z", "--cached", "--others", "--exclude-standard", "--"]
49+
out = subprocess.check_output(cmd)
50+
for rel_b in out.split(b"\x00"):
51+
if not rel_b:
52+
continue
53+
rel = rel_b.decode("utf-8", errors="replace")
54+
p = repo_root / rel
55+
if p.is_file():
56+
yield p
57+
58+
def iter_files_walk(repo_root: pathlib.Path):
59+
"""
60+
Fallback: walk the tree and filter manually (does NOT perfectly mirror .gitignore).
61+
"""
62+
for root, dirs, files in os.walk(repo_root):
63+
# prune common junk dirs
64+
dirs[:] = [d for d in dirs if d not in DEFAULT_EXCLUDE_DIRS]
65+
for name in files:
66+
p = pathlib.Path(root) / name
67+
rel = p.relative_to(repo_root).as_posix()
68+
if should_exclude_by_glob(rel):
69+
continue
70+
yield p
71+
72+
def iter_repo_files(repo_root: pathlib.Path, use_git: bool):
73+
if use_git:
74+
yield from iter_files_git(repo_root)
75+
else:
76+
# use git if available and .git exists
77+
if (repo_root/".git").exists() and git_available():
78+
yield from iter_files_git(repo_root)
79+
else:
80+
yield from iter_files_walk(repo_root)
81+
82+
def write_repo(repo_root: pathlib.Path, out_prefix: pathlib.Path, max_mb: float, force_git: bool):
83+
repo_root = repo_root.resolve()
84+
max_bytes = int(max_mb * (1024**2))
85+
chunk_idx = 1
86+
bytes_in_chunk = 0
87+
88+
def open_chunk(idx):
89+
suffix = "" if idx == 1 else f".part{idx}"
90+
path = out_prefix if idx == 1 else out_prefix.with_name(out_prefix.name + suffix)
91+
return path, io.open(path, "w", encoding="utf-8", newline="\n")
92+
93+
out_path, fh = open_chunk(chunk_idx)
94+
95+
count = 0
96+
for p in iter_repo_files(repo_root, force_git):
97+
rel = p.relative_to(repo_root).as_posix()
98+
if should_exclude_by_glob(rel):
99+
continue
100+
if not should_keep_by_ext(p, DEFAULT_INCLUDE_EXTS):
101+
continue
102+
if not is_text_file(str(p)):
103+
continue
104+
105+
header = f"File: {rel}\nContents:\n"
106+
try:
107+
with io.open(p, "r", encoding="utf-8") as rf:
108+
content = rf.read()
109+
except UnicodeDecodeError:
110+
with io.open(p, "r", encoding="latin-1") as rf:
111+
content = rf.read()
112+
113+
block = header + content.rstrip() + "\n\n"
114+
block_bytes = len(block.encode("utf-8"))
115+
116+
if bytes_in_chunk + block_bytes > max_bytes and bytes_in_chunk > 0:
117+
fh.close()
118+
chunk_idx += 1
119+
out_path, fh = open_chunk(chunk_idx)
120+
bytes_in_chunk = 0
121+
122+
fh.write(block)
123+
bytes_in_chunk += block_bytes
124+
count += 1
125+
126+
fh.close()
127+
return chunk_idx, count
128+
129+
def main():
130+
ap = argparse.ArgumentParser(description="Dump repo sources to 'File: ...\\nContents:\\n...' format, honoring .gitignore.")
131+
ap.add_argument("--repo", default=".", help="Path to repo root (default: .)")
132+
ap.add_argument("--out", default="src.txt", help="Output filename/prefix")
133+
ap.add_argument("--max-mb", type=float, default=100.0, help="Max size per output file in MB (default: 100MB)")
134+
ap.add_argument("--git-mode", action="store_true", help="Force using 'git ls-files' (best accuracy for .gitignore).")
135+
args = ap.parse_args()
136+
137+
repo_root = pathlib.Path(args.repo)
138+
out_prefix = pathlib.Path(args.out)
139+
140+
try:
141+
chunks, files = write_repo(repo_root, out_prefix, args.max_mb, args.git_mode)
142+
print(f"Wrote {chunks} file(s); included {files} text source files. Upload the first file and any '.partN' files too.")
143+
except subprocess.CalledProcessError as e:
144+
print("Warning: Git mode failed; falling back to walk() (may include gitignored files).", file=sys.stderr)
145+
chunks, files = write_repo(repo_root, out_prefix, args.max_mb, force_git=False)
146+
print(f"Wrote {chunks} file(s); included {files} text source files. Upload the first file and any '.partN' files too.")
147+
148+
if __name__ == "__main__":
149+
sys.exit(main())
150+

utils/get_company_project_cla_managers.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
#!/bin/bash
22
# API_URL=https://[xyz].ngrok-free.app (defaults to localhost:5000)
3-
# API_URL=https://api.lfcla.dev.platform.linuxfoundation.org
3+
# API_URL=https://api-gw.platform.linuxfoundation.org/cla-service
4+
# API_URL=https://api-gw.dev.platform.linuxfoundation.org/cla-service
45
# DEBUG='' ./utils/get_company_project_cla_managers.sh f7c7ac9c-4dbf-4104-ab3f-6b38a26d82dc a09P000000DsCE5IAN
56
# Note: To run manually see cla-backend-go/auth/authorizer.go:SecurityAuth() and update accordingly 'LG:'
7+
# STAGE=prod ./utils/scan.sh projects-cla-groups project_name 'Cloud Native Computing Foundation (CNCF)'
8+
# STAGE=prod ./utils/scan.sh companies company_name 'Red Hat, Inc.'
9+
# ./get_oauth_token_prod.sh
10+
# DEBUG='' API_URL=https://api-gw.platform.linuxfoundation.org/cla-service ./utils/get_company_project_cla_managers.sh '86fda258-9866-45e3-b4fe-50502ac0957c' 'a0941000002wBz4AAE'
611

712
if [ -z "$TOKEN" ]
813
then
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash
2+
# API_URL=https://api-gw.platform.linuxfoundation.org/cla-service
3+
# API_URL=https://api-gw.dev.platform.linuxfoundation.org/cla-service
4+
# STAGE=prod ./utils/scan.sh projects project_id d8cead54-92b7-48c5-a2c8-b1e295e8f7f1
5+
# STAGE=prod ./utils/scan.sh projects-cla-groups project_name 'Cloud Native Computing Foundation (CNCF)'
6+
# STAGE=prod ./utils/scan.sh companies company_name 'Red Hat, Inc.'
7+
# STAGE=prod ./utils/scan.sh users lf_username lgryglicki
8+
# API_URL=https://api-gw.platform.linuxfoundation.org/cla-service ./utils/notify_cla_managers_example_post.sh
9+
10+
if [ -z "$TOKEN" ]
11+
then
12+
# source ./auth0_token.secret
13+
TOKEN="$(cat ./auth0.token.secret)"
14+
fi
15+
16+
if [ -z "$TOKEN" ]
17+
then
18+
echo "$0: TOKEN not specified and unable to obtain one"
19+
exit 1
20+
fi
21+
22+
if [ -z "$XACL" ]
23+
then
24+
XACL="$(cat ./x-acl.secret)"
25+
fi
26+
27+
if [ -z "$XACL" ]
28+
then
29+
echo "$0: XACL not specified and unable to obtain one"
30+
exit 2
31+
fi
32+
33+
if [ -z "$API_URL" ]
34+
then
35+
export API_URL="http://localhost:5001"
36+
fi
37+
38+
data='{
39+
"companyName": "Cloud Native Computing Foundation (CNCF)",
40+
"claGroupID": "d8cead54-92b7-48c5-a2c8-b1e295e8f7f1",
41+
"userID": "2c895887-d33a-11ef-9205-4e2baeedbda2",
42+
"list": [
43+
{ "email": "[email protected]", "name": "Lukasz Gryglicki 1" },
44+
{ "email": "[email protected]", "name": "Lukasz Gryglicki 2" },
45+
{ "email": "[email protected]", "name": "Lukasz Gryglicki 3" }
46+
]
47+
}'
48+
49+
curl -s -XPOST -H "X-ACL: ${XACL}" -H "Authorization: Bearer ${TOKEN}" -H "Content-Type: application/json" "${API_URL}/v4/notify-cla-managers" -d "$data" | jq -r '.'

0 commit comments

Comments
 (0)