Connecting Jira webhooks to SOLID PODs

Connecting Jira webhooks to SOLID PODs

To connect a Jira webhook to a Solid POD, you can create an Express web application that listens for incoming Jira webhook events, parses the event data, and writes the data to a Solid POD using the solid-client library.

Here’s an example of how to create an Express application that listens for incoming Jira webhook events and writes the issue data to a Solid POD:

First, install the necessary dependencies:

npm install express body-parser solid-client

Create an app.js file and import the required modules:

const express = require("express");
const bodyParser = require("body-parser");
const { getClient } = require("@inrupt/solid-client");
const {
  createSolidDataset,
  createThing,
  setThing
} = require("@inrupt/solid-client");
const { FOAF, VCARD, RDF } = require("@inrupt/vocab-common-rdf");

const app = express();
app.use(bodyParser.json());

Define the Solid POD endpoint and login with a WebID:

const solidEndpoint = "https://your-pod-url.com/";
const webId = "https://your-webid-url.com/";

const client = getClient();
await client.login({ oidcIssuer: solidEndpoint, redirectUrl: webId });

Define a route to handle incoming webhook events:

app.post("/jira-webhook", async (req, res) => {
  const event = req.body;
  console.log("Received Jira webhook event:", event);

  // Extract relevant data from the event payload
  const issue = {
    id: event.issue.id,
    key: event.issue.key,
    summary: event.issue.fields.summary,
    description: event.issue.fields.description,
    status: event.issue.fields.status.name,
    created: event.issue.fields.created,
    updated: event.issue.fields.updated,
    issuetype: event.issue.fields.issuetype.name,
    reporter: event.issue.fields.reporter.name,
    assignee: event.issue.fields.assignee.name
  };

  // Write the issue data to a Solid POD
  const dataset = await createSolidDataset();
  const thing = createThing({ name: `Jira Issue ${issue.id}` });
  setThing(dataset, thing);

  thing.addString(RDF.type, FOAF.Document);
  thing.addString(FOAF.maker, issue.reporter);
  thing.addString(VCARD.status, issue.status);
  thing.addString(VCARD.description, issue.description);
  thing.addString(VCARD.created, issue.created);
  thing.addString(VCARD.updated, issue.updated);
  thing.addString(VCARD.issuetype, issue.issuetype);
  thing.addString(VCARD.assignee, issue.assignee);

  const podUrl = `${solidEndpoint}public/issues/${issue.id}.ttl`;
  const savedDataset = await client.fetch(podUrl, {
    method: "PUT",
    body: dataset
  });

  console.log(`Issue data saved to Solid POD: ${savedDataset}`);

  res.status(200).send("Webhook event received");
});

Start the Express server:

const port = process.env.PORT || 3000;
app.listen(port, () => {
  console.log(`Server is running on port ${port}`);
});

Create a webhook in Jira that points to the URL of your Express server followed by /jira-webhook. Make sure to select the appropriate events that should trigger the webhook.

With this code, your Express application will listen for incoming Jira webhook events and extract the relevant data from the event payload. The application will then write the issue data to a Solid POD using the solid-client library. You can adapt this code to write different types of data to your Solid POD as needed.

Note that this example code assumes that you have already set up your Solid POD and have granted your WebID the necessary permissions to write to the desired location in your POD. If you haven’t done so yet, you may need to configure your POD’s access control settings to allow write access for your WebID.