UP | HOME
Ravi Sagar | Home | Blog

Add comment on issue create trigger

Table of Contents

Let us continue developing apps using Forge.

1 Create the app.

forge create

Name: comment-issue-app Category: Triggers and Validator Template: product-trigger

2 App permissions

For adding comment we need to add scope to the manifest.yml the following lines.

permissions:
  scopes:
    - 'write:jira-work'

So the overall manifest.yml look like this.

permissions:
  scopes:
    - 'write:jira-work'
modules:
  trigger:
    - key: comment-issue-app-hello-world
      function: main
      events:
        - avi:jira:created:issue
  function:
    - key: main
      handler: index.run
app:
  id: ari:cloud:ecosystem::app/9a2232eb-b238-23ed0-8ab0-234f2f2
  name: comment-issue-app

3 Deploy and install.

Run forge deploy and then forge install.

Finally run sudo forge tunnel to ensure that further code changes are redeployed for you and you can also monitor the terminal.

4 Create an issue

The code in the index.jsx will listen for the issue create event and will display in the console.

export async function run(event, context) {
console.log('Hello World!');
}

If you see "Hello World" in your terminal then good news :).

5 Install @forge/api

This is needed to make REST API calls.

npm install @forge/api

6 Add code to add comment using REST API

7 TODO User not working

When I changed the code to use .asUser instead of .asApp() then I got the following error.

ERROR   15:25:13.396  03a32d7dca3a6078  [NEEDS_AUTHENTICATION_ERR: Authentication required] {
  serviceKey: 'atlassian-token-service-key'
}