Create a Compass component when a new repository is created on GitHub


Intro video is not displayed because you have disallowed functional cookies.
Get Started

Not the template you're looking for? Browse more.

About ScriptRunner Connect


What is ScriptRunner Connect?

ScriptRunner Connect is an AI assisted code-first (JavaScript/TypeScript) integration platform (iPaaS) for building complex integrations and automations.

Can I try it out for free?

Yes. ScriptRunner Connect comes with a forever free tier.

Can I customize the integration logic?

Absolutely. The main value proposition of ScriptRunner Connect is that you'll get full access to the code that is powering the integration, which means you can make any changes to the the integration logic yourself.

Can I change the integration to communicate with additional apps?

Yes. Since ScriptRunner Connect specializes in enabling complex integrations, you can easily change the integration logic to connect to as many additional apps as you need, no limitations.

What if I don't feel comfortable making changes to the code?

First you can try out our AI assistant which can help you understand what the code does, and also help you make changes to the code. Alternatively you can hire our professionals to make the changes you need or build new integrations from scratch.

Do I have to host it myself?

No. ScriptRunner Connect is a fully managed SaaS (Software-as-a-Service) product.

What about security?

ScriptRunner Connect is ISO 27001 and SOC 2 certified. Learn more about our security.

Template Content


README

Scripts

TypeScriptOnGitHubRepositories
Repositories

README


Create a Compass component when a new repository is created on GitHub

📋 Overview

This integration automatically creates Compass components when new GitHub repositories are created for Organisation. When a repository is created on GitHub, a webhook event triggers the creation of a corresponding SERVICE-type component in Compass with a direct link to the repository.

This template was developed with the assistance of an AI agent.

What it does:

  • Listens for GitHub repository creation events for Organisation via webhook
  • Automatically creates a Compass component with repository details
  • Links the Compass component to the GitHub repository for easy navigation

Business value:

  • Maintains an up-to-date inventory of services in Compass
  • Reduces manual component creation overhead
  • Ensures all new repositories are tracked in your architecture documentation
  • Provides quick access to repository links from Compass

🖊️ Setup

Connectors

Jira Cloud Connector (for Compass)

  • Create a Jira Cloud Connector in ScriptRunner Connect web UI
  • Configure the Connector using self-managed OAuth 2.0 app
  • Add appropriate Compass API scopes in the self-managed app: read:component:compass, write:component:compass
  • In the API connection details choose custom vendor API version - Compass GraphQL

Event Listeners

GitHub Repository Event Listener

  • Webhook Setup: Configure the webhook in your GitHub organization settings:
    • Go to Settings → Webhooks → Add webhook
    • Use the webhook URL provided in the Event Listener configuration
    • Set Content type to application/json
    • Select "Repositories" event type
    • Save the webhook

Parameters

CLOUD_ID (Text)

  • Description: Your Jira Cloud site ID, required for Compass API calls
  • How to find: Check the URL in your browser's address bar when logged into your Jira site, or visit https://your-domain.atlassian.net/_edge/tenant_info (replace your-domain with your site's name)
  • Example: a1b2c3d4e5f6g7h8i9j0k1l2
  • Required: Yes

COMPONENT_TYPE (Text)

  • Description: The type of Compass component to create when a repository is created
  • Valid values: APPLICATION, LIBRARY, SERVICE, OTHER
  • Example: SERVICE
  • Required: Yes

🚀 Using the Integration

Testing the Integration

  1. Using Event Listener Test Payload:

    • Navigate to the GitHub Repository Event Listener in ScriptRunner Connect web UI
    • Go to the "Test Event Payloads" tab
    • Configure a test payload with repository creation event data
    • Click the play button in the Event Listener item in the Resource Manager tree to trigger the script
  2. Creating a Test Repository:

    • Create a new repository in your GitHub organization
    • The webhook will automatically trigger the script
    • Check the Script Invocation Logs in ScriptRunner Connect web UI to verify execution

Verifying Success

  • Check Script Invocation Logs: Look for log entries confirming component creation
  • Verify in Compass: Navigate to Compass and search for the repository name to confirm the component was created
  • Check Component Details: Verify the component has the correct name, description, and repository link

