← Gitlab + SWAPI - Star Wars integrations

Get Film with SWAPI - Star Wars APIon New Review Request (Instant) from Gitlab API

Pipedream makes it easy to connect APIs for SWAPI - Star Wars, Gitlab and + other apps remarkably fast.

Trigger workflow on
New Review Request (Instant) from the Gitlab API
Next, do this
Get Film with the SWAPI - Star Wars API
No credit card required
Trusted by 200,000+ developers from startups to Fortune 500 companies:
Trusted by 200,000+ developers from startups to Fortune 500 companies

Developers Pipedream

Getting Started

This integration creates a workflow with a Gitlab trigger and SWAPI - Star Wars action. When you configure and deploy the workflow, it will run on Pipedream's servers 24x7 for free.

  1. Select this integration
  2. Configure the New Review Request (Instant) trigger
    1. Connect your Gitlab account
    2. Select a Project ID
  3. Configure the Get Film action
    1. Connect your SWAPI - Star Wars account
    2. Select a film
  4. Deploy the workflow
  5. Send a test event to validate your setup
  6. Turn on the trigger

Details

This integration uses pre-built, open source components from Pipedream's GitHub repo. These components are developed by Pipedream and the community, and verified and maintained by Pipedream.

To contribute an update to an existing component or create a new component, create a PR on GitHub. If you're new to Pipedream component development, you can start with quickstarts for trigger span and action development, and then review the component API reference.

Trigger

Description:Emits an event when a reviewer is added to a merge request
Version:0.0.1
Key:gitlab-new-review-request

Trigger Code

const gitlab = require("../../gitlab.app.js");

module.exports = {
  key: "gitlab-new-review-request",
  name: "New Review Request (Instant)",
  description: "Emits an event when a reviewer is added to a merge request",
  version: "0.0.1",
  dedupe: "unique",
  props: {
    gitlab,
    projectId: { propDefinition: [gitlab, "projectId"] },
    http: {
      type: "$.interface.http",
      customResponse: true,
    },
    db: "$.service.db",
  },
  hooks: {
    async activate() {
      const hookParams = {
        merge_requests_events: true,
        push_events: false,
        url: this.http.endpoint,
      };
      const opts = {
        hookParams,
        projectId: this.projectId,
      };
      const { hookId, token } = await this.gitlab.createHook(opts);
      console.log(
        `Created "merge request events" webhook for project ID ${this.projectId}.
        (Hook ID: ${hookId}, endpoint: ${hookParams.url})`
      );
      this.db.set("hookId", hookId);
      this.db.set("token", token);
    },
    async deactivate() {
      const hookId = this.db.get("hookId");
      const opts = {
        hookId,
        projectId: this.projectId,
      };
      await this.gitlab.deleteHook(opts);
      console.log(
        `Deleted webhook for project ID ${this.projectId}.
        (Hook ID: ${hookId})`
      );
    },
  },
  methods: {
    getNewReviewers(body) {
      const { action, title } = body.object_attributes;

      // When a merge request is first created, any assignees
      // in it are interpreted as new review requests.
      if (action === "open" || action === "reopen") {
        const { assignees = [] } = body;
        return assignees;
      }

      // Gitlab API provides any merge request update diff
      // as part of their response. We can check the presence of
      // the `assignees` attribute within those changes to verify
      // if there are new review requests.
      const { assignees } = body.changes;
      if (!assignees) {
        console.log(`No new assignees in merge request "${title}"`);
        return [];
      }

      // If the assignees of the merge request changed, we need to compute
      // the difference in order to extract the new reviewers.
      const previousAssigneesUsernames = new Set(assignees.previous.map(a => a.username));
      const newAssignees = assignees.current.filter(a => !previousAssigneesUsernames.has(a.username));
      if (newAssignees.length > 0) {
        console.log(
          `Assignees added to merge request "${title}": ${newAssignees.map(a => a.username).join(', ')}`
        );
      }
      return newAssignees;
    },
    generateMeta(data, reviewer) {
      const {
        id,
        title,
        updated_at
      } = data.object_attributes;
      const summary = `New reviewer for "${title}": ${reviewer.username}`;
      const ts = +new Date(updated_at);
      const compositeId = `${id}-${ts}-${reviewer.username}`;
      return {
        id: compositeId,
        summary,
        ts,
      };
    },
  },
  async run(event) {
    const { headers, body } = event;

    // Reject any calls not made by the proper Gitlab webhook.
    if (!this.gitlab.isValidSource(headers, this.db)) {
      this.http.respond({
        status: 404,
      });
      return;
    }

    // Acknowledge the event back to Gitlab.
    this.http.respond({
      status: 200,
    });

    // Gitlab doesn't offer a specific hook for "new merge request reviewers" events,
    // but such event can be deduced from the payload of "merge request" events.
    this.getNewReviewers(body).forEach(reviewer => {
      const meta = this.generateMeta(body, reviewer);
      const event = {
        ...body,
        reviewer,
      };
      this.$emit(event, meta);
    });
  },
};

