Skip to content

Commit

Permalink
Merge pull request #255 from rajbos/main
Browse files Browse the repository at this point in the history
Adding support for different target host than the executing environment
  • Loading branch information
lelia authored Mar 13, 2024
2 parents 319b4de + ed47107 commit 5a65682
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 78 deletions.
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>.

**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

0 comments on commit 5a65682

Please sign in to comment.