How to enclose file to pull request comment via REST API in Bitbucket Server/DataCenter

お困りですか?

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

コミュニティに質問

アトラシアン社外秘

この記事は未検証なのでお客様と共有できません。

プラットフォームについて: Server および Data Center のみ。この記事は、Server および Data Center プラットフォームのアトラシアン製品にのみ適用されます。

Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Fisheye および Crucible は除く

要約

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.

環境

Bitbucket Server and DataCenter version 7.16+

ソリューション

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 below. Please take note of the attachment value in the response text as you will need it for the next API command. For example, the attachment value for the response text below is 1/3.

応答の例
{"attachments":
 [
  {
    "id":"3",
    "url":"http://localhost:7990/bitbucket/projects/TEST/repos/attachments/attachments/3",
    "links":{
        "self":{"href":"http://localhost:7990/bitbucket/projects/TEST/repos/attachments/attachments/3"},
        "attachment":{"href":"attachment:1/3"}
    	 }
   }
 ]
}

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

Execute another API command to add a comment (with attachment) to a pull-request with the attachment value received from the previous API command. For example, the attachment value to add is 1/3.

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](attachment:1/3)"}'

As a response, you should expect:

応答の例
{
	"properties":{
		"repositoryId":1
	},
	"id":1,
	"version":0,
	"text":"From Local Drive - [foo.txt](attachment:1/1)",
	"author":{"name":"admin",
	"emailAddress":"admin@local.host",
	"id":2,
	"displayName":"admin",
	"active":true,
	"slug":"admin",
	"type":"NORMAL",
	"links":{
		"self":[
			{
				"href":"http://localhost:7990/users/admin"
			}
		]
	}
},
	"createdDate":1634907380937,
	"updatedDate":1634907380937,
	"comments":[

	],
	"tasks":[

	],
	"severity":"NORMAL",
	"state":"OPEN",
	"permittedOperations":{
		"editable":true,
		"transitionable":true,
		"deletable":true
	}
}

If you find any issue with the API call, please reach out to Bitbucket support.


最終更新日: 2022 年 10 月 7 日

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

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