Skip to content

Commit

Permalink
Fix merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
vibhanshub committed Jan 10, 2024
2 parents 9cb4c84 + 719c9d0 commit 697c3f6
Show file tree
Hide file tree
Showing 71 changed files with 2,571 additions and 769 deletions.
8 changes: 6 additions & 2 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
{
"$schema": "https://unpkg.com/@changesets/config@2.0.0/schema.json",
"$schema": "https://unpkg.com/@changesets/config@3.0.0/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
"ignore": [],
"privatePackages": {
"tag": true,
"version": true
}
}
5 changes: 0 additions & 5 deletions .changeset/moody-ants-fetch.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/sixty-tigers-search.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/sweet-seahorses-complain.md

This file was deleted.

80 changes: 80 additions & 0 deletions .github/workflows/production.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Release integration to production

on:
release:
types: [published]

jobs:
deploy-integration-to-production:
if: startsWith(github.event.release.tag_name, '@gitbook/integration-')
name: Deploy integration to production
runs-on: ubuntu-latest
steps:
- name: Get integration package name
id: integration-package
uses: actions/github-script@v7
with:
script: |
const tag = context.payload.release.tag_name;
const integrationPackage = '@' + tag.split('@')[1];
core.setOutput('integrationPackage', integrationPackage)
- name: Checkout repo
uses: actions/checkout@v3

- name: Setup Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: 20.x

- name: Install Dependencies
# We need to build and then re-install so that the "bin" can be correctly linked
run: |
npm ci
npm run build
npm ci
# TODO: Remove this once we incorporate this in the publish API of the integration
- name: Publish all integrations assets to production
run: npm run publish-assets
env:
CLOUDFLARE_PAGES_PROJECT: ${{ secrets.INTEGRATIONS_ASSETS_PROD_PROJECT }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_PAGES_API_TOKEN }}

- name: Deploy integration
run: npm run publish-integrations -- --filter=${{ steps.integration-package.outputs.integrationPackage }}
env:
GITBOOK_TOKEN: ${{ secrets.GITBOOK_PROD_API_TOKEN }}
GITBOOK_ENDPOINT: https://api.gitbook.com
GITBOOK_ORGANIZATION: gitbook
UNFURL_GITHUB_CLIENT_ID: ${{ secrets.UNFURL_GITHUB_CLIENT_ID }}
UNFURL_GITHUB_CLIENT_SECRET: ${{ secrets.UNFURL_GITHUB_CLIENT_SECRET }}
GITLAB_CLIENT_ID: ${{ secrets.GITLAB_CLIENT_ID }}
GITLAB_CLIENT_SECRET: ${{ secrets.GITLAB_CLIENT_SECRET }}
DISCORD_CLIENT_ID: $ {{ secrets.DISCORD_CLIENT_ID }}
DISCORD_CLIENT_SECRET: $ {{ secrets.DISCORD_CLIENT_SECRET }}
DISCORD_BOT_TOKEN: $ {{ secrets.DISCORD_BOT_TOKEN }}
SLACK_CLIENT_ID: ${{ secrets.SLACK_PROD_CLIENT_ID }}
SLACK_CLIENT_SECRET: ${{ secrets.SLACK_PROD_CLIENT_SECRET }}
SLACK_SIGNING_SECRET: ${{ secrets.SLACK_PROD_SIGNING_SECRET }}
FIGMA_CLIENT_ID: ${{ secrets.FIGMA_PROD_CLIENT_ID }}
FIGMA_CLIENT_SECRET: ${{ secrets.FIGMA_PROD_CLIENT_SECRET }}
MAILCHIMP_CLIENT_ID: ${{ secrets.MAILCHIMP_PROD_CLIENT_ID }}
MAILCHIMP_CLIENT_SECRET: ${{ secrets.MAILCHIMP_PROD_CLIENT_SECRET }}
JIRA_CLIENT_ID: ${{ secrets.JIRA_PROD_CLIENT_ID }}
JIRA_CLIENT_SECRET: ${{ secrets.JIRA_PROD_CLIENT_SECRET }}
LINEAR_CLIENT_ID: ${{ secrets.LINEAR_PROD_CLIENT_ID }}
LINEAR_CLIENT_SECRET: ${{ secrets.LINEAR_PROD_CLIENT_SECRET }}
GITHUB_APP_INSTALL_URL: ${{ secrets.GITBOOK_GITHUB_APP_INSTALL_URL }}
GITHUB_APP_ID: ${{ secrets.GITBOOK_GITHUB_APP_ID }}
GITHUB_CLIENT_ID: ${{ secrets.GITBOOK_GITHUB_CLIENT_ID }}
GITHUB_CLIENT_SECRET: ${{ secrets.GITBOOK_GITHUB_CLIENT_SECRET }}
GITHUB_WEBHOOK_SECRET: ${{ secrets.GITBOOK_GITHUB_WEBHOOK_SECRET }}
GITHUB_PRIVATE_KEY: ${{ secrets.GITBOOK_GITHUB_PRIVATE_KEY }}
GITHUB_ENTITIES_APP_INSTALL_URL: ${{ secrets.ENTITIES_GITHUB_APP_INSTALL_URL }}
GITHUB_ENTITIES_APP_ID: ${{ secrets.ENTITIES_GITHUB_APP_ID }}
GITHUB_ENTITIES_CLIENT_ID: ${{ secrets.ENTITIES_GITHUB_CLIENT_ID }}
GITHUB_ENTITIES_CLIENT_SECRET: ${{ secrets.ENTITIES_GITHUB_CLIENT_SECRET }}
GITHUB_ENTITIES_WEBHOOK_SECRET: ${{ secrets.ENTITIES_GITHUB_WEBHOOK_SECRET }}
GITHUB_ENTITIES_PRIVATE_KEY: ${{ secrets.ENTITIES_GITHUB_PRIVATE_KEY }}
58 changes: 9 additions & 49 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ jobs:
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
fetch-depth: 0

