The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
In a Bitbucket Server add-on I like to create pull request comments of more than 32kB length. But the length is limited to that.
My idea is to create a text-file and attach it by Java API to that pull request.
There is the class com.atlassian.stash.internal.attach.AttachmentService in bitbucket-service-api-4.14.7.jar, but it seems to be internal only and not reachable at runtime from within my add-on.
Any ideas how to create an attachment? Or in general, how to add that information to a pull request?
Kind regards, Johannes
Relevant for those who are below 7.x, above packages changed. and the type that is returned from attachmentService is now different. But that code should be the inspiration
import com.atlassian.stash.internal.attach.AttachmentService
import com.atlassian.stash.internal.attach.AttachmentSupplier
import java.nio.charset.StandardCharsets
import com.atlassian.bitbucket.comment.AddCommentRequest
import com.atlassian.bitbucket.comment.AddCommentRequest.Builder
def PullRequest epr = event.getPullRequest();
def fromRefId = epr.fromRef.getId();
def toRefId = epr.toRef.getId();
def mergeCommit = event.commit.displayId
def StringBuilder sb = new StringBuilder();
epr.changesets.each{changeset -> changeset.changes.values.each{ change -> sb.append( change.getType().name() + " " + change.getPath() + "\n") } }
def att = attachmentService.save(event.repository, new AttachmentSupplier(){
public String getName(){
return "hoc.txt";
}
public long getSize(){
return sb.length();
}
public InputStream open(){
return new ByteArrayInputStream(sb.toString().getBytes(StandardCharsets.UTF_8));
}
})
def AddCommentRequest commentRequest = new AddCommentRequest.Builder(epr, "[hoc.txt](attachment:192/" + att +")").build();
commentService.addComment(commentRequest);
Beginning on April 4th, we will be implementing push limits. This means that your push cannot be completed if it is over 3.5 GB. If you do attempt to complete a push that is over 3.5 GB, it will fail...
Connect with like-minded Atlassian users at free events near you!
Find an eventConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.
Host an eventYou're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.