Skip to content

Commit

Permalink
Add support for creating PR's in ghes and behind proxy (#41)
Browse files Browse the repository at this point in the history
Co-authored-by: sethu madhav kollu <[email protected]>
  • Loading branch information
thomaseizinger and sethuk07 authored Jun 16, 2021
1 parent 13c98ab commit 285345f
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 12 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,17 @@ jobs:
## Advanced usage
To get an idea of all inputs that are supported, have a look at [this file](./src/getInputs.ts) or the [tests](./__tests__/getInputs.test.ts).
For self-hosted runners behind a corporate proxy, set the https_proxy environment variable.
```yaml
- name: Create pull request
uses: thomaseizinger/create-pull-request@master
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
head: ${{ github.ref }}
base: master
title: "An automatically created PR!"
env:
https_proxy: http://<proxy_address>:<port>
```
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ inputs:
reviewers:
description: 'A comma-separated list of GitHub logins that should review this PR.'
required: false
outputs:
number:
description: 'Pull Request number'
html_url:
description: 'URL that Pull Request may be reviewed at'
runs:
using: 'node12'
main: 'dist/index.js'
4 changes: 2 additions & 2 deletions dist/index.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"license": "MIT",
"dependencies": {
"@actions/core": "^1.2.0",
"@octokit/action": "^1.3.0"
"@octokit/action": "^1.3.0",
"https-proxy-agent": "^5.0.0"
},
"devDependencies": {
"@types/jest": "^24.0.23",
Expand Down
10 changes: 8 additions & 2 deletions src/getInputs.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { getInput } from "@actions/core/lib/core";
import {PullsCreateReviewRequestParams, PullsCreateParams} from '@octokit/plugin-rest-endpoint-methods/dist-types/generated/rest-endpoint-methods-types'
import {
PullsCreateReviewRequestParams,
PullsCreateParams
} from "@octokit/plugin-rest-endpoint-methods/dist-types/generated/rest-endpoint-methods-types";

type Inputs = PullsCreateParams & Required<Omit<PullsCreateReviewRequestParams, 'pull_number' | 'team_reviewers'>>
type Inputs = PullsCreateParams &
Required<
Omit<PullsCreateReviewRequestParams, "pull_number" | "team_reviewers">
>;

export function getInputs(): Inputs {
const head = getInput("head", { required: true });
Expand Down
16 changes: 15 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
import { setFailed, setOutput } from "@actions/core";
import { Octokit } from "@octokit/action";
import { OctokitOptions } from "@octokit/core/dist-types/types";
import { getInputs } from "./getInputs";
import { HttpsProxyAgent } from "https-proxy-agent";

async function run(): Promise<void> {
try {
const { reviewers, ...pullParams } = getInputs();

const octokit = new Octokit();
const options: OctokitOptions = {};
options.baseUrl = process.env.GITHUB_API_URL;

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

const octokit = new Octokit(options);
const pullRequest = await octokit.pulls.create(pullParams);
const pullNumber = pullRequest.data.number;
const htmlUrl = pullRequest.data.html_url;

if (reviewers.length > 0) {
await octokit.pulls.createReviewRequest({
Expand All @@ -20,6 +33,7 @@ async function run(): Promise<void> {
}

setOutput("number", pullNumber.toString());
setOutput("html_url", htmlUrl);
} catch (error) {
setFailed(error.message);
}
Expand Down
6 changes: 1 addition & 5 deletions types/mock-env/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
declare module "mock-env" {
function morph<T>(
callback: () => T,
vars: object,
toRemove?: string[]
): void;
function morph<T>(callback: () => T, vars: object, toRemove?: string[]): void;
}
24 changes: 23 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,13 @@ acorn@^6.0.1, acorn@^6.0.7, acorn@^6.2.1:
resolved "https://registry.yarnpkg.com/acorn/-/acorn-6.4.0.tgz#b659d2ffbafa24baf5db1cdbb2c94a983ecd2784"
integrity sha512-gac8OEcQ2Li1dxIEWGZzsp2BitJxwkwcOm0zHAJLcPJaVvm58FRnk6RkuLRpU1EujipU2ZFODv2P9DLMfnV8mw==

agent-base@6:
version "6.0.2"
resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-6.0.2.tgz#49fff58577cfee3f37176feab4c22e00f86d7f77"
integrity sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==
dependencies:
debug "4"

ajv-errors@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/ajv-errors/-/ajv-errors-1.0.1.tgz#f35986aceb91afadec4102fbd85014950cefa64d"
Expand Down Expand Up @@ -1874,6 +1881,13 @@ data-urls@^1.0.0:
whatwg-mimetype "^2.2.0"
whatwg-url "^7.0.0"

debug@4:
version "4.3.1"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.1.tgz#f0d229c505e0c6d8c49ac553d1b13dc183f6b2ee"
integrity sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==
dependencies:
ms "2.1.2"

debug@^2.2.0, debug@^2.3.3, debug@^2.6.8, debug@^2.6.9:
version "2.6.9"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"
Expand Down Expand Up @@ -3056,6 +3070,14 @@ https-browserify@^1.0.0:
resolved "https://registry.yarnpkg.com/https-browserify/-/https-browserify-1.0.0.tgz#ec06c10e0a34c0f2faf199f7fd7fc78fffd03c73"
integrity sha1-7AbBDgo0wPL68Zn3/X/Hj//QPHM=

https-proxy-agent@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-5.0.0.tgz#e2a90542abb68a762e0a0850f6c9edadfd8506b2"
integrity sha512-EkYm5BcKUGiduxzSt3Eppko+PiNWNEpa4ySk9vTC6wDsQJW9rHSa+UhGNJoRYp7bz6Ht1eaRIa6QaJqO5rCFbA==
dependencies:
agent-base "6"
debug "4"

[email protected], iconv-lite@^0.4.24, iconv-lite@^0.4.4:
version "0.4.24"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b"
Expand Down Expand Up @@ -4493,7 +4515,7 @@ [email protected]:
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"
integrity sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=

ms@^2.1.1:
ms@2.1.2, ms@^2.1.1:
version "2.1.2"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"
integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==
Expand Down

0 comments on commit 285345f

Please sign in to comment.