@@ -98,11 +98,14 @@ async def _perform_commands_bitbucket(commands_conf: str, agent: PRAgent, api_ur
98
98
99
99
def is_bot_user (data ) -> bool :
100
100
try :
101
- if data ["data" ]["actor" ]["type" ] != "user" :
102
- get_logger ().info (f"BitBucket actor type is not 'user': { data ['data' ]['actor' ]['type' ]} " )
101
+ actor = data .get ("data" , {}).get ("actor" , {})
102
+ # allow actor type: user . if it's "AppUser" or "team" then it is a bot user
103
+ allowed_actor_types = {"user" }
104
+ if actor and actor ["type" ].lower () not in allowed_actor_types :
105
+ get_logger ().info (f"BitBucket actor type is not 'user', skipping: { actor } " )
103
106
return True
104
107
except Exception as e :
105
- get_logger ().error ("Failed 'is_bot_user' logic: {e}" )
108
+ get_logger ().error (f "Failed 'is_bot_user' logic: { e } " )
106
109
return False
107
110
108
111
@@ -161,16 +164,18 @@ async def inner():
161
164
return "OK"
162
165
163
166
# Get the username of the sender
164
- try :
165
- username = data ["data" ]["actor" ]["username" ]
166
- except KeyError :
167
+ actor = data .get ("data" , {}).get ("actor" , {})
168
+ if actor :
167
169
try :
168
- username = data [ "data" ][ " actor" ][ "display_name " ]
170
+ username = actor [ "username " ]
169
171
except KeyError :
170
- username = data ["data" ]["actor" ]["nickname" ]
171
- log_context ["sender" ] = username
172
+ try :
173
+ username = actor ["display_name" ]
174
+ except KeyError :
175
+ username = actor ["nickname" ]
176
+ log_context ["sender" ] = username
172
177
173
- sender_id = data [ "data" ][ "actor" ][ "account_id" ]
178
+ sender_id = data . get ( "data" , {}). get ( "actor" , {}). get ( "account_id" , "" )
174
179
log_context ["sender_id" ] = sender_id
175
180
jwt_parts = input_jwt .split ("." )
176
181
claim_part = jwt_parts [1 ]
0 commit comments