Forge Comment Event Body as a String?

Hello,

I see that the Forge Comment interface is defined as such:

interface Comment {
  id: string;
  author: User;
  body: any;
  updateAuthor: User;
  created: string;
  updated: string;
  jsdPublic: boolean;
}

We noticed that in most cases, the body is a JSON object that follows the Atlassian Document Format, but in some cases it’s a string. What does any include here? Are the only 2 options, string or Atlassian Document format?

When we’ve recieved a string body, we noticed that there is some kind of templating markup being used inside with tags like * for emphasis {code} for preformatted text, etc.

In what cases would we expect the comment body to not be in ADF? Could a third party app be creating jira comments as strings? Is the jira admin able to redact comment bodies from being exposed to forge events?

Thanks!

Hi @DerekBrooks ,

My guess is the string based comments are those against pages encoded in the legacy editor format whilst the ADF comments are against pages encoded with the new editor. The new editor was released a few years ago and the rollout involved the conversion of most pages from the old format to the new format, but this conversion couldn’t automatically be done for some pages which utilised features of the old editor that are not available in the new editor. In addition, the migration of sites from server/DC to cloud is another source of content in the old editor format.

Dugald

1 Like

Hi @DerekBrooks ,

After taking another look at the Comment interface you shared, I see that you are asking about Jira issue comments.

I ran a test and can see that events triggered by Jira automation adding comments arrive in string format, whilst those triggered by the Jira issue UI arrive in ADF format.

Dugald

Hi @DerekBrooks ,

I’ve created a test app that confirms the format of the event is be dependent on the version of the Jira API (v2 or v3) used to add the comment. I’ll consult the Jira team to work out what type of action we need to take.

If you are interested, here’s my test code:

manifest.yml:

modules:
  trigger:
    - key: forge-issue-comment-handler
      function: main
      events:
        - avi:jira:commented:issue
  function:
    - key: main
      handler: index.run
app:
  runtime:
    name: nodejs18.x
  id: ari:cloud:ecosystem::app/xxxx
permissions:
  scopes:
    - read:jira-work
    - write:jira-work

index.js:

import api, { route } from "@forge/api";

export async function run(event, context) {
  const eventString = JSON.stringify(event, null, 2);
	console.log(`Received event:`);
	console.log(` * event: ${eventString}`);
	console.log(` * context: ${JSON.stringify(context, null, 2)}`);
  const createACommentWithV2 = eventString.indexOf("pls create a comment with v2") >= 0;
  const createACommentWithV3 = eventString.indexOf("pls create a comment with v3") >= 0;
  console.log(` * createACommentWithV2: ${createACommentWithV2}`);
  console.log(` * createACommentWithV3: ${createACommentWithV3}`);
  if (createACommentWithV2 || createACommentWithV3) {
    const commentText = "Lorem ipsum dolor sit amet, consectetur...";
    const comment = createACommentWithV2 ? commentText : {
      content: [
        {
          content: [
            {
              text: commentText,
              type: "text"
            }
          ],
          type: "paragraph"
        }
      ],
      type: "doc",
      version: 1
    };
    const bodyData = {
      body: comment
    };
    const issueIdOrKey = event.issue.key;
    const url = createACommentWithV2 ? route`/rest/api/2/issue/${issueIdOrKey}/comment` : route`/rest/api/3/issue/${issueIdOrKey}/comment`;
    console.log(` * creating a comment ${url}...`);
    const response = await api.asApp().requestJira(url, {
      method: 'POST',
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(bodyData)
    });
    console.log(`Response: ${response.status} ${response.statusText}`);
    console.log(await response.json());
  }
}

Dugald

2 Likes

@DerekBrooks ,

I’ve created JRACLOUD-84074: Forge issue comment events have varying comment formats - ADF and markup. I suggest voting for the issue to indicate your interest in having it fixed.

Dugald

2 Likes

Thanks @dmorrow! You have my vote for standardizing the comment body to be a single format.

In the mean time, is there documentation for the markup format that we can expect? Is it safe to assume that this is Confluence Wiki Markup with full macro support.

i.e. I see {code} in some of the comment body strings, but that’s not part of the standard Confluence Wiki Markup library. However, it appears to be supported by the Code Block Macro.

1 Like

Hi @DerekBrooks ,

Maybe Text Formatting Notation Help - Create and track feature requests for Atlassian products.

DUgald

1 Like