Skip to content

Commit

Permalink
feat: Add support for Github Enterprise (#126)
Browse files Browse the repository at this point in the history
* feat: Add support for Github Enterprise

* Test

* Update action.yml

Co-authored-by: Ghais Zaher <[email protected]>

* Update README.md

Co-authored-by: Ghais Zaher <[email protected]>

---------

Co-authored-by: Ghais Zaher <[email protected]>
  • Loading branch information
yeikel and ghaiszaher committed Feb 16, 2023
1 parent 885c9c7 commit 4cbb611
Show file tree
Hide file tree
Showing 4 changed files with 290 additions and 256 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ Optional. Usually in form of `github_token: ${{ secrets.GITHUB_TOKEN }}`. The de

Optional. Set to `true` to get the file name from the stack trace. The default is `false`.

### `github_base_url`

Optional: If you use GitHub Enterprise, you can set this to the URL of your server (e.g. https://github.myorg.com/api/v3).


## Example usage

```yml
Expand Down
18 changes: 15 additions & 3 deletions action.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const { retry } = require("@octokit/plugin-retry");
const RetryingOctokit = Octokit.plugin(retry);
const { parseTestReports } = require('./utils.js');


const action = async () => {
const reportPaths = core.getInput('report_paths').split(',').join('\n');
core.info(`Going to parse results form ${reportPaths}`);
Expand All @@ -16,6 +17,7 @@ const action = async () => {
const failIfNoTests = core.getInput('fail_if_no_tests') === 'true';
const skipPublishing = core.getInput('skip_publishing') === 'true';
const isFilenameInStackTrace = core.getInput('file_name_in_stack_trace') === 'true';
const githubBaseUrl = core.getInput('github_base_url');

let { count, skipped, annotations } = await parseTestReports(reportPaths, isFilenameInStackTrace);
const foundResults = count > 0 || skipped > 0;
Expand All @@ -24,6 +26,16 @@ const action = async () => {
? 'success'
: 'failure';

function buildRetryingOctokitClient() {
const baseRequest = { auth: githubToken, request: { retries: 3 } };

if (githubBaseUrl){
baseRequest.baseUrl = githubBaseUrl;
}

return new RetryingOctokit(baseRequest)
}

if (!skipPublishing) {
const title = foundResults
? `${count} tests run, ${skipped} skipped, ${annotations.length} failed.`
Expand All @@ -35,7 +47,7 @@ const action = async () => {
const status = 'completed';
const head_sha = commit || (pullRequest && pullRequest.head.sha) || github.context.sha;

const octokit = new RetryingOctokit({auth: githubToken, request: { retries: 3 }});
const octokit = buildRetryingOctokitClient();
if (createCheck) {
core.info(`Posting status '${status}' with conclusion '${conclusion}' to ${link} (sha: ${head_sha})`);
const createCheckRequest = {
Expand All @@ -62,11 +74,11 @@ const action = async () => {
status: 'in_progress'
})
core.debug(JSON.stringify(check_runs, null, 2));
if (check_runs.length == 0) {
if (check_runs.length === 0) {
core.setFailed(`Did not find any in progress '${name}' check for sha ${head_sha}`);
return;
}
if (check_runs.length != 1) {
if (check_runs.length !== 1) {
core.setFailed(`Found multiple in progress '${name}' checks for sha ${head_sha}`);
return;
}
Expand Down
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ inputs:
description: 'get filename from stack trace'
required: false
default: 'false'
github_base_url:
description: 'if you use Github Enterprise, you can set this to the URL of your server (e.g. https://github.myorg.com/api/v3)'
required: false
default: ""

outputs:
outcome:
description: 'the test outcome, either `success` or `failure`'
Expand Down
Loading

0 comments on commit 4cbb611

Please sign in to comment.