@@ -70,6 +70,18 @@ def find_pr() -> str:
70
70
else :
71
71
raise Exception (f"The { event_type } event doesn\' t relate to a Pull Request." )
72
72
73
+ def current_user () -> str :
74
+ response = github .get ('https://api.github.com/user' )
75
+ if response .status_code != 403 :
76
+ user = response .json ()
77
+ debug ('GITHUB_TOKEN user:' )
78
+ debug (json .dumps (user ))
79
+
80
+ return user ['login' ]
81
+
82
+ # Assume this is the github actions app token
83
+ return 'github-actions[bot]'
84
+
73
85
class TerraformComment :
74
86
"""
75
87
The GitHub comment for this specific terraform plan
@@ -90,8 +102,8 @@ def __init__(self, pr_url: str):
90
102
debug ('Looking for an existing comment:' )
91
103
for comment in response .json ():
92
104
debug (json .dumps (comment ))
93
- if comment ['user' ]['login' ] == 'github-actions[bot]' :
94
- match = re .match (rf'{ re .escape (self ._comment_identifier )} \n```(.*?)```(.*)' , comment ['body' ], re .DOTALL )
105
+ if comment ['user' ]['login' ] == current_user () :
106
+ match = re .match (rf'{ re .escape (self ._comment_identifier )} \n```(?:hcl)?( .*?)```(.*)' , comment ['body' ], re .DOTALL )
95
107
96
108
if not match :
97
109
match = re .match (rf'{ re .escape (self ._old_comment_identifier )} \n```(.*?)```(.*)' , comment ['body' ], re .DOTALL )
@@ -232,7 +244,7 @@ def status(self, status: str) -> None:
232
244
self ._status = status .strip ()
233
245
234
246
def update_comment (self ):
235
- body = f'{ self ._comment_identifier } \n ```\n { self .plan } \n ```'
247
+ body = f'{ self ._comment_identifier } \n ```hcl \n { self .plan } \n ```'
236
248
237
249
if self .status :
238
250
body += '\n ' + self .status
0 commit comments