Skip to content

Commit b09977d

Browse files
Merge pull request #4726 from linuxfoundation/unicron-4701-allow-bots-to-skip-cla-post-deploy-updates
Add more visibility and fix one dminor debugging message in another function
2 parents 5a9689c + 03598e3 commit b09977d

File tree

4 files changed

+53
-29
lines changed

4 files changed

+53
-29
lines changed

WHITELISTING_BOTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,4 @@ Or using AWS CLI:
109109
aws --profile "lfproduct-prod" dynamodb scan --table-name "cla-prod-github-orgs" --filter-expression "contains(organization_name,:v)" --expression-attribute-values "{\":v\":{\"S\":\"linuxfoundation\"}}" --max-items 100 | jq -r '.Items'
110110
```
111111

112+
To check for log entries related to skipping CLA check, you can use the following command: `` STAGE=dev DTFROM='1 hour ago' DTTO='1 second ago' ./utils/search_aws_log_group.sh 'cla-backend-dev-githubactivity' 'skip_cla' ``.

cla-backend-go/github/bots.go

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,27 @@ func isActorSkipped(actor *UserCommitSummary, config string) bool {
8585
return propertyMatches(usernamePattern, username) && propertyMatches(emailPattern, email)
8686
}
8787

88+
func actorToString(actor *UserCommitSummary) string {
89+
const nullStr = "(null)"
90+
if actor == nil {
91+
return nullStr
92+
}
93+
id, login, username, email := nullStr, nullStr, nullStr, nullStr
94+
if actor.CommitAuthor != nil && actor.CommitAuthor.ID != nil {
95+
id = fmt.Sprintf("%v", *actor.CommitAuthor.ID)
96+
}
97+
if actor.CommitAuthor != nil && actor.CommitAuthor.Login != nil {
98+
login = *actor.CommitAuthor.Login
99+
}
100+
if actor.CommitAuthor != nil && actor.CommitAuthor.Name != nil {
101+
username = *actor.CommitAuthor.Name
102+
}
103+
if actor.CommitAuthor != nil && actor.CommitAuthor.Email != nil {
104+
email = *actor.CommitAuthor.Email
105+
}
106+
return fmt.Sprintf("id='%v',login='%v',username='%v',email='%v'", id, login, username, email)
107+
}
108+
88109
// SkipWhitelistedBots- check if the actors are whitelisted based on the skip_cla configuration.
89110
// Returns two lists:
90111
// - actors still missing cla: actors who still need to sign the CLA after checking skip_cla
@@ -127,7 +148,6 @@ func SkipWhitelistedBots(ev events.Service, orgModel *models.GithubOrganization,
127148
}
128149

129150
var config string
130-
131151
// 1. Exact match
132152
if val, ok := skipCLA[repo]; ok {
133153
config = val
@@ -168,27 +188,21 @@ func SkipWhitelistedBots(ev events.Service, orgModel *models.GithubOrganization,
168188
log.WithFields(f).Debug("No skip_cla config found for repo, skipping whitelisted bots check")
169189
return actorsMissingCLA, []*UserCommitSummary{}
170190
}
171-
const nullStr = "(null)"
191+
192+
// Log full configuration
193+
actorDebugData := make([]string, 0, len(actorsMissingCLA))
194+
for _, a := range actorsMissingCLA {
195+
actorDebugData = append(actorDebugData, actorToString(a))
196+
}
197+
log.WithFields(f).Debugf("final skip_cla config for repo %s is %s; actorsMissingCLA: [%s]", orgRepo, config, strings.Join(actorDebugData, ", "))
172198

173199
for _, actor := range actorsMissingCLA {
200+
if actor == nil {
201+
continue
202+
}
203+
actorData := actorToString(actor)
204+
log.WithFields(f).Debugf("Checking actor: %s for skip_cla config: %s", actorData, config)
174205
if isActorSkipped(actor, config) {
175-
if actor == nil {
176-
continue
177-
}
178-
id, login, username, email := nullStr, nullStr, nullStr, nullStr
179-
if actor.CommitAuthor != nil && actor.CommitAuthor.ID != nil {
180-
id = fmt.Sprintf("%v", *actor.CommitAuthor.ID)
181-
}
182-
if actor.CommitAuthor != nil && actor.CommitAuthor.Login != nil {
183-
login = *actor.CommitAuthor.Login
184-
}
185-
if actor.CommitAuthor != nil && actor.CommitAuthor.Name != nil {
186-
username = *actor.CommitAuthor.Name
187-
}
188-
if actor.CommitAuthor != nil && actor.CommitAuthor.Email != nil {
189-
email = *actor.CommitAuthor.Email
190-
}
191-
actorData := fmt.Sprintf("id='%v',login='%v',username='%v',email='%v'", id, login, username, email)
192206
msg := fmt.Sprintf(
193207
"Skipping CLA check for repo='%s', actor: %s due to skip_cla config: '%s'",
194208
orgRepo, actorData, config,
@@ -202,8 +216,6 @@ func SkipWhitelistedBots(ev events.Service, orgModel *models.GithubOrganization,
202216
ev.LogEvent(&events.LogEventArgs{
203217
EventType: events.BypassCLA,
204218
EventData: &eventData,
205-
UserID: id,
206-
UserName: login,
207219
ProjectID: projectID,
208220
})
209221
log.WithFields(f).Debugf("event logged")

cla-backend/cla/models/github_models.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ def update_merge_group_status(
597597
f"signing url: {sign_url}"
598598
)
599599
cla.log.warning(
600-
"{fn} - This is an error condition - "
600+
f"{fn} - This is an error condition - "
601601
f"should have at least one committer in one of these lists: "
602602
f"{len(signed)} passed, {missing}"
603603
)
@@ -1037,19 +1037,28 @@ def skip_whitelisted_bots(self, org_model, org_repo, actors_missing_cla) -> Tupl
10371037
cla.log.debug("No skip_cla config found for repo %s, skipping whitelisted bots check", org_repo)
10381038
return actors_missing_cla, []
10391039

1040+
actor_debug_data = [
1041+
f"id='{getattr(a, 'author_id', '(null)')}',"
1042+
f"login='{getattr(a, 'author_login', '(null)')}',"
1043+
f"username='{getattr(a, 'author_username', '(null)')}',"
1044+
f"email='{getattr(a, 'author_email', '(null)')}'"
1045+
for a in actors_missing_cla
1046+
]
1047+
cla.log.debug("final skip_cla config for repo %s is %s; actors_missing_cla: [%s]", org_repo, config, ", ".join(actor_debug_data))
10401048
out_actors_missing_cla = []
10411049
whitelisted_actors = []
10421050
for actor in actors_missing_cla:
10431051
if actor is None:
10441052
continue
10451053
try:
1054+
actor_data = "id='{}',login='{}',username='{}',email='{}'".format(
1055+
getattr(actor, "author_id", "(null)"),
1056+
getattr(actor, "author_login", "(null)"),
1057+
getattr(actor, "author_username", "(null)"),
1058+
getattr(actor, "author_email", "(null)"),
1059+
)
1060+
cla.log.debug("Checking actor: %s for skip_cla config: %s", actor_data, config)
10461061
if self.is_actor_skipped(actor, config):
1047-
actor_data = "id='{}',login='{}',username='{}',email='{}'".format(
1048-
getattr(actor, "author_id", "(null)"),
1049-
getattr(actor, "author_login", "(null)"),
1050-
getattr(actor, "author_username", "(null)"),
1051-
getattr(actor, "author_email", "(null)"),
1052-
)
10531062
msg = "Skipping CLA check for repo='{}', actor: {} due to skip_cla config: '{}'".format(
10541063
org_repo,
10551064
actor_data,
@@ -1912,7 +1921,7 @@ def update_pull_request(
19121921
f"signing url: {sign_url}"
19131922
)
19141923
cla.log.warning(
1915-
"{fn} - This is an error condition - "
1924+
f"{fn} - This is an error condition - "
19161925
f"should have at least one committer in one of these lists: "
19171926
f"{len(signed)} passed, {missing}"
19181927
)

utils/skip_cla_entry.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
# delete-item Deletes the entire `skip_cla` entry.
77
#
88
# MODE=add-key ./utils/skip_cla_entry.sh sun-test-org 'repo1' 're:vee?rendra' '*'
9+
# MODE=add-key ./utils/skip_cla_entry.sh 'sun-test-org' 'repo1' 'lukaszgryglicki' 're:gryglicki'
910
# ./utils/scan.sh github-orgs organization_name sun-test-org
11+
# STAGE=dev DTFROM='1 hour ago' DTTO='1 second ago' ./utils/search_aws_log_group.sh 'cla-backend-dev-githubactivity' 'skip_cla'
1012

1113
if [ -z "$MODE" ]
1214
then

0 commit comments

Comments
 (0)