How to enclose file to pull request comment via REST API

お困りですか?

アトラシアン コミュニティをご利用ください。

コミュニティに質問

背景

Bitbucket Server pull request comments allow to enclose file(s) from local drive (via Bitbucket Server UI) and in this Knowledge Base Article we will be demonstrating how to enclose file to pull request comment via REST API.

Create a file

foo.txt
foo A
foo B
foo C

Add file as attachment

curl -k -u admin:admin \
     -X POST 'http://localhost:7990/projects/{projectKey}/repos/{repositorySlug}/attachments' \
     -H 'Content-Type: multipart/form-data;' \
     -F 'files=@foo.txt'

As a response, you should expect:

Sample response
{
	"attachments": [
		{
			"id": "5b3728a433/foo.txt",
			"url": "http://localhost:7990/projects/{projectKey}/repos/{repositorySlug}/attachments/5b3728a433/foo.txt",
			"links": {
				"self": {
					"href": "http://localhost:7990/projects/{projectKey}/repos/{repositorySlug}/attachments/5b3728a433/foo.txt"
				},
				"attachment": {
					"href": "attachment:1/5b3728a433%2Ffoo.txt"
				}
			}
		}
	]
}

Add comment to pull-request, referring attachment in comment's message

curl -k -u admin:admin \
     -H 'Content-type: application/json' \
     -X POST 'http://localhost:7990/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId}/comments' \
     -d '{"text": "From Local Drive - [foo.txt](http://localhost:7990/projects/{projectKey}/repos/{repositorySlug}/attachments/5b3728a433/foo.txt)"}'

As a response, you should expect:

Sample response
{
	"properties": {
		"repositoryId": 1
	},
	"id": 45,
	"version": 0,
	"text": "From Local Drive - [foo.txt](http://localhost:7990/projects/{projectKey}/repos/{repositorySlug}/attachments/5b3728a433/foo.txt)",
	"author": {
		"name": "admin",
		"emailAddress": "admin@local.host",
		"id": 1,
		"displayName": "Admin Istrator",
		"active": true,
		"slug": "admin",
		"type": "NORMAL",
		"links": {
			"self": [
				{
					"href": "http://localhost:7990/users/admin"
				}
			]
		}
	},
	"createdDate": 1528687290320,
	"updatedDate": 1528687290320,
	"comments": [

	],
	"tasks": [

	],
	"permittedOperations": {
		"editable": true,
		"deletable": true
	}
}

リファレンス

Further information on https://docs.atlassian.com/bitbucket-server/rest/<bitbucket-server-version>/bitbucket-rest.html


最終更新日 2018 年 6 月 18 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.