Forge repo instructions - 07-add-product-trigger-solution

[Bonus Exercise] Add a new module to your manifest: trigger

At this point, you can already call external APIs and was able to work with different UI Kit components. Congratulations!

For this exercise, we’ll work with components that reside behind the scenes. We’ll add a new module to our app and listen to events that happen to the product; in this use case, we are looking out for new work items being created on Jira.

Add new trigger module to your manifest file

Yes, that is correct. We can add modules to our existing manifest without going through forge create all the time.

  1. Go to your Forge CLI and run the forge module add command to add a new trigger.

    If your Forge tunnel is still running, stop it by pressing CTRL + C before calling this command

    forge module add
    
    

    Select the following options

    ? Select a product Trigger
    ? Select a module trigger          - Run a Forge function in response to Atlassian product events
    ? Module key product-trigger
    ? Function key product-trigger-fn
    
    

    This will update your manifest.yml file to add the new trigger listening for the Jira issue created event

    trigger:
      - key: product-trigger
        function: product-trigger-fn
        events:
          - avi:jira:created:issue
        filter:
          ignoreSelf: false
          expression: event.issue.fields.summary != null
    
    

    The function handler has been wired for us

    function:
      - key: resolver
        handler: index.handler
      - key: product-trigger-fn
        handler: product-trigger.run    
    
    

    The necessary permission scope has been added, too!

    permissions:
      ...
      scopes: [ read:jira-work ]
    
    
  2. Verify the function that your trigger will call. The forge module add command has already created the new file src/product-trigger.js which contains the function

    export const run = (event) => {
      console.log('Received product event', JSON.stringify(event));
    };
    
    

Test if the product trigger is being called

  1. Deploy your changes. Given that we updated the permissions, we need to approve the major version bump by adding --approve MAJOR VERSION_RULE

    forge deploy --approve MAJOR_VERSION_RULE
    
    
  2. Since there’s a change in the permissions, we need to upgrade the installation, too.

    forge install --upgrade
    
    
  3. Run the tunnel to see the logs

    forge tunnel
    
    
  4. Create a new work item and verify that the tunnel’s console printed out our logs.