- name: Setup Node.js 18.x
- name: Setup Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: 18.x
node-version: 20.x

- name: Install Dependencies
run: npm ci
Expand All @@ -32,19 +32,21 @@ jobs:
with:
publish: npm run release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Using a PAT instead of GITHUB_TOKEN because we need to run workflows when releases are created
# https://github.com/orgs/community/discussions/26875#discussioncomment-3253761
GITHUB_TOKEN: ${{ secrets.GH_PERSONAL_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

publish-integrations:
name: Publish Integrations
publish-integrations-staging:
name: Publish Integrations to Staging
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3
- name: Setup Node.js 18.x
- name: Setup Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: 18.x
node-version: 20.x
- name: Install Dependencies
# We need to build and then re-install so that the "bin" can be correctly linked
run: |
Expand Down Expand Up @@ -96,45 +98,3 @@ jobs:
GITHUB_ENTITIES_CLIENT_SECRET: ${{ secrets.ENTITIES_GITHUB_STAGING_CLIENT_SECRET }}
GITHUB_ENTITIES_WEBHOOK_SECRET: ${{ secrets.ENTITIES_GITHUB_STAGING_WEBHOOK_SECRET }}
GITHUB_ENTITIES_PRIVATE_KEY: ${{ secrets.ENTITIES_GITHUB_STAGING_PRIVATE_KEY }}
- name: Publish all integrations assets to production
run: npm run publish-assets
env:
CLOUDFLARE_PAGES_PROJECT: ${{ secrets.INTEGRATIONS_ASSETS_PROD_PROJECT }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_PAGES_API_TOKEN }}
- name: Publish all integrations to production
run: npm run publish-integrations
env:
GITBOOK_TOKEN: ${{ secrets.GITBOOK_PROD_API_TOKEN }}
GITBOOK_ENDPOINT: https://api.gitbook.com
GITBOOK_ORGANIZATION: gitbook
UNFURL_GITHUB_CLIENT_ID: ${{ secrets.UNFURL_GITHUB_CLIENT_ID }}
UNFURL_GITHUB_CLIENT_SECRET: ${{ secrets.UNFURL_GITHUB_CLIENT_SECRET }}
GITLAB_CLIENT_ID: ${{ secrets.GITLAB_CLIENT_ID }}
GITLAB_CLIENT_SECRET: ${{ secrets.GITLAB_CLIENT_SECRET }}
DISCORD_CLIENT_ID: $ {{ secrets.DISCORD_CLIENT_ID }}
DISCORD_CLIENT_SECRET: $ {{ secrets.DISCORD_CLIENT_SECRET }}
DISCORD_BOT_TOKEN: $ {{ secrets.DISCORD_BOT_TOKEN }}
SLACK_CLIENT_ID: ${{ secrets.SLACK_PROD_CLIENT_ID }}
SLACK_CLIENT_SECRET: ${{ secrets.SLACK_PROD_CLIENT_SECRET }}
SLACK_SIGNING_SECRET: ${{ secrets.SLACK_PROD_SIGNING_SECRET }}
FIGMA_CLIENT_ID: ${{ secrets.FIGMA_PROD_CLIENT_ID }}
FIGMA_CLIENT_SECRET: ${{ secrets.FIGMA_PROD_CLIENT_SECRET }}
MAILCHIMP_CLIENT_ID: ${{ secrets.MAILCHIMP_PROD_CLIENT_ID }}
MAILCHIMP_CLIENT_SECRET: ${{ secrets.MAILCHIMP_PROD_CLIENT_SECRET }}
JIRA_CLIENT_ID: ${{ secrets.JIRA_PROD_CLIENT_ID }}
JIRA_CLIENT_SECRET: ${{ secrets.JIRA_PROD_CLIENT_SECRET }}
LINEAR_CLIENT_ID: ${{ secrets.LINEAR_PROD_CLIENT_ID }}
LINEAR_CLIENT_SECRET: ${{ secrets.LINEAR_PROD_CLIENT_SECRET }}
GITHUB_APP_INSTALL_URL: ${{ secrets.GITBOOK_GITHUB_APP_INSTALL_URL }}
GITHUB_APP_ID: ${{ secrets.GITBOOK_GITHUB_APP_ID }}
GITHUB_CLIENT_ID: ${{ secrets.GITBOOK_GITHUB_CLIENT_ID }}
GITHUB_CLIENT_SECRET: ${{ secrets.GITBOOK_GITHUB_CLIENT_SECRET }}
GITHUB_WEBHOOK_SECRET: ${{ secrets.GITBOOK_GITHUB_WEBHOOK_SECRET }}
GITHUB_PRIVATE_KEY: ${{ secrets.GITBOOK_GITHUB_PRIVATE_KEY }}
GITHUB_ENTITIES_APP_INSTALL_URL: ${{ secrets.ENTITIES_GITHUB_APP_INSTALL_URL }}
GITHUB_ENTITIES_APP_ID: ${{ secrets.ENTITIES_GITHUB_APP_ID }}
GITHUB_ENTITIES_CLIENT_ID: ${{ secrets.ENTITIES_GITHUB_CLIENT_ID }}
GITHUB_ENTITIES_CLIENT_SECRET: ${{ secrets.ENTITIES_GITHUB_CLIENT_SECRET }}
GITHUB_ENTITIES_WEBHOOK_SECRET: ${{ secrets.ENTITIES_GITHUB_WEBHOOK_SECRET }}
GITHUB_ENTITIES_PRIVATE_KEY: ${{ secrets.ENTITIES_GITHUB_PRIVATE_KEY }}
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"eslint.format.enable": true,
// Fix errors on save using ESLint
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
},
// Format using Prettier to format on save
"editor.defaultFormatter": "esbenp.prettier-vscode",
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# GitBook Integration Platform

