11import datetime
2- import json
32import os
43
54import boto3
@@ -29,23 +28,7 @@ def get_diff(repository_name, last_commit_id, previous_commit_id):
2928 afterCommitSpecifier = last_commit_id
3029 )
3130
32- differences = []
33-
34- if response is None :
35- return differences
36-
37- while "nextToken" in response :
38- response = codecommit .get_differences (
39- repositoryName = repository_name ,
40- beforeCommitSpecifier = previous_commit_id ,
41- afterCommitSpecifier = last_commit_id ,
42- nextToken = response ["nextToken" ]
43- )
44- differences += response .get ("differences" , [])
45- else :
46- differences += response ["differences" ]
47-
48- return differences
31+ return response ["differences" ]
4932
5033
5134def get_diff_change_message_type (change_type ):
@@ -74,7 +57,6 @@ def get_last_commit_log(repository, commit_id):
7457
7558
7659def get_message_text (differences , last_commit ):
77- print (last_commit )
7860 text = ''
7961 commit_id = last_commit ['commitId' ]
8062 text += f'commit ID: { commit_id } \n '
@@ -98,7 +80,8 @@ def get_message_text(differences, last_commit):
9880 get_diff_change_message_type (diff ['changeType' ]),
9981 diff ['beforeBlob' ]['blobId' ])
10082
101- text += (f'Commit: https://{ AWS_DEFAULT_REGION } .console.aws.amazon.com/codesuite/'
83+ text += (f'Commit: '
84+ f'https://{ AWS_DEFAULT_REGION } .console.aws.amazon.com/codesuite/'
10285 f'codecommit/repositories/{ REPOSITORY_NAME } /commit/{ commit_id } ?'
10386 f'region={ AWS_DEFAULT_REGION } ' )
10487
@@ -114,13 +97,10 @@ def publish(repository, message):
11497
11598
11699def lambda_handler (event , context ):
117- print (json .dumps (event ))
118-
119- repository = REPOSITORY_NAME
120100
121101 try :
122- last_commit_id = get_last_commit_id (repository , MAIN_BRANCH_NAME )
123- last_commit = get_last_commit_log (repository , last_commit_id )
102+ last_commit_id = get_last_commit_id (REPOSITORY_NAME , MAIN_BRANCH_NAME )
103+ last_commit = get_last_commit_log (REPOSITORY_NAME , last_commit_id )
124104
125105 previous_commit_id = None
126106 if len (last_commit ['parents' ]) > 0 :
@@ -129,15 +109,18 @@ def lambda_handler(event, context):
129109 print (f'Last commit ID: { last_commit_id } ' )
130110 print (f'Previous commit ID: { previous_commit_id } ' )
131111
132- differences = get_diff (repository , last_commit_id , previous_commit_id )
112+ differences = get_diff (
113+ REPOSITORY_NAME , last_commit_id , previous_commit_id )
133114 message_text = get_message_text (differences , last_commit )
134115
135- return publish (repository , message_text )
116+ print (message_text )
117+
118+ return publish (REPOSITORY_NAME , message_text )
136119
137120 except Exception as e :
138121 import traceback
139122 print (e )
140123 traceback .print_exc ()
141- print (f'Error getting repository { repository } . Ensure it exists in the '
142- 'same region as this function.' )
124+ print (f'Error getting repository { REPOSITORY_NAME } . Ensure it exists '
125+ 'in the same region as this function.' )
143126 raise e
0 commit comments