Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
28 changes: 22 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ All processing is done within Github Actions, no data is sent to an external ser

## Inputs

| Key | Required | Default | Description |
| -------------------- | -------- | ------- | ----------------------------------------------------------------------------------------------------- |
| `GITHUB_TOKEN` | **yes** | - | Github Token generated by Github Action workflow. You can pass this in as `${{secrets.GITHUB_TOKEN}}` |
| `COVERAGE_FILE_PATH` | **yes** | - | Location of coverage file that was generated |
| `COVERAGE_FORMAT` | **no** | lcov | Format of coverage file. May be `lcov`, `clover`, or `go` |
| `DEBUG` | **no** | - | Log debugging information. Comma-separated list of possible values `coverage`, `pr_lines_added` |
| Key | Required | Default | Description |
| -------------------- | -------- | ------------------------ | ----------------------------------------------------------------------------------------------------- |
| `GITHUB_TOKEN` | **yes** | - | Github Token generated by Github Action workflow. You can pass this in as `${{secrets.GITHUB_TOKEN}}` |
| `GITHUB_BASE_URL` | **no** | `https://api.github.com` | Base URL for GitHub API. Required for GitHub Enterprise Server or Cloud. |
| `COVERAGE_FILE_PATH` | **yes** | - | Location of coverage file that was generated |
| `COVERAGE_FORMAT` | **no** | `lcov` | Format of coverage file. May be `lcov`, `clover`, or `go` |
| `DEBUG` | **no** | - | Log debugging information. Comma-separated list of possible values `coverage`, `pr_lines_added` |

## Usage

Expand All @@ -37,6 +38,21 @@ coverage format with values appropriate for your repo:
COVERAGE_FORMAT: "lcov"
```

## Usage with GitHub Enterprise Server or Cloud

You need to the `GITHUB_BASE_URL` input to point to your API endpoint to use this action with GitHub Enterprise Server or Cloud. For example:

```yaml
with:
GITHUB_BASE_URL: https://github.acme-inc.com/api/v3 # for GitHub Enterprise Server
```
or

```yaml
with:
GITHUB_BASE_URL: https://api.acme-inc.ghe.com # for GitHub Enterprise Cloud
```

### Golang Workflow Example

```yaml
Expand Down
8 changes: 5 additions & 3 deletions __tests__/utils/github.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ import {test} from '@jest/globals'
import {GithubUtil} from '../../src/utils/github'

test('github init successfully', async function () {
const githubUtil = new GithubUtil('1234')
const githubUtil = new GithubUtil('1234', 'https://api.github.com')
expect(githubUtil).toBeInstanceOf(GithubUtil)
})

test('github init to throw error', function () {
expect(() => new GithubUtil('')).toThrowError('GITHUB_TOKEN is missing')
expect(() => new GithubUtil('', 'https://api.github.com')).toThrowError(
'GITHUB_TOKEN is missing'
)
})

test('build annotations', function () {
const githubUtil = new GithubUtil('1234')
const githubUtil = new GithubUtil('1234', 'https://api.github.com')

const prFiles = {
'file1.txt': [
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ inputs:
GITHUB_TOKEN:
required: true
description: 'Github token from workflow. This is automatically generated by github and is rotated. You can limit scopes of this token as well.'
GITHUB_BASE_URL:
required: false
description: 'Github base URL. Set this if you are using a GitHub Enterprise Server or a instance on `ghe.com``.'
default: 'https://api.github.com'
COVERAGE_FILE_PATH:
required: true
description: 'Path to coverage file'
Expand Down
7 changes: 4 additions & 3 deletions dist/index.js

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

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

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export async function play(): Promise<void> {
}
core.info('Performing Code Coverage Analysis')
const GITHUB_TOKEN = core.getInput('GITHUB_TOKEN', {required: true})
const GITHUB_BASE_URL = core.getInput('GITHUB_BASE_URL')
const COVERAGE_FILE_PATH = core.getInput('COVERAGE_FILE_PATH', {
required: true
})
Expand Down Expand Up @@ -81,7 +82,7 @@ export async function play(): Promise<void> {
core.info(JSON.stringify(item))
}
}
const githubUtil = new GithubUtil(GITHUB_TOKEN)
const githubUtil = new GithubUtil(GITHUB_TOKEN, GITHUB_BASE_URL)

// 3. Get current pull request files
const pullRequestFiles = await githubUtil.getPullRequestDiff()
Expand Down
4 changes: 2 additions & 2 deletions src/utils/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import {Octokit} from 'octokit'
export class GithubUtil {
private client: Octokit

constructor(token: string) {
constructor(token: string, baseUrl: string) {
if (!token) {
throw new Error('GITHUB_TOKEN is missing')
}
this.client = new Octokit({auth: token})
this.client = new Octokit({auth: token, baseUrl})
}

getPullRequestRef(): string {
Expand Down