Expected Behavior

  • Repository Created: A new component is created in Compass with:
    • Name matching the repository name
    • Type matching the COMPONENT_TYPE parameter value (default: SERVICE)
    • Description from the repository
    • A REPOSITORY-type link pointing to the GitHub repository URL
  • Other Repository Actions: Events like repository deletion or archival are logged but skipped (no component creation)

❗️ Considerations

  • Component Type: The component type is configurable via the COMPONENT_TYPE parameter. Valid values are APPLICATION, LIBRARY, SERVICE, or OTHER. Default to SERVICE if not specified.
  • Webhook Reliability: Ensure GitHub webhook delivery is configured correctly. Check webhook delivery logs in GitHub if events are not being received.
  • Rate Limiting: Compass API may have rate limits. If processing many repositories, consider adding retry logic or rate limiting handling.
  • Event Processing: Only repository creation events are processed. Other repository events (deleted, archived, renamed) are ignored.

API Connections


TypeScriptOnGitHubRepositories

import CompassGraphQL from './api/compass';
import { RepositoryEvent } from '@sr-connect/github/events';
import { mutation as buildMutation } from 'gql-query-builder';

/**
 * Event listener script that automatically creates Compass components when GitHub repositories are created.
 *
 * This script is triggered by GitHub repository webhook events and creates a corresponding
 * component in Compass with a link to the repository. Only processes 'created' actions and skips other
 * repository events (e.g., deleted, archived).
 *
 * @param event - GitHub repository event containing repository details and action type
 * @param context - ScriptRunner Connect context providing environment variables and invocation metadata
 */
export default async function (event: RepositoryEvent, context: Context<EV>): Promise<void> {
    const CLOUD_ID = context.environment.vars.CLOUD_ID;
    const TYPE = context.environment.vars.COMPONENT_TYPE;
    // Prevent manual execution - this script should only be triggered via Event Listener
    // Manual testing should use the Event Listener's Test Event Payload feature
    if (context.triggerType === 'MANUAL') {
        console.error(
            'This script is designed to be triggered externally or manually from the Event Listener. Please consider using Event Listener Test Event Payload if you need to trigger this script manually.',
        );
        return;
    }

    // Extract repository information from the GitHub webhook event
    const action = event.action;
    const name = event.repository.name;
    const description = event.repository.description;
    const url = event.repository.html_url;

    // Build GraphQL mutation to create a Compass component
    // Uses gql-query-builder to construct the mutation with proper type safety
    const { query, variables } = buildMutation(
        {
            operation: 'compass',
            fields: [
                {
                    operation: 'createComponent',
                    variables: {
                        // Jira Cloud ID required for Compass API - identifies the Atlassian site
                        cloudId: {
                            value: CLOUD_ID,
                            type: 'ID',
                            required: true,
                        },
                        // Component creation input with repository details
                        input: {
                            value: {
                                name,
                                typeId: TYPE, // Component type - by default SERVICE represents a service/application
                                description,
                                // Link to the GitHub repository for easy navigation from Compass
                                links: [
                                    {
                                        name: 'Repository',
                                        type: 'REPOSITORY',
                                        url,
                                    },
                                ],
                            },
                            type: 'CreateCompassComponentInput',
                            required: true,
                        },
                    },
                    // Request specific fields in the response for validation and logging
                    fields: [
                        'success',
                        {
                            componentDetails: ['id', 'name', 'description', 'typeId'],
                        },
                        {
                            errors: ['message'],
                        },
                    ],
                },
            ],
        },
        null,
        {
            operationName: 'CreateComponent',
        },
    );

    // Only process repository creation events - skip other actions (deleted, archived, etc.)
    if (action === 'created') {
        // Execute GraphQL mutation via Compass API Connection
        // The API Connection handles authentication automatically
        const response = await CompassGraphQL.fetch('/gateway/api/graphql', {
            method: 'POST',
            body: JSON.stringify({ query, variables }),
        });
        const componentCreated = await response.json();

        // Log success for monitoring and debugging
        if (componentCreated.data.compass.createComponent.success) {
            console.log(`Created component for repository "${name}" - ${url}`);
        } else {
            console.log('Component creation may have failed:', componentCreated);
        }
    } else {
        console.log('Skipping event. Reason: ', action);
    }
}

© 2025 ScriptRunner · Terms and Conditions · Privacy Policy · Legal Notice · Cookie Preferences