![GitBook Banner](./assets/gitbook-integrations-banner.png)

Welcome to GitBook Integration Platform!

This repository contains code, packages, and scripts related to the integrations platform in GitBook. Want to get started building your first integration? Head to our [documentation](https://developer.gitbook.com/getting-started/setup-guide) to get started.
Expand Down
2 changes: 1 addition & 1 deletion integrations/formspree/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "formspree",
"name": "@gitbook/integration-formspree",
"private": true,
"scripts": {
"lint": "eslint ./**/*.ts*",
Expand Down
2 changes: 1 addition & 1 deletion integrations/github-files/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"devDependencies": {
"@gitbook/api": "*",
"@gitbook/cli": "^0.13.0",
"@gitbook/cli": "^0.15.0",
"@gitbook/eslint-config": "*",
"@gitbook/runtime": "*",
"@gitbook/tsconfig": "*"
Expand Down
43 changes: 43 additions & 0 deletions integrations/github/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# @gitbook/integration-github

## 0.0.7

### Patch Changes

- 9285fe2: Release

## 0.0.6

### Patch Changes

- 8e40049: Release

## 0.0.5

### Patch Changes

- 3373bce: Release

## 0.0.4

### Patch Changes

- a7e2098: Release

## 0.0.3

### Patch Changes

- 37e4590: Release

## 0.0.2

### Patch Changes

- d3622ef: Release

## 0.0.1

### Patch Changes

- 2c3fecc: skip import or export git sync operations if no configuration found
20 changes: 20 additions & 0 deletions integrations/github/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Publishing this Integration

## Prerequisites
1. Make sure you've [setup this repository and authenticated](https://app.gitbook.com/o/d8f63b60-89ae-11e7-8574-5927d48c4877/s/-MG7r2HeK94SceWjMDdW/development/integrations/working-with-integrations) with the `gitbook` CLI properly.
2. Once that is done, ensure that you have a GitHub App [configured and published](https://app.gitbook.com/o/d8f63b60-89ae-11e7-8574-5927d48c4877/s/-MG7r2HeK94SceWjMDdW/development/configuration#github) correctly.

### Publishing
Go to the integration folder at `cd integrations/github`. Before you run `publish` you must set a bunch of environment variables that are defined in the `manifest` file. In order to do that, open your GitHub App settings at https://github.com/settings/apps and then do the following

- `export GITHUB_APP_INSTALL_URL=https://github.com/apps/your-app-name/installations/new` , and replace `your-app-name` with whatever is the name of your app currently in the settings page URL.
- `export GITHUB_APP_ID=app-id-from-settings`
- `export GITHUB_CLIENT_ID=client-id-from-settings`
- `export GITHUB_CLIENT_SECRET=client-secret-that-you-noted-down-earlier`
- `export GITHUB_WEBHOOK_SECRET=webhook-secret-that-you-noted-down-earlier`
- ```export GITHUB_PRIVATE_KEY=`cat ~/Downloads/gitbook-dev-YOURNAME.key```
(this is the file that we converted from `.pem` to `.key` earlier. Make sure the file exists at the path)

Once you've exported these `env` variables, it's time to run the `publish` script:

`gitbook publish --organization orgId` where `orgId` will be the ID of your personal organization in your dev environment under which this integration should be published.
7 changes: 3 additions & 4 deletions integrations/github/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gitbook/integration-github",
"version": "0.0.0",
"version": "0.0.7",
"private": true,
"scripts": {
"lint": "eslint --ext .js,.jsx,.ts,.tsx .",
Expand All @@ -14,16 +14,15 @@
"hash-sum": "^2.0.0",
"http-errors": "^2.0.0",
"http-link-header": "^1.1.1",
"itty-router": "^4.0.14",
"itty-router": "^4.0.26",
"jose": "^4.14.4"
},
"devDependencies": {
"@gitbook/cli": "^0.13.0",
"@gitbook/cli": "*",
"@gitbook/eslint-config": "*",
"@gitbook/tsconfig": "*",
"@octokit/webhooks-types": "^7.2.0",
"@types/hash-sum": "^1.0.0",
"@types/http-errors": "^2.0.1",
"@types/http-link-header": "^1.0.3"
}
}
16 changes: 8 additions & 8 deletions integrations/github/src/api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import httpError from 'http-errors';
import LinkHeader from 'http-link-header';
import { StatusError } from 'itty-router';

import { Logger } from '@gitbook/runtime';

Expand Down Expand Up @@ -289,7 +289,7 @@ async function requestGitHubAPI(
retriesLeft = 1
): Promise<Response> {
const { access_token } = credentials;
logger.debug(`requesting GitHub API [${options.method}] ${url.toString()}`);
logger.debug(`GitHub API -> [${options.method}] ${url.toString()}`);
const response = await fetch(url.toString(), {
...options,
headers: {
Expand Down Expand Up @@ -333,12 +333,12 @@ async function requestGitHubAPI(
return requestGitHubAPI(context, refreshed, url, options, retriesLeft - 1);
}

logger.error(
`GitHub API error: ${response.status} for [${options.method}] ${url.toString()}`
);
const text = await response.text();

logger.error(`[${options.method}] (${response.status}) GitHub API error: ${text}`);

// Otherwise, we throw an error
throw httpError(response.status, `GitHub API error: ${response.statusText}`);
throw new StatusError(response.status, `GitHub API error: ${response.statusText}`);
}

return response;
Expand All @@ -365,7 +365,7 @@ async function refreshCredentials(

if (!resp.ok) {
// If refresh fails for whatever reason, we ask the user to re-authenticate
throw httpError(401, `Unauthorized: kindly re-authenticate!`);
throw new StatusError(401, `Unauthorized: kindly re-authenticate!`);
}

const data = await resp.formData();
Expand Down Expand Up @@ -393,7 +393,7 @@ export function extractTokenCredentialsOrThrow(

const oAuthCredentials = config?.oauth_credentials;
if (!oAuthCredentials?.access_token) {
throw httpError(401, 'Unauthorized: kindly re-authenticate!');
throw new StatusError(401, 'Unauthorized: kindly re-authenticate!');
}

return oAuthCredentials;
Expand Down
Loading

0 comments on commit 697c3f6

Please sign in to comment.