Skip to content

Commit

Permalink
Merge pull request #144 from sethumadhav07/addproxysupport
Browse files Browse the repository at this point in the history
Add ability to get it working with proxy
  • Loading branch information
8398a7 authored Sep 21, 2021
2 parents 17d0ca7 + 2472e5d commit 0ddb66b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
2 changes: 2 additions & 0 deletions __tests__/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ describe('8398a7/action-slack', () => {
beforeEach(() => {
process.env.GITHUB_REPOSITORY = '8398a7/action-slack';
process.env.GITHUB_EVENT_NAME = 'push';
process.env.https_proxy = 'http://localhost:1334';
process.env.HTTPS_PROXY = 'http://localhost:1334';
const github = require('@actions/github');
github.context.payload = {};
});
Expand Down
13 changes: 3 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@actions/core": "^1.4.0",
"@actions/github": "^5.0.0",
"@slack/webhook": "^6.0.0",
"https-proxy-agent": "^5.0.0",
"semver": "^7.3.5"
},
"devDependencies": {
Expand Down
16 changes: 14 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import * as core from '@actions/core';
import { context, getOctokit } from '@actions/github';
import { GitHub } from '@actions/github/lib/utils';
import { IncomingWebhook, IncomingWebhookSendArguments } from '@slack/webhook';
import {
IncomingWebhook,
IncomingWebhookSendArguments,
IncomingWebhookDefaultArguments,
} from '@slack/webhook';
import { FieldFactory } from './fields';
import { HttpsProxyAgent } from 'https-proxy-agent';

export const Success = 'success';
type SuccessType = 'success';
Expand Down Expand Up @@ -58,7 +63,14 @@ export class Client {
if (webhookUrl === undefined || webhookUrl === null || webhookUrl === '') {
throw new Error('Specify secrets.SLACK_WEBHOOK_URL');
}
this.webhook = new IncomingWebhook(webhookUrl);

const options: IncomingWebhookDefaultArguments = {};
const proxy = process.env.https_proxy || process.env.HTTPS_PROXY;
if (proxy) {
options.agent = new HttpsProxyAgent(proxy);
}

this.webhook = new IncomingWebhook(webhookUrl, options);
this.fieldFactory = new FieldFactory(
this.with.fields,
this.jobName,
Expand Down

0 comments on commit 0ddb66b

Please sign in to comment.