Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for different target host than the executing environment #255

Merged
merged 5 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ A newline-delimited (`"\n"`) string representing a list of allowed [license keys

**Example:** `"0bsd\napache-2.0\nmit"`

### `targetInstanceUrl` (optional, string)

This parameter can be used to target a GitHub Enterprise Server instance instead of https://github.com.
lelia marked this conversation as resolved.
Show resolved Hide resolved

**Example:** `https://my-private.github-server.com`

## Outputs

### `forkUrl` (string)
Expand Down Expand Up @@ -136,6 +142,20 @@ with:
licenseAllowlist: "0bsd\napache-2.0\nmit"
```

### Target a GitHub Enterprise Server

Create a fork in your own GitHub Enterprise Server:

```yaml
uses: wayfair-incubator/forker@a694606ff02c8ba2654865adeb7a6d2053b34afa
with:
token: ${{ secrets.ACCESS_TOKEN }}
repo: tremor-runtime
owner: tremor-rs
user: lelia
targetInstanceUrl: https://my-private.github-server.com
```

---

## Developing
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ inputs:
description: 'List of allowed licenses for repository being forked'
required: false
default: 'undefined'
targetInstanceUrl:
description: 'GitHub target instance that will have the fork'
required: false
outputs:
forkUrl:
description: 'The URL of the forked repository'
Expand Down
140 changes: 72 additions & 68 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

51 changes: 44 additions & 7 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"license": "MIT",
"dependencies": {
"@actions/core": "1.10.1",
"@octokit/rest": "20.0.2"
"@octokit/rest": "20.0.2",
"https-proxy-agent": "^7.0.0"
},
"devDependencies": {
"@types/jest": "28.1.8",
Expand Down
16 changes: 15 additions & 1 deletion src/github.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
import * as core from '@actions/core'
import {HTTP} from './const'
import {Octokit} from '@octokit/rest'
import {HttpsProxyAgent} from 'https-proxy-agent'

const token: string = core.getInput('token', {required: true})
const octokit = new Octokit({auth: token})
const targetInstanceUrl: string = core.getInput('targetInstanceUrl')
const httpsProxy: string = process.env.HTTPS_PROXY as string
const octokit = targetInstanceUrl ? new Octokit({
auth: token,
baseUrl: targetInstanceUrl,
request: {
agent: httpsProxy
? new HttpsProxyAgent(httpsProxy)
: undefined,
},
}) : new Octokit({
auth: token,
})

export async function changeUserPermissions(
org: string,
Expand Down Expand Up @@ -84,6 +97,7 @@ export async function forkRepo(
}`
)
} else {
core.info(`Received an error code: ${err.status} ${(err as Error).message}`)
core.setFailed(`🚨 Failed to create fork of repository: ${repo}`)
}
}
Expand Down