Trigger Configuration

This component may be configured based on the props defined in the component code. Pipedream automatically prompts for input values in the UI and CLI.
LabelPropTypeDescription
GitlabgitlabappThis component uses the Gitlab app.
Project IDprojectIdintegerSelect a value from the drop down menu.
N/Ahttp$.interface.httpThis component uses $.interface.http to generate a unique URL when the component is first instantiated. Each request to the URL will trigger the run() method of the component.
N/Adb$.service.dbThis component uses $.service.db to maintain state between component invocations.

Trigger Authentication

Gitlab uses OAuth authentication. When you connect your Gitlab account, Pipedream will open a popup window where you can sign into Gitlab and grant Pipedream permission to connect to your account. Pipedream securely stores and automatically refreshes the OAuth tokens so you can easily authenticate any Gitlab API.

Pipedream requests the following authorization scopes when you connect your account:

apiread_userread_repositorywrite_repositoryread_registrysudoopenidprofileemail

About Gitlab

Project planning and source code management

Action

Description:
Version:0.0.12
Key:swapi-get-film

Action Code

const swapi = require('../../swapi.app.js')
const axios = require('axios')

module.exports = {
  key: "swapi-get-film",
  name: "Get Film",
  version: "0.0.12",
  type: "action",
  props: {
    swapi,
    film: { propDefinition: [swapi, "film"] },
  },
  async run() {
    return (await axios({
      url: `https://swapi.dev/api/films/${this.film}`
    })).data
  },
}

Action Configuration

This component may be configured based on the props defined in the component code. Pipedream automatically prompts for input values in the UI.

LabelPropTypeDescription
SWAPI - Star WarsswapiappThis component uses the SWAPI - Star Wars app.
filmfilmstringSelect a value from the drop down menu.

Action Authentication

The SWAPI - Star Wars API does not require authentication.

About SWAPI - Star Wars

The Star Wars API

About Pipedream

Stop writing boilerplate code, struggling with authentication and managing infrastructure. Start connecting APIs with code-level control when you need it — and no code when you don't.

Into to Pipedream
Watch us build a workflow
Watch us build a workflow
4 min
Watch now ➜
"The past few weeks, I truly feel like the clichéd 10x engineer."
@heyellieday
Powerful features that scale
Manage concurrency and execution rate
Manage concurrency and execution rate

Queue up to 10,000 events per workfow and manage the concurrency and rate at which workflows are triggered.

Process large payloads up to 5 terabytes
Process large payloads up to 5 terabytes

Large file support enables you to trigger workflows with any data (e.g., large JSON files, images and videos) up to 5 terabytes.

Return custom responses to HTTP requests
Return custom responses to HTTP requests

Return any JSON-serializable response from an HTTP triggered workflow using $respond().

Use most npm packages
Use most npm packages

To use any npm package, just require() it -- there's no npm install or package.json required.

Maintain state between executions
Maintain state between executions

Use $checkpoint to save state in one workflow invocation and read it the next time your workflow runs.

Pass data between steps
Pass data between steps

Return data from any step to inspect it in a human-friendly way and reference the data in future steps via the steps object.