Skip to content

Commit 03598e3

Browse files
SPlit actor debugging info into a helper function
Signed-off-by: Lukasz Gryglicki <[email protected]>
1 parent 31aa026 commit 03598e3

File tree

1 file changed

+24
-38
lines changed

1 file changed

+24
-38
lines changed

cla-backend-go/github/bots.go

Lines changed: 24 additions & 38 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
@@ -171,48 +191,16 @@ func SkipWhitelistedBots(ev events.Service, orgModel *models.GithubOrganization,
171191

172192
// Log full configuration
173193
actorDebugData := make([]string, 0, len(actorsMissingCLA))
174-
const nullStr = "(null)"
175194
for _, a := range actorsMissingCLA {
176-
if a == nil {
177-
continue
178-
}
179-
id, login, username, email := nullStr, nullStr, nullStr, nullStr
180-
if a.CommitAuthor != nil && a.CommitAuthor.ID != nil {
181-
id = fmt.Sprintf("%v", *a.CommitAuthor.ID)
182-
}
183-
if a.CommitAuthor != nil && a.CommitAuthor.Login != nil {
184-
login = *a.CommitAuthor.Login
185-
}
186-
if a.CommitAuthor != nil && a.CommitAuthor.Name != nil {
187-
username = *a.CommitAuthor.Name
188-
}
189-
if a.CommitAuthor != nil && a.CommitAuthor.Email != nil {
190-
email = *a.CommitAuthor.Email
191-
}
192-
actorDebugData = append(actorDebugData,
193-
fmt.Sprintf("id='%v',login='%v',username='%v',email='%v'", id, login, username, email))
195+
actorDebugData = append(actorDebugData, actorToString(a))
194196
}
195-
log.WithFields(f).Debugf("final skip_cla config for repo %s is %s; actorsMissingCLA: [%s]",
196-
orgRepo, config, strings.Join(actorDebugData, "; "))
197+
log.WithFields(f).Debugf("final skip_cla config for repo %s is %s; actorsMissingCLA: [%s]", orgRepo, config, strings.Join(actorDebugData, ", "))
197198

198199
for _, actor := range actorsMissingCLA {
199200
if actor == nil {
200201
continue
201202
}
202-
id, login, username, email := nullStr, nullStr, nullStr, nullStr
203-
if actor.CommitAuthor != nil && actor.CommitAuthor.ID != nil {
204-
id = fmt.Sprintf("%v", *actor.CommitAuthor.ID)
205-
}
206-
if actor.CommitAuthor != nil && actor.CommitAuthor.Login != nil {
207-
login = *actor.CommitAuthor.Login
208-
}
209-
if actor.CommitAuthor != nil && actor.CommitAuthor.Name != nil {
210-
username = *actor.CommitAuthor.Name
211-
}
212-
if actor.CommitAuthor != nil && actor.CommitAuthor.Email != nil {
213-
email = *actor.CommitAuthor.Email
214-
}
215-
actorData := fmt.Sprintf("id='%v',login='%v',username='%v',email='%v'", id, login, username, email)
203+
actorData := actorToString(actor)
216204
log.WithFields(f).Debugf("Checking actor: %s for skip_cla config: %s", actorData, config)
217205
if isActorSkipped(actor, config) {
218206
msg := fmt.Sprintf(
@@ -228,8 +216,6 @@ func SkipWhitelistedBots(ev events.Service, orgModel *models.GithubOrganization,
228216
ev.LogEvent(&events.LogEventArgs{
229217
EventType: events.BypassCLA,
230218
EventData: &eventData,
231-
UserID: id,
232-
UserName: login,
233219
ProjectID: projectID,
234220
})
235221
log.WithFields(f).Debugf("event logged")

0 commit comments

Comments
 (0)