コード例 #1
0
    def add_comment(self, sslVerify, token, mergeRequestId, newComments,
                    buildId, workspace, **kwargs):
        ''' Adds a new comment to the merge request '''

        commentBody = ' '.join(newComments)

        url = (
            f'{self.host}/api/v4/projects/{self.projectId}/merge_requests/{mergeRequestId}/notes'
        )
        payload = {'body': commentBody}
        headers = {'Private-Token': token}
        data = urllib.parse.urlencode(payload).encode('utf-8')

        print_key_value_list(f'{INFO_TAG} Adding new Comment to:',
                             [('Host URL', self.host),
                              ('Project Id', self.projectId),
                              ('Target Endpoint', url),
                              ('Comment', commentBody),
                              ('MergeRequest Id', mergeRequestId)])

        response = http_request(url, data, headers, 'POST', sslVerify)

        if response.statusCode == 201:
            commentId = str(response.responseBody['id'])
            save_comment_to_file(commentBody, buildId, commentId, workspace)
            print(
                f'{SUCCESS_LINE} Comment created succesfully with id \'{commentId}\', saved to ./{buildId}-comment.txt'
            )
        else:
            print(
                f'{ERROR_LINE} Could not create comment on merge request ({response.responseBody} -- {response.statusCode})'
            )
コード例 #2
0
	def add_comment(self, sslVerify, token, pullRequestId, newComments, buildId, workspace, **kwargs):
		''' Adds a new comment to the pull request '''

		commentBody	= ' '.join( newComments )

		url			= ( f'{self.host}/rest/api/1.0/projects/{self.project}/repos/{self.repository}/pull-requests/{pullRequestId}/comments' )
		headers		= { 'Authorization' : f'Bearer {token}', 'Content-Type' : 'application/json' }
		payload		= { 'text' : commentBody }
		payload		= json.dumps( payload )
		data		= payload.encode( 'utf-8' )
		
		print_key_value_list( f'{INFO_TAG} Adding new Comment to:', [
			( 'Host URL', self.host ), ( 'Project Name', self.project ), ( 'Repository', self.repository ), 
			( 'Target Endpoint', url), ( 'Comment', commentBody ), ( 'PullRequest Id', pullRequestId )
		] )

		response = http_request( url, data, headers, 'POST', sslVerify )

		if response.statusCode == 201:
			commentId		= str( response.responseBody[ 'id' ] )
			commentVersion	= str( response.responseBody[ 'version' ] )
			save_comment_to_file( commentBody, buildId, commentId, workspace, commentVersion )
			print( f'{SUCCESS_LINE} Comment created succesfully with id \'{commentId}\', saved to ./{buildId}-comment.txt' )
		else:
			print( f'{ERROR_LINE} Could not create comment on pull request ({response.responseBody} -- {response.statusCode})' )
コード例 #3
0
    def edit_comment(self, sslVerify, token, pullRequestId, newComments,
                     buildId, workspace, **kwargs):
        ''' Appends message to the pull request's comments '''

        commentId, lastComments = get_last_comment(workspace, buildId)
        commentBody = append_new_comments(newComments, lastComments)

        url = (
            f'{self.host}/api/2.0/repositories/{self.owner}/{self.projectName}/pullrequests/{pullRequestId}/comments/{commentId}'
        )
        headers = {
            'Authorization': f'Basic {token}',
            'Content-Type': 'application/json'
        }
        payload = {'content': {'raw': commentBody}}
        payload = json.dumps(payload)
        data = payload.encode('utf-8')

        print_key_value_list(f'{INFO_TAG} Edditing Comment to:',
                             [('Host URL', self.host), ('Owner', self.owner),
                              ('Project Name', self.projectName),
                              ('Target Endpoint', url),
                              ('Comment', commentBody),
                              ('PullRequest Id', pullRequestId)])

        response = http_request(url, data, headers, 'PUT', sslVerify)

        if response.statusCode == 200:
            commentId = str(response.responseBody['id'])
            save_comment_to_file(commentBody, buildId, commentId, workspace)
            print(
                f'{SUCCESS_LINE} Comment created succesfully with id \'{commentId}\', saved to ./{buildId}-comment.txt'
            )
        else:
            print(
                f'{ERROR_LINE} Could not edit comment on pull request ({response.responseBody} -- {response.statusCode})'
            )