Skip to content
This repository has been archived by the owner on May 5, 2024. It is now read-only.

Commit

Permalink
fix: updates for the new opensentinel API
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinpinto committed Jun 2, 2020
1 parent f2df8d9 commit 53ab424
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 39 deletions.
17 changes: 7 additions & 10 deletions packages/keybase-notifications/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Keybase Build Notifications

This action allows you to post GitHub build notifications to [Keybase Chat](https://keybase.io/blog/keybase-chat) channels, teams, and DMs. It sends messages via the [opensentinel API](https://keybase.io/sentinelbot), using your `owner` and `token` values.
This action allows you to post GitHub build notifications to [Keybase Chat](https://keybase.io/blog/keybase-chat) channels, teams, and DMs. It sends messages via the [opensentinel API](https://www.opensentinel.com), using your `token` value.

![Keybase default GitHub notification](images/keybase-gh-notification-example.png)

Expand All @@ -18,12 +18,12 @@ This action allows you to post GitHub build notifications to [Keybase Chat](http
## Using the Action

You will need an opensentinel API token in order to use this action. Go through the [@sentinelbot](https://keybase.io/sentinelbot) setup flow for a **Generic Webhook** and make a note of the `owner` and `token` values in the URL you receive.
You will need an opensentinel automation API token in order to use this action. Create an account and go through the [Keybase setup information](https://www.opensentinel.com/docs/integrations/keybase). This action utilizes a **Generic Webhook** token.

As a reference, `@sentinelbot` Webhook URLs for Keybase will look something like:
For reference, opensentinel automation wbhook URLs for Keybase look something like:

```text
https://api.opensentinel.com/kb/webhooks?owner=<OSL_OWNER>&token=<OSL_TOKEN>
https://automations.opensentinel.com/webhook?token=<OSL_TOKEN>
```

### Build notifications for CI Tests
Expand All @@ -48,7 +48,6 @@ jobs:
if: always()
with:
job_status: ${{ job.status }}
opensentinel_owner: ${{ secrets.OSL_OWNER }}
opensentinel_token: ${{ secrets.OSL_TOKEN }}
on_success: "never"
on_failure: "always"
Expand Down Expand Up @@ -82,7 +81,6 @@ jobs:
with:
job_status: ${{ job.status }}
job_name: "Production Release"
opensentinel_owner: ${{ secrets.OSL_OWNER }}
opensentinel_token: ${{ secrets.OSL_TOKEN }}
```

Expand All @@ -92,7 +90,6 @@ This will send you a notification message to let you know if the production rele

| Parameter | Description | Default |
| ------------------------ | ---------------------------------------------------- | ------------- |
| `opensentinel_owner`\*\* | URL querystring value for owner | `null` |
| `opensentinel_token`\*\* | URL querystring value for token | `null` |
| `job_status`\*\* | GitHub Actions job status - use `${{ job.status }}` | `null` |
| `job_name` | Display name to use in the chat message | Workflow name |
Expand All @@ -105,11 +102,11 @@ This will send you a notification message to let you know if the production rele

## What about other GitHub events?

Due to the way the permission system around GitHub Actions works, repo secrets cannot be accessed by users on forks & such. In general, an Action that requires a secret will fail when invoked through a pull request from a fork.
The opensentinel system itself handles other GitHub events directly. This action is primarily geared toward sending build + other ad-hoc messages.

This action will do its hardest to **NOT fail the build** as a result of a processing error (network/permissions/etc).

If you're still interested in receiving Keybase notifications for other GitHub events (`push`, `pull_request`, etc), set up a **GitHub Notification** webhook with [opensentinel](https://keybase.io/sentinelbot) and add that to your repository. The webhook system is not bound by the permission issues mentioned here!
If you're still interested in receiving Keybase notifications for other GitHub events (`push`, `pull_request`, etc), set up a **GitHub Notification** webhook with [opensentinel](https://www.opensentinel.com/docs/handlers/github-notification) and add that to your repository.

## Filtering Notifications

Expand All @@ -134,7 +131,7 @@ Every commit that lands on master for this project triggers an automatic build a

## How to get help

The main [README](https://github.com/marvinpinto/actions/blob/master/README.md) for this project has a bunch of information related to debugging & submitting issues. [Opensentinel](https://keybase.io/sentinelbot) help is available in the [opensentinel.users](https://keybase.io/team/opensentinel.users) user group. If you're still stuck, try and get a hold of me on [keybase](https://keybase.io/marvinpinto) and I will do my best to help you out.
The main [README](https://github.com/marvinpinto/actions/blob/master/README.md) for this project has a bunch of information related to debugging & submitting issues. opensentinel help is available through a few [support channels](https://www.opensentinel.com/docs/general/contact) and if you're still stuck, try and get a hold of me on [keybase](https://keybase.io/marvinpinto) and I will do my best to help you out.

## License

Expand Down
37 changes: 18 additions & 19 deletions packages/keybase-notifications/__tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ describe('main handler', () => {
jest.resetModules();
nock.disableNetConnect();

process.env['INPUT_OPENSENTINEL_OWNER'] = 'fakeoslowner';
process.env['INPUT_OPENSENTINEL_TOKEN'] = 'abcd1234fake';
process.env['INPUT_JOB_STATUS'] = 'Success';
process.env['INPUT_JOB_NAME'] = 'Testing Production Deployment';
Expand Down Expand Up @@ -42,9 +41,9 @@ describe('main handler', () => {
});

it('is able to send out a "success" build message', async () => {
const opensentinelAPIcall = nock('https://api.opensentinel.com')
const opensentinelAPIcall = nock('https://automations.opensentinel.com')
.post(
'/kb/webhooks?owner=fakeoslowner&token=abcd1234fake',
'/webhook?token=abcd1234fake',
'GitHub build **Testing Production Deployment** (tag v0.0.1) for repository `marvinpinto/private-actions-tester` completed successfully :tada: - https://example.com',
)
.reply(202, {
Expand All @@ -58,9 +57,9 @@ describe('main handler', () => {

it('is able to send out a "failure" build message', async () => {
process.env['INPUT_JOB_STATUS'] = 'Failure';
const opensentinelAPIcall = nock('https://api.opensentinel.com')
const opensentinelAPIcall = nock('https://automations.opensentinel.com')
.post(
'/kb/webhooks?owner=fakeoslowner&token=abcd1234fake',
'/webhook?token=abcd1234fake',
'GitHub build **Testing Production Deployment** (tag v0.0.1) for repository `marvinpinto/private-actions-tester` failed :rotating_light: - https://example.com',
)
.reply(202, {
Expand All @@ -74,9 +73,9 @@ describe('main handler', () => {

it('is able to send out a "cancel" build message', async () => {
process.env['INPUT_JOB_STATUS'] = 'Cancelled';
const opensentinelAPIcall = nock('https://api.opensentinel.com')
const opensentinelAPIcall = nock('https://automations.opensentinel.com')
.post(
'/kb/webhooks?owner=fakeoslowner&token=abcd1234fake',
'/webhook?token=abcd1234fake',
'GitHub build **Testing Production Deployment** (tag v0.0.1) for repository `marvinpinto/private-actions-tester` was cancelled by `marvinpinto` :warning: - https://example.com',
)
.reply(202, {
Expand All @@ -90,9 +89,9 @@ describe('main handler', () => {

it('reverts back to using the workflow name if no job name is specified', async () => {
delete process.env['INPUT_JOB_NAME'];
const opensentinelAPIcall = nock('https://api.opensentinel.com')
const opensentinelAPIcall = nock('https://automations.opensentinel.com')
.post(
'/kb/webhooks?owner=fakeoslowner&token=abcd1234fake',
'/webhook?token=abcd1234fake',
'GitHub build **keybase** (tag v0.0.1) for repository `marvinpinto/private-actions-tester` completed successfully :tada: - https://example.com',
)
.reply(202, {
Expand All @@ -106,9 +105,9 @@ describe('main handler', () => {

it('falls back gracefully if this is not a tagged ref', async () => {
process.env['GITHUB_REF'] = 'refs/heads/master';
const opensentinelAPIcall = nock('https://api.opensentinel.com')
const opensentinelAPIcall = nock('https://automations.opensentinel.com')
.post(
'/kb/webhooks?owner=fakeoslowner&token=abcd1234fake',
'/webhook?token=abcd1234fake',
'GitHub build **Testing Production Deployment** for repository `marvinpinto/private-actions-tester` completed successfully :tada: - https://example.com',
)
.reply(202, {
Expand All @@ -122,9 +121,9 @@ describe('main handler', () => {

it('falls back gracefully if there is no repository set (for whatever reason)', async () => {
delete process.env['GITHUB_REPOSITORY'];
const opensentinelAPIcall = nock('https://api.opensentinel.com')
const opensentinelAPIcall = nock('https://automations.opensentinel.com')
.post(
'/kb/webhooks?owner=fakeoslowner&token=abcd1234fake',
'/webhook?token=abcd1234fake',
'GitHub build **Testing Production Deployment** (tag v0.0.1) completed successfully :tada: - https://example.com',
)
.reply(202, {
Expand All @@ -138,9 +137,9 @@ describe('main handler', () => {

it('does not send out success messages if configured not to', async () => {
process.env['INPUT_ON_SUCCESS'] = 'never';
const opensentinelAPIcall = nock('https://api.opensentinel.com')
const opensentinelAPIcall = nock('https://automations.opensentinel.com')
.post(
'/kb/webhooks?owner=fakeoslowner&token=abcd1234fake',
'/webhook?token=abcd1234fake',
'GitHub build **Testing Production Deployment** (tag v0.0.1) for repository `marvinpinto/private-actions-tester` completed successfully :tada: - https://example.com',
)
.reply(202, {
Expand All @@ -155,9 +154,9 @@ describe('main handler', () => {
it('does not send out failure messages if configured not to', async () => {
process.env['INPUT_ON_FAILURE'] = 'never';
process.env['INPUT_JOB_STATUS'] = 'Failure';
const opensentinelAPIcall = nock('https://api.opensentinel.com')
const opensentinelAPIcall = nock('https://automations.opensentinel.com')
.post(
'/kb/webhooks?owner=fakeoslowner&token=abcd1234fake',
'/webhook?token=abcd1234fake',
'GitHub build **Testing Production Deployment** (tag v0.0.1) for repository `marvinpinto/private-actions-tester` failed :rotating_light: - https://example.com',
)
.reply(202, {
Expand All @@ -170,9 +169,9 @@ describe('main handler', () => {
});

it('fails gracefully if unable to send out the message via the opensentinel API', async () => {
const opensentinelAPIcall = nock('https://api.opensentinel.com')
const opensentinelAPIcall = nock('https://automations.opensentinel.com')
.post(
'/kb/webhooks?owner=fakeoslowner&token=abcd1234fake',
'/webhook?token=abcd1234fake',
'GitHub build **Testing Production Deployment** (tag v0.0.1) for repository `marvinpinto/private-actions-tester` completed successfully :tada: - https://example.com',
)
.reply(408, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ server.post('/', (req, res) => {
});

export const setupEnv = {
INPUT_OPENSENTINEL_OWNER: 'fakeoslowner',
INPUT_OPENSENTINEL_TOKEN: 'abcd1234fake',
INPUT_JOB_STATUS: 'Success',
INPUT_JOB_NAME: 'Testing Production Deployment',
Expand Down
5 changes: 1 addition & 4 deletions packages/keybase-notifications/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ name: "Keybase Build Notifications"
author: "marvinpinto"
description: "Send GitHub build notifications to your Keybase team or channel"
inputs:
opensentinel_owner:
description: 'The "owner" portion of your Opensentinel (generic) Webhook URL (e.g. https://api.opensentinel.com/kb/webhooks?owner=<THIS VALUE>&token=efgh6789)'
required: true
opensentinel_token:
description: 'The "token" portion of your Opensentinel (generic) Webhook URL (e.g. https://api.opensentinel.com/kb/webhooks?owner=abcd1234&token=<THIS VALUE>)'
description: 'The "token" portion of your opensentinel (generic) Webhook URL (e.g. https://automations.opensentinel.com/webhook?token=<THIS VALUE>)'
required: true
job_status:
description: "Actions build status (e.g. success, failure, cancelled)"
Expand Down
7 changes: 2 additions & 5 deletions packages/keybase-notifications/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ enum BuildNotification {
}

type Args = {
opensentinelOwner: string;
opensentinelToken: string;
jobStatus: JobStatus;
jobName: string;
Expand All @@ -28,7 +27,6 @@ type Args = {

const getAndValidateArgs = (): Args => {
const args = {
opensentinelOwner: core.getInput('opensentinel_owner', {required: true}),
opensentinelToken: core.getInput('opensentinel_token', {required: true}),
jobStatus: JobStatus.UNKNOWN,
jobName: '',
Expand Down Expand Up @@ -138,13 +136,12 @@ export const main = async () => {

core.debug(`Outbound message: ${msg}`);
const params = qs.stringify({
owner: args.opensentinelOwner,
token: args.opensentinelToken,
});
const baseUrl = process.env['JEST_MOCK_HTTP_PORT']
? `http://localhost:${process.env['JEST_MOCK_HTTP_PORT']}`
: 'https://api.opensentinel.com';
const url = `${baseUrl}/kb/webhooks?${params}`;
: 'https://automations.opensentinel.com';
const url = `${baseUrl}/webhook?${params}`;
await axios.post(url, msg, {
headers: {
'Content-Type': 'text/plain',
Expand Down

0 comments on commit 53ab424

Please sign in to comment.