4.3.0 • Published 8 months ago

@eng-automation/integrations v4.3.0

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
8 months ago

opstooling-integrations

Reusable third party integrations library

All integrations are unified under similar API, with following rules in mind:

  • Setup/configuration is supported in two ways:
    • Automatic (static): all options are in environment variables, and setup is performed on first execution of any method.
    • Manual: use getInstance(opts) method from an integration, and pass the instance as a parameter to each method. This allows to have more than one instance of integration. One example why this is needed, are installation-authenticated instances of github in cla-bot-2021.
  • Mocks are provided for each query, but fixtures are added when needed.
  • All retry / rate-limiting logic should also be implemented in this module.

Using mocks and fixtures

// module.ts
import { github } from "opstooling-integrations";

export async function foo() {
  await github.createCommitStatus({...});
}
// module.spec.ts
import { describe, expect, it, jest } from "@jest/globals";
import { fixtures, github } from "opstooling-integrations";
import { foo } from ".";

jest.mock("opstooling-integrations");

describe("foo", () => {
  it("calls github.createCommitStatus", async () => {
  jest.mocked(github.createCommitStatus).mockResolvedValue(fixtures.github.createCommitStatusSuccessfulResponse());
    await foo();

    expect(github.createCommitStatus).toHaveBeenCalledWith({...});
  });
});

Integrations

GitHub

Configuration

Four auth types are supported: app, installation, and token.

app auth

Non-installation auth type for GitHub Apps. Using this means that org/repo permissions aren't accessible.
Requires appId and privateKey.

installation auth

This type is used to authorize requests for specific org/repo application installation. Requires installationId, which can be resolved using app auth. If app expected to have only one installation, then it can be configured through environment. Otherwise, use github.getInstance and pass the instance further.
Requires appId, privateKey and installationId.

token auth

Simplest of all, requires only token, works for personal tokens or oauth tokens.

Environment variableOption for getInstance()DescriptionRequired?Default value
GITHUB_AUTH_TYPEauthTypeapp, token, installationnotoken
GITHUB_APP_IDappIdGitHub app IDyes, if authType is app, or installation-
GITHUB_PRIVATE_KEY or GITHUB_PRIVATE_KEY_BASE64privateKeyGitHub app private key. Use GITHUB_PRIVATE_KEY_BASE64 to curcumvent newline issuesyes, if authType is app or installation-
GITHUB_TOKENauthTokenGitHub auth token. Can be personal, oauth, etc.yes, if authType is token-
GITHUB_INSTALLATION_IDinstallationIdGitHub app installation idif authType is installation-
GITHUB_BASE_URLbaseUrlAPI endpoint URLnohttps://api.github.com