Skip to content

Commit

Permalink
feat: customize account name for manifest creation flow using `GH_ORG…
Browse files Browse the repository at this point in the history
…` environment variable (#1606)
  • Loading branch information
decyjphr committed Jan 11, 2022
1 parent c83edcb commit 992b480
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 16 deletions.
27 changes: 14 additions & 13 deletions docs/configuration.md
Expand Up @@ -19,18 +19,19 @@ For more on the set up of these items, check out [Configuring a GitHub App](./de

Some less common environment variables are:

| Environment Variable | [Programmatic Argument](./development.md#run-probot-programmatically) | Description |
| --------------------- | --------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `GHE_HOST` | `new Probot({ Octokit: ProbotOctokit.defaults({ baseUrl }) })` | The hostname of your GitHub Enterprise instance. <p>_(Example: `github.mycompany.com`)_</p> |
| `GHE_PROTOCOL` | `new Probot({ Octokit: ProbotOctokit.defaults({ baseUrl }) })` | The protocol of your GitHub Enterprise instance. Defaults to HTTPS. Do not change unless you are certain. <p>_(Example: `https`)_</p> |
| `LOG_FORMAT` | - | By default, logs are formatted for readability in development. You can set this to `json` in order to disable the formatting |
| `LOG_LEVEL` | `const log = require('pino')({ level })` | The verbosity of logs to show when running your app, which can be `fatal`, `error`, `warn`, `info`, `debug`, `trace` or `silent`. Default: `info` |
| `LOG_LEVEL_IN_STRING` | - | By default, when using the `json` format, the level printed in the log records is an int (`10`, `20`, ..). This option tells the logger to print level as a string: `{"level": "info"}`. Default `false` |
| `LOG_MESSAGE_KEY` | `const log = require('pino')({ messageKey: 'msg' })` | Only relevant when `LOG_FORMAT` is set to `json`. Sets the json key for the log message. Default: `msg` |
| `SENTRY_DSN` | - | Set to a [Sentry](https://sentry.io/) DSN to report all errors thrown by your app. <p>_(Example: `https://1234abcd@sentry.io/12345`)_</p> |
| `PORT` | `new Server({ port })` | The port to start the local server on. Default: `3000` |
| `HOST` | `new Server({ host })` | The host to start the local server on. |
| `WEBHOOK_PATH` | `new Server({ webhookPath })` | The URL path which will receive webhooks. Default: `/` |
| `REDIS_URL` | `new Probot({ redisConfig })` | Set to a `redis://` url as connection option for [ioredis](https://github.com/luin/ioredis#connect-to-redis) in order to enable [cluster support for request throttling](https://github.com/octokit/plugin-throttling.js#clustering). <p>_(Example: `redis://:secret@redis-123.redislabs.com:12345/0`)_</p> |
| Environment Variable | [Programmatic Argument](./development.md#run-probot-programmatically) | Description |
| --------------------- | --------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `GHE_HOST` | `new Probot({ Octokit: ProbotOctokit.defaults({ baseUrl }) })` | The hostname of your GitHub Enterprise instance. <p>_(Example: `github.mycompany.com`)_</p> |
| `GHE_PROTOCOL` | `new Probot({ Octokit: ProbotOctokit.defaults({ baseUrl }) })` | The protocol of your GitHub Enterprise instance. Defaults to HTTPS. Do not change unless you are certain. <p>_(Example: `https`)_</p> |
| `GH_ORG` | - | The organization where you want to register the app in the app creation manifest flow. If set, the app is registered for an organization (https://github.com/organizations/ORGANIZATION/settings/apps/new), if not set, the GitHub app would be registered for the user account (https://github.com/settings/apps/new). |
| `LOG_FORMAT` | - | By default, logs are formatted for readability in development. You can set this to `json` in order to disable the formatting |
| `LOG_LEVEL` | `const log = require('pino')({ level })` | The verbosity of logs to show when running your app, which can be `fatal`, `error`, `warn`, `info`, `debug`, `trace` or `silent`. Default: `info` |
| `LOG_LEVEL_IN_STRING` | - | By default, when using the `json` format, the level printed in the log records is an int (`10`, `20`, ..). This option tells the logger to print level as a string: `{"level": "info"}`. Default `false` |
| `LOG_MESSAGE_KEY` | `const log = require('pino')({ messageKey: 'msg' })` | Only relevant when `LOG_FORMAT` is set to `json`. Sets the json key for the log message. Default: `msg` |
| `SENTRY_DSN` | - | Set to a [Sentry](https://sentry.io/) DSN to report all errors thrown by your app. <p>_(Example: `https://1234abcd@sentry.io/12345`)_</p> |
| `PORT` | `new Server({ port })` | The port to start the local server on. Default: `3000` |
| `HOST` | `new Server({ host })` | The host to start the local server on. |
| `WEBHOOK_PATH` | `new Server({ webhookPath })` | The URL path which will receive webhooks. Default: `/` |
| `REDIS_URL` | `new Probot({ redisConfig })` | Set to a `redis://` url as connection option for [ioredis](https://github.com/luin/ioredis#connect-to-redis) in order to enable [cluster support for request throttling](https://github.com/octokit/plugin-throttling.js#clustering). <p>_(Example: `redis://:secret@redis-123.redislabs.com:12345/0`)_</p> |

For more information on the formatting conventions and rules of `.env` files, check out [the npm `dotenv` module's documentation](https://www.npmjs.com/package/dotenv#rules).
6 changes: 3 additions & 3 deletions src/manifest-creation.ts
Expand Up @@ -101,8 +101,8 @@ export class ManifestCreation {

get createAppUrl() {
const githubHost = process.env.GHE_HOST || `github.com`;
return `${
process.env.GHE_PROTOCOL || "https"
}://${githubHost}/settings/apps/new`;
return `${process.env.GHE_PROTOCOL || "https"}://${githubHost}${
process.env.GH_ORG ? "/organizations/".concat(process.env.GH_ORG) : ""
}/settings/apps/new`;
}
}
16 changes: 16 additions & 0 deletions test/manifest-creation.test.ts
Expand Up @@ -46,6 +46,7 @@ describe("ManifestCreation", () => {
describe("createAppUrl", () => {
afterEach(() => {
delete process.env.GHE_HOST;
delete process.env.GH_ORG;
delete process.env.GHE_PROTOCOL;
});

Expand All @@ -55,13 +56,28 @@ describe("ManifestCreation", () => {
);
});

test("creates an app url when github org is set", () => {
process.env.GH_ORG = "testorg";
expect(setup.createAppUrl).toEqual(
"https://github.com/organizations/testorg/settings/apps/new"
);
});

test("creates an app url when github host env is set", () => {
process.env.GHE_HOST = "hiimbex.github.com";
expect(setup.createAppUrl).toEqual(
"https://hiimbex.github.com/settings/apps/new"
);
});

test("creates an app url when github host env and github org is set", () => {
process.env.GHE_HOST = "hiimbex.github.com";
process.env.GH_ORG = "testorg";
expect(setup.createAppUrl).toEqual(
"https://hiimbex.github.com/organizations/testorg/settings/apps/new"
);
});

test("creates an app url when github host env and protocol are set", () => {
process.env.GHE_HOST = "hiimbex.github.com";
process.env.GHE_PROTOCOL = "http";
Expand Down

0 comments on commit 992b480

Please sign in to comment.