@@ -704,6 +704,31 @@ def get_pullrequest(self, project, repository, pull_request_id):
704704 pullRequestId = pull_request_id )
705705 return self .get (url )
706706
707+ def change_reviewed_status (self , projectKey , repositorySlug , pullRequestId , status , userSlug ):
708+ """
709+ Change the current user's status for a pull request.
710+ Implicitly adds the user as a participant if they are not already.
711+ If the current user is the author, this method will fail.
712+ :param projectKey:
713+ :param repositorySlug:
714+ :param pullRequestId:
715+ :param status:
716+ :param userSlug:
717+ :return:
718+ """
719+ url = "/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId}/participants/{userSlug}" .format (
720+ projectKey = projectKey , repositorySlug = repositorySlug , pullRequestId = pullRequestId , userSlug = userSlug ,
721+ )
722+ approved = True if status == "APPROVED" else False
723+ data = {
724+ "user" : {
725+ "name" : userSlug
726+ },
727+ "approved" : approved ,
728+ "status" : status
729+ }
730+ return self .put (url , data )
731+
707732 def get_tags (self , project , repository , filter = '' , limit = 1000 , order_by = None , start = 0 ):
708733 """
709734 Retrieve the tags matching the supplied filterText param.
@@ -1139,7 +1164,7 @@ def upload_plugin(self, plugin_path):
11391164 'upm-token' ]
11401165 url = 'rest/plugins/1.0/?token={upm_token}' .format (upm_token = upm_token )
11411166 return self .post (url , files = files , headers = headers )
1142-
1167+
11431168 def upload_file (self , project , repository , content , message , branch , filename ):
11441169 """
11451170 Upload new file for given branch.
@@ -1153,13 +1178,13 @@ def upload_file(self, project, repository, content, message, branch, filename):
11531178 "message" : message ,
11541179 "branch" : branch
11551180 }
1156-
1181+
11571182 url = 'rest/api/1.0/projects/{project}/repos/{repository}/browse/{filename}' .format (
11581183 project = project ,
11591184 repository = repository ,
11601185 filename = filename )
11611186 return self .put (url , files = data )
1162-
1187+
11631188 def update_file (self , project , repository , content , message , branch , filename , sourceCommitId ):
11641189 """
11651190 Update existing file for given branch.
@@ -1178,9 +1203,54 @@ def update_file(self, project, repository, content, message, branch, filename, s
11781203 "branch" : branch ,
11791204 "sourceCommitId" : sourceCommitId
11801205 }
1181-
1206+
11821207 url = 'rest/api/1.0/projects/{project}/repos/{repository}/browse/{filename}' .format (
11831208 project = project ,
11841209 repository = repository ,
11851210 filename = filename )
1186- return self .put (url , files = data )
1211+ return self .put (url , files = data )
1212+
1213+ def get_code_insights_report (self , projectKey , repositorySlug , commitId , report_key ):
1214+ """
1215+ Retrieve the specified code-insights report.
1216+ :projectKey: str
1217+ :repositorySlug: str
1218+ :commitId: str
1219+ :report_key: str
1220+ """
1221+ url = "/rest/insights/1.0/projects/{projectKey}/repos/{repositorySlug}/commits/{commitId}/reports/{key}" .format (
1222+ projectKey = projectKey , repositorySlug = repositorySlug , commitId = commitId , key = report_key
1223+ )
1224+ return self .get (url )
1225+
1226+ def delete_code_insights_report (self , projectKey , repositorySlug , commitId , report_key ):
1227+ """
1228+ Delete a report for the given commit. Also deletes any annotations associated with this report.
1229+ :projectKey: str
1230+ :repositorySlug: str
1231+ :commitId: str
1232+ :report_key: str
1233+ """
1234+ url = "/rest/insights/1.0/projects/{projectKey}/repos/{repositorySlug}/commits/{commitId}/reports/{key}" .format (
1235+ projectKey = projectKey , repositorySlug = repositorySlug , commitId = commitId , key = report_key
1236+ )
1237+ return self .delete (url )
1238+
1239+ def create_code_insights_report (self , projectKey , repositorySlug , commitId , report_key , report_title , ** report_params ):
1240+ """
1241+ Create a new insight report, or replace the existing one if a report already exists for the given repository, commit, and report key.
1242+ A request to replace an existing report will be rejected if the authenticated user was not the creator of the specified report.
1243+ For further information visit: https://docs.atlassian.com/bitbucket-server/rest/6.6.1/bitbucket-code-insights-rest.html
1244+ :projectKey: str
1245+ :repositorySlug: str
1246+ :commitId: str
1247+ :report_key: str
1248+ :report_title: str
1249+ :report_params:
1250+ """
1251+ url = "/rest/insights/1.0/projects/{projectKey}/repos/{repositorySlug}/commits/{commitId}/reports/{key}" .format (
1252+ projectKey = projectKey , repositorySlug = repositorySlug , commitId = commitId , key = report_key
1253+ )
1254+ data = {"title" : report_title }
1255+ data .update (report_params )
1256+ return self .put (url , data = data )
0 